Compare commits

...

3 commits

19 changed files with 351 additions and 5 deletions

View file

@ -25,7 +25,7 @@ MonoBehaviour:
areaSound:
clip: {fileID: 8300000, guid: 038ff3eab9aa0034bac26ccb648ef2a1, type: 3}
volume: 0.632
minPitch: 1.14
minPitch: 1.04
maxPitch: 0.96
SlowFactor: 0.5
EffectDuration: 8

View file

@ -0,0 +1,31 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 37cc60a4a6e53e24cb6d1c0be310868a, type: 3}
m_Name: SlowAreaUpgradedSpell
m_EditorClassIdentifier: Assembly-CSharp::TD.Gameplay.BuilderSpells.SlowAreaUpgradedSpellDefinition
DisplayName: Slow Area II
Description: Upgraded Slow Area. Slows for 50% longer.
Icon: {fileID: 0}
Cooldown: 10
TargetType: 1
Radius: 5
enemyLayerMask:
serializedVersion: 2
m_Bits: 1152
areaVfxPrefab: {fileID: 1462673130280185047, guid: bf2f1f2a9a54e9162b80673e3f7eeaf6, type: 3}
areaSound:
clip: {fileID: 8300000, guid: 038ff3eab9aa0034bac26ccb648ef2a1, type: 3}
volume: 0.632
minPitch: 1.04
maxPitch: 0.96
SlowFactor: 0.5
EffectDuration: 12

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 364edf6abc3c31e33b53d0a01142b8ab
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,20 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7b1c5b562f39c72eea3bafd0165af078, type: 3}
m_Name: Draft_BuilderSpellOption_SlowAreaUpgrade
m_EditorClassIdentifier: Assembly-CSharp::TD.Gameplay.Draft.BuilderSpellUpgradeDraftOption
DisplayName: Slow Area II
Description: Slows enemies in the area for 50% longer than the default slow area.
Icon: {fileID: 0}
Weight: 1
BaseKind: 1
UpgradedKind: 2

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d180030b68a9a5e1da497bf6f83451d4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -13428,6 +13428,7 @@ MonoBehaviour:
spells:
- {fileID: 11400000, guid: 051c48f416e5366b59d49b0e062333ac, type: 2}
- {fileID: 11400000, guid: d893f46b037536b4ba91307e184cecfe, type: 2}
- {fileID: 11400000, guid: 364edf6abc3c31e33b53d0a01142b8ab, type: 2}
--- !u!4 &914832726
Transform:
m_ObjectHideFlags: 0
@ -28786,6 +28787,7 @@ MonoBehaviour:
- {fileID: 11400000, guid: 65ff25c1c8a89f7df8e88f71968c1c98, type: 2}
- {fileID: 11400000, guid: 5f390de69ba43b2a6a0d89cf09580320, type: 2}
- {fileID: 11400000, guid: 29b35841f7e5db454903798cb5d83434, type: 2}
- {fileID: 11400000, guid: d180030b68a9a5e1da497bf6f83451d4, type: 2}
--- !u!4 &2139601601
Transform:
m_ObjectHideFlags: 0

View file

@ -11,5 +11,6 @@ namespace TD.Core
{
Fireball = 0,
SlowArea = 1,
SlowAreaUpgraded = 2,
}
}

View file

@ -0,0 +1,21 @@
// Assets/_Project/Scripts/Gameplay/BuilderSpells/SlowAreaUpgradedSpellDefinition.cs
using TD.Core;
using UnityEngine;
namespace TD.Gameplay.BuilderSpells
{
/// <summary>
/// Draft upgrade for <see cref="SlowAreaSpellDefinition"/> — identical behavior, just a
/// distinct <see cref="BuilderSpellKind"/> so <see
/// cref="TD.Gameplay.Draft.BuilderSpellUpgradeDraftOption"/> can replace the base spell
/// with this one in the player's loadout. All fields (SlowFactor, EffectDuration, etc.)
/// are inherited; author this asset with a longer EffectDuration than the base spell.
/// </summary>
[CreateAssetMenu(fileName = "SlowAreaUpgradedSpell",
menuName = "TD/Builder Spells/Slow Area (Upgraded)")]
public class SlowAreaUpgradedSpellDefinition : SlowAreaSpellDefinition
{
public override BuilderSpellKind Kind => BuilderSpellKind.SlowAreaUpgraded;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 37cc60a4a6e53e24cb6d1c0be310868a

View file

@ -20,8 +20,9 @@ namespace TD.Gameplay
/// same constraint on a struct); <c>byte</c> already does, for free.</para>
///
/// <para><b>Granted via draft.</b> <see cref="TD.Gameplay.Draft.BuilderEffectDraftOption"/>
/// calls <see cref="ServerGrantEffect"/> when a player picks it. Effects are permanent for
/// the match — there is no revoke.</para>
/// calls <see cref="ServerGrantEffect"/> when a player picks it. Effects are otherwise
/// permanent for the match — the only way one leaves the granted set is
/// <see cref="ServerUpgradeEffect"/> swapping it for its upgraded replacement.</para>
///
/// <para><b>Query, don't snapshot.</b> Consumers (e.g. <see cref="WaveManager"/> 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;
}
/// <summary>
/// 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.
/// </summary>
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;
}
}
}

View file

@ -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);
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 717648113e8090fc6856744d898ab375

View file

@ -15,7 +15,9 @@ namespace TD.Gameplay.Draft
/// <see cref="PlayerSpellLoadout"/> and <see cref="BuilderSpellPool"/> already key off of.
/// <see cref="IsValidFor"/> also checks slot capacity — once
/// <see cref="PlayerSpellLoadout.MaxSpellSlots"/> is reached, no further spell options are
/// offered.
/// offered. Gates on <see cref="PlayerSpellLoadout.PlayerHasEverGranted"/> rather than
/// current possession, so a base spell already upgraded past (see
/// <see cref="BuilderSpellUpgradeDraftOption"/>) is never re-offered.
/// </remarks>
[CreateAssetMenu(fileName = "BuilderSpellOption", menuName = "TD/Draft/Builder Spell Option")]
public class BuilderSpellDraftOption : DraftOption
@ -29,7 +31,7 @@ namespace TD.Gameplay.Draft
var loadout = PlayerSpellLoadout.GetForClient(clientId);
if (loadout == null) return false;
if (loadout.SlotCount >= PlayerSpellLoadout.MaxSpellSlots) return false;
return !loadout.PlayerHasSpell(Kind);
return !loadout.PlayerHasEverGranted(Kind);
}
public override bool ServerApply(ulong clientId)

View file

@ -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;
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7b1c5b562f39c72eea3bafd0165af078

View file

@ -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);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: aeec22f152a57ef5798eae035c091543

View file

@ -60,6 +60,10 @@ namespace TD.Gameplay
private readonly NetworkList<SpellSlot> spells = new NetworkList<SpellSlot>();
// Every kind ever granted this match, including ones since upgraded away. Unlike
// `spells`, entries here are never removed — see PlayerHasEverGranted.
private readonly NetworkList<byte> everGrantedKinds = new NetworkList<byte>();
/// <summary>Fired on every peer when a spell is granted or a cooldown changes.</summary>
public event System.Action OnLoadoutChanged;
@ -100,6 +104,14 @@ namespace TD.Gameplay
public BuilderSpellKind? GetKind(int slot)
=> (slot >= 0 && slot < spells.Count) ? spells[slot].Kind : (BuilderSpellKind?)null;
/// <summary>
/// True if this player has ever been granted the given spell this match, whether or
/// not it's still occupying a slot (e.g. it may have since been upgraded away). Used
/// by <see cref="TD.Gameplay.Draft.BuilderSpellDraftOption"/> so a base spell already
/// upgraded past is never re-offered.
/// </summary>
public bool PlayerHasEverGranted(BuilderSpellKind kind) => everGrantedKinds.Contains((byte)kind);
/// <summary>True if <paramref name="slot"/> is out of range, empty, or still cooling down.</summary>
public bool IsSlotOnCooldown(int slot)
{
@ -136,9 +148,33 @@ namespace TD.Gameplay
if (PlayerHasSpell(kind)) return false;
spells.Add(SpellSlot.CreateReady(kind));
if (!everGrantedKinds.Contains((byte)kind)) everGrantedKinds.Add((byte)kind);
return true;
}
/// <summary>
/// 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.
/// </summary>
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);
if (!everGrantedKinds.Contains((byte)newKind)) everGrantedKinds.Add((byte)newKind);
return true;
}
}
return false;
}
// ----- Cast RPC -----------------------------------------------------
/// <summary>

View file

@ -146,5 +146,30 @@ namespace TD.Gameplay
unlockedTypeIds.Add(towerTypeId);
return true;
}
/// <summary>
/// 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.
/// </summary>
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;
}
}
}