diff --git a/Assets/_Project/Scripts/Gameplay/BuilderUpgradeManager.cs b/Assets/_Project/Scripts/Gameplay/BuilderUpgradeManager.cs
index f11f9ec..6b81aea 100644
--- a/Assets/_Project/Scripts/Gameplay/BuilderUpgradeManager.cs
+++ b/Assets/_Project/Scripts/Gameplay/BuilderUpgradeManager.cs
@@ -20,8 +20,9 @@ namespace TD.Gameplay
/// same constraint on a struct); byte already does, for free.
///
/// Granted via draft.
- /// calls when a player picks it. Effects are permanent for
- /// the match — there is no revoke.
+ /// calls when a player picks it. Effects are otherwise
+ /// permanent for the match — the only way one leaves the granted set is
+ /// swapping it for its upgraded replacement.
///
/// Query, don't snapshot. Consumers (e.g. awarding
/// kill gold) query this manager live at the point of use rather than towers caching their
@@ -117,5 +118,24 @@ namespace TD.Gameplay
grantedKinds.Add(value);
return true;
}
+
+ ///
+ /// Server-only: replaces a previously granted effect with a different one (an upgrade
+ /// pick). No-op if the old effect isn't currently granted or the new one already is.
+ /// Returns true if the swap happened.
+ ///
+ public bool ServerUpgradeEffect(BuilderEffectKind oldKind, BuilderEffectKind newKind)
+ {
+ if (!IsServer) return false;
+
+ byte newValue = (byte)newKind;
+ if (grantedKinds.Contains(newValue)) return false;
+
+ byte oldValue = (byte)oldKind;
+ if (!grantedKinds.Remove(oldValue)) return false;
+
+ grantedKinds.Add(newValue);
+ return true;
+ }
}
}
diff --git a/Assets/_Project/Scripts/Gameplay/Draft/BuilderEffectUpgradeDraftOption.cs b/Assets/_Project/Scripts/Gameplay/Draft/BuilderEffectUpgradeDraftOption.cs
new file mode 100644
index 0000000..46022b5
--- /dev/null
+++ b/Assets/_Project/Scripts/Gameplay/Draft/BuilderEffectUpgradeDraftOption.cs
@@ -0,0 +1,42 @@
+// Assets/_Project/Scripts/Gameplay/Draft/BuilderEffectUpgradeDraftOption.cs
+using UnityEngine;
+using TD.Core;
+using TD.Gameplay.BuilderEffects;
+
+namespace TD.Gameplay.Draft
+{
+ ///
+ /// Draft choice — "upgrade a builder effect you already have". Replaces
+ /// with in the player's
+ /// .
+ ///
+ ///
+ /// Mirrors , but swaps rather than adds. Only offered
+ /// while the player currently has granted — once taken,
+ /// is removed, which automatically makes this option (and any sibling
+ /// upgrade branching off the same base) invalid for future drafts.
+ ///
+ [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);
+ }
+ }
+}
diff --git a/Assets/_Project/Scripts/Gameplay/Draft/BuilderSpellUpgradeDraftOption.cs b/Assets/_Project/Scripts/Gameplay/Draft/BuilderSpellUpgradeDraftOption.cs
new file mode 100644
index 0000000..a9d56bd
--- /dev/null
+++ b/Assets/_Project/Scripts/Gameplay/Draft/BuilderSpellUpgradeDraftOption.cs
@@ -0,0 +1,52 @@
+// Assets/_Project/Scripts/Gameplay/Draft/BuilderSpellUpgradeDraftOption.cs
+using UnityEngine;
+using TD.Core;
+using TD.Gameplay.BuilderSpells;
+
+namespace TD.Gameplay.Draft
+{
+ ///
+ /// Draft choice — "upgrade a builder spell you already have". Replaces
+ /// with in the player's
+ /// , in place — the upgraded spell keeps the same hotkey
+ /// slot the base spell occupied.
+ ///
+ ///
+ /// Mirrors , but swaps rather than adds (so it doesn't
+ /// consume a slot). Only offered while the player currently has
+ /// granted — once taken, is removed, which automatically makes this
+ /// option (and any sibling upgrade branching off the same base) invalid for future drafts.
+ ///
+ [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);
+ }
+
+ /// Inherits the upgraded spell's icon (resolved from the pool by
+ /// ) unless this option assigns an override.
+ 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;
+ }
+ }
+}
diff --git a/Assets/_Project/Scripts/Gameplay/Draft/TowerUpgradeDraftOption.cs b/Assets/_Project/Scripts/Gameplay/Draft/TowerUpgradeDraftOption.cs
new file mode 100644
index 0000000..7746e3e
--- /dev/null
+++ b/Assets/_Project/Scripts/Gameplay/Draft/TowerUpgradeDraftOption.cs
@@ -0,0 +1,70 @@
+// Assets/_Project/Scripts/Gameplay/Draft/TowerUpgradeDraftOption.cs
+using UnityEngine;
+using TD.Towers;
+
+namespace TD.Gameplay.Draft
+{
+ ///
+ /// Draft choice — "upgrade a tower you already have". Replaces
+ /// with in the player's : every
+ /// tower of that type placed from now on is the upgraded version. Already-placed towers
+ /// are unaffected.
+ ///
+ ///
+ /// Mirrors , but swaps rather than adds. Only offered
+ /// while the player currently has unlocked — once taken,
+ /// is removed from the deck, which automatically makes this option
+ /// (and any sibling upgrade branching off the same base) invalid for future drafts.
+ ///
+ [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);
+ }
+
+ /// Inherits the upgraded tower's icon unless this option assigns an override.
+ public override Sprite ResolveIcon()
+ => Icon != null ? Icon : (UpgradedTower != null ? UpgradedTower.Icon : null);
+ }
+}
diff --git a/Assets/_Project/Scripts/Gameplay/Draft/TowerUpgradeDraftOption.cs.meta b/Assets/_Project/Scripts/Gameplay/Draft/TowerUpgradeDraftOption.cs.meta
new file mode 100644
index 0000000..a35a5d2
--- /dev/null
+++ b/Assets/_Project/Scripts/Gameplay/Draft/TowerUpgradeDraftOption.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: aeec22f152a57ef5798eae035c091543
\ No newline at end of file
diff --git a/Assets/_Project/Scripts/Gameplay/PlayerSpellLoadout.cs b/Assets/_Project/Scripts/Gameplay/PlayerSpellLoadout.cs
index ef994bb..0d8bfb3 100644
--- a/Assets/_Project/Scripts/Gameplay/PlayerSpellLoadout.cs
+++ b/Assets/_Project/Scripts/Gameplay/PlayerSpellLoadout.cs
@@ -139,6 +139,28 @@ namespace TD.Gameplay
return true;
}
+ ///
+ /// Server-only: replaces a previously granted spell with a different one (an upgrade
+ /// pick), in place — the upgraded spell keeps the base spell's hotkey slot and starts
+ /// off cooldown. No-op if the old spell isn't currently granted or the new one already
+ /// is. Returns true if the swap happened.
+ ///
+ public bool ServerUpgradeSpell(BuilderSpellKind oldKind, BuilderSpellKind newKind)
+ {
+ if (!IsServer) return false;
+ if (PlayerHasSpell(newKind)) return false;
+
+ for (int i = 0; i < spells.Count; i++)
+ {
+ if (spells[i].Kind == oldKind)
+ {
+ spells[i] = SpellSlot.CreateReady(newKind);
+ return true;
+ }
+ }
+ return false;
+ }
+
// ----- Cast RPC -----------------------------------------------------
///
diff --git a/Assets/_Project/Scripts/Gameplay/PlayerTowerDeck.cs b/Assets/_Project/Scripts/Gameplay/PlayerTowerDeck.cs
index 356d459..9d7b54d 100644
--- a/Assets/_Project/Scripts/Gameplay/PlayerTowerDeck.cs
+++ b/Assets/_Project/Scripts/Gameplay/PlayerTowerDeck.cs
@@ -146,5 +146,30 @@ namespace TD.Gameplay
unlockedTypeIds.Add(towerTypeId);
return true;
}
+
+ ///
+ /// Server-only: replaces a previously unlocked tower type with a different one (an
+ /// upgrade pick) — every tower of that type placed from now on uses the new definition.
+ /// Already-placed towers keep whatever type they were placed with; this only changes
+ /// what's placeable going forward. No-op if the old type isn't currently unlocked or
+ /// the new one already is. Returns true if the swap happened.
+ ///
+ public bool ServerUpgradeTower(int oldTypeId, int newTypeId)
+ {
+ if (!IsServer) return false;
+ if (newTypeId <= 0) return false;
+ if (Contains(newTypeId)) return false;
+
+ for (int i = 0; i < unlockedTypeIds.Count; i++)
+ {
+ if (unlockedTypeIds[i] == oldTypeId)
+ {
+ unlockedTypeIds.RemoveAt(i);
+ unlockedTypeIds.Add(newTypeId);
+ return true;
+ }
+ }
+ return false;
+ }
}
}