start of draft option upgrades
This commit is contained in:
parent
e78ae0cda1
commit
db9c828e63
7 changed files with 235 additions and 2 deletions
|
|
@ -0,0 +1,42 @@
|
|||
// Assets/_Project/Scripts/Gameplay/Draft/BuilderEffectUpgradeDraftOption.cs
|
||||
using UnityEngine;
|
||||
using TD.Core;
|
||||
using TD.Gameplay.BuilderEffects;
|
||||
|
||||
namespace TD.Gameplay.Draft
|
||||
{
|
||||
/// <summary>
|
||||
/// Draft choice — "upgrade a builder effect you already have". Replaces
|
||||
/// <see cref="BaseKind"/> with <see cref="UpgradedKind"/> in the player's
|
||||
/// <see cref="BuilderUpgradeManager"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mirrors <see cref="BuilderEffectDraftOption"/>, but swaps rather than adds. Only offered
|
||||
/// while the player currently has <see cref="BaseKind"/> granted — once taken,
|
||||
/// <see cref="BaseKind"/> is removed, which automatically makes this option (and any sibling
|
||||
/// upgrade branching off the same base) invalid for future drafts.
|
||||
/// </remarks>
|
||||
[CreateAssetMenu(fileName = "BuilderEffectUpgradeOption",
|
||||
menuName = "TD/Draft/Builder Effect Upgrade Option")]
|
||||
public class BuilderEffectUpgradeDraftOption : DraftOption
|
||||
{
|
||||
[Header("Payload")]
|
||||
[Tooltip("The builder effect this option upgrades from.")]
|
||||
public BuilderEffectKind BaseKind;
|
||||
|
||||
[Tooltip("The builder effect this option upgrades to.")]
|
||||
public BuilderEffectKind UpgradedKind;
|
||||
|
||||
public override bool IsValidFor(ulong clientId)
|
||||
{
|
||||
var upgrades = BuilderUpgradeManager.GetForClient(clientId);
|
||||
return upgrades != null && upgrades.PlayerHasEffect(BaseKind);
|
||||
}
|
||||
|
||||
public override bool ServerApply(ulong clientId)
|
||||
{
|
||||
var upgrades = BuilderUpgradeManager.GetForClient(clientId);
|
||||
return upgrades != null && upgrades.ServerUpgradeEffect(BaseKind, UpgradedKind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
// Assets/_Project/Scripts/Gameplay/Draft/BuilderSpellUpgradeDraftOption.cs
|
||||
using UnityEngine;
|
||||
using TD.Core;
|
||||
using TD.Gameplay.BuilderSpells;
|
||||
|
||||
namespace TD.Gameplay.Draft
|
||||
{
|
||||
/// <summary>
|
||||
/// Draft choice — "upgrade a builder spell you already have". Replaces
|
||||
/// <see cref="BaseKind"/> with <see cref="UpgradedKind"/> in the player's
|
||||
/// <see cref="PlayerSpellLoadout"/>, in place — the upgraded spell keeps the same hotkey
|
||||
/// slot the base spell occupied.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mirrors <see cref="BuilderSpellDraftOption"/>, but swaps rather than adds (so it doesn't
|
||||
/// consume a slot). Only offered while the player currently has <see cref="BaseKind"/>
|
||||
/// granted — once taken, <see cref="BaseKind"/> is removed, which automatically makes this
|
||||
/// option (and any sibling upgrade branching off the same base) invalid for future drafts.
|
||||
/// </remarks>
|
||||
[CreateAssetMenu(fileName = "BuilderSpellUpgradeOption",
|
||||
menuName = "TD/Draft/Builder Spell Upgrade Option")]
|
||||
public class BuilderSpellUpgradeDraftOption : DraftOption
|
||||
{
|
||||
[Header("Payload")]
|
||||
[Tooltip("The builder spell this option upgrades from.")]
|
||||
public BuilderSpellKind BaseKind;
|
||||
|
||||
[Tooltip("The builder spell this option upgrades to.")]
|
||||
public BuilderSpellKind UpgradedKind;
|
||||
|
||||
public override bool IsValidFor(ulong clientId)
|
||||
{
|
||||
var loadout = PlayerSpellLoadout.GetForClient(clientId);
|
||||
return loadout != null && loadout.PlayerHasSpell(BaseKind);
|
||||
}
|
||||
|
||||
public override bool ServerApply(ulong clientId)
|
||||
{
|
||||
var loadout = PlayerSpellLoadout.GetForClient(clientId);
|
||||
return loadout != null && loadout.ServerUpgradeSpell(BaseKind, UpgradedKind);
|
||||
}
|
||||
|
||||
/// <summary>Inherits the upgraded spell's icon (resolved from the pool by
|
||||
/// <see cref="UpgradedKind"/>) unless this option assigns an override.</summary>
|
||||
public override Sprite ResolveIcon()
|
||||
{
|
||||
if (Icon != null) return Icon;
|
||||
var def = BuilderSpellPool.Instance != null ? BuilderSpellPool.Instance.Get(UpgradedKind) : null;
|
||||
return def != null ? def.Icon : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
// Assets/_Project/Scripts/Gameplay/Draft/TowerUpgradeDraftOption.cs
|
||||
using UnityEngine;
|
||||
using TD.Towers;
|
||||
|
||||
namespace TD.Gameplay.Draft
|
||||
{
|
||||
/// <summary>
|
||||
/// Draft choice — "upgrade a tower you already have". Replaces <see cref="BaseTower"/>
|
||||
/// with <see cref="UpgradedTower"/> in the player's <see cref="PlayerTowerDeck"/>: every
|
||||
/// tower of that type placed from now on is the upgraded version. Already-placed towers
|
||||
/// are unaffected.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mirrors <see cref="NewTowerDraftOption"/>, but swaps rather than adds. Only offered
|
||||
/// while the player currently has <see cref="BaseTower"/> unlocked — once taken,
|
||||
/// <see cref="BaseTower"/> is removed from the deck, which automatically makes this option
|
||||
/// (and any sibling upgrade branching off the same base) invalid for future drafts.
|
||||
/// </remarks>
|
||||
[CreateAssetMenu(fileName = "TowerUpgradeOption", menuName = "TD/Draft/Tower Upgrade Option")]
|
||||
public class TowerUpgradeDraftOption : DraftOption
|
||||
{
|
||||
[Header("Payload")]
|
||||
[Tooltip("The tower this option upgrades from. Must be present in the player's deck " +
|
||||
"for this option to be offered.")]
|
||||
public TowerDefinition BaseTower;
|
||||
|
||||
[Tooltip("The tower this option upgrades to. Must also be present in the " +
|
||||
"TowerPlacementManager catalog (that's where its TowerTypeId comes from).")]
|
||||
public TowerDefinition UpgradedTower;
|
||||
|
||||
public override bool IsValidFor(ulong clientId)
|
||||
{
|
||||
var deck = PlayerTowerDeck.GetForClient(clientId);
|
||||
var pm = TowerPlacementManager.Instance;
|
||||
if (deck == null || pm == null || BaseTower == null || UpgradedTower == null) return false;
|
||||
|
||||
if (!pm.TryGetTypeId(BaseTower, out int baseTypeId)) return false;
|
||||
|
||||
return deck.Contains(baseTypeId);
|
||||
}
|
||||
|
||||
public override bool ServerApply(ulong clientId)
|
||||
{
|
||||
var deck = PlayerTowerDeck.GetForClient(clientId);
|
||||
var pm = TowerPlacementManager.Instance;
|
||||
if (deck == null || pm == null || BaseTower == null || UpgradedTower == null) return false;
|
||||
|
||||
if (!pm.TryGetTypeId(BaseTower, out int baseTypeId))
|
||||
{
|
||||
Debug.LogError($"[TowerUpgradeDraftOption] '{BaseTower.name}' is not in the tower " +
|
||||
$"catalog; cannot apply. Add it to TowerPlacementManager.towerDefinitions.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pm.TryGetTypeId(UpgradedTower, out int upgradedTypeId))
|
||||
{
|
||||
Debug.LogError($"[TowerUpgradeDraftOption] '{UpgradedTower.name}' is not in the " +
|
||||
$"tower catalog; cannot apply. Add it to " +
|
||||
$"TowerPlacementManager.towerDefinitions.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return deck.ServerUpgradeTower(baseTypeId, upgradedTypeId);
|
||||
}
|
||||
|
||||
/// <summary>Inherits the upgraded tower's icon unless this option assigns an override.</summary>
|
||||
public override Sprite ResolveIcon()
|
||||
=> Icon != null ? Icon : (UpgradedTower != null ? UpgradedTower.Icon : null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aeec22f152a57ef5798eae035c091543
|
||||
Loading…
Add table
Add a link
Reference in a new issue