Updating HUD, Gold Config, and finishing off Play flow for 9player map.

This commit is contained in:
Matt F 2026-05-22 12:18:23 -07:00
parent a7be12fa9b
commit 3dcc0e7edd
28 changed files with 2272 additions and 9601 deletions

View file

@ -63,7 +63,10 @@ namespace TD.Gameplay
// --- Tunables ----------------------------------------------------
[Tooltip("How much gold this player starts with when the match begins.")]
[Tooltip("Fallback starting gold used only when no GoldConfig is reachable at " +
"match start (e.g. editor testing in the Match scene without the lobby " +
"flow). Normally WaveManager overwrites this with GoldConfig.StartingGold " +
"during InitAfterSpawn.")]
[SerializeField] private int startingGold = 100;
// --- Networked state ---------------------------------------------
@ -77,7 +80,19 @@ namespace TD.Gameplay
writePerm: NetworkVariableWritePermission.Server
);
// Gold this player has accumulated since the start of the current wave. Reset to
// 0 at the start of each new wave by WaveManager. Includes kill rewards,
// completion bonus, and no-leak bonus — anything that flows through AwardGold.
// Spending does NOT decrement it; it's a "gold earned", not "gold held", counter.
// The HUD's top-bar "+N g/wave" reads this for the LOCAL player.
private readonly NetworkVariable<int> goldEarnedThisWave = new NetworkVariable<int>(
value: 0,
readPerm: NetworkVariableReadPermission.Everyone,
writePerm: NetworkVariableWritePermission.Server
);
public int CurrentGold => currentGold.Value;
public int GoldEarnedThisWave => goldEarnedThisWave.Value;
// --- Lifecycle ---------------------------------------------------
@ -128,7 +143,9 @@ namespace TD.Gameplay
/// <summary>
/// Server-side entry point for awarding gold (wave clear, enemy kill).
/// Direct call — not Rpc-wrapped — because awards always originate
/// from server-authoritative game events.
/// from server-authoritative game events. Also increments
/// <see cref="GoldEarnedThisWave"/> so the HUD's per-wave counter reflects
/// it; spending does not decrement that counter (it tracks earnings, not balance).
/// </summary>
public void AwardGold(int amount)
{
@ -141,6 +158,39 @@ namespace TD.Gameplay
if (amount <= 0) return;
currentGold.Value += amount;
goldEarnedThisWave.Value += amount;
}
/// <summary>
/// Server-side: overwrites the player's current gold to the exact specified
/// amount. Used by <c>WaveManager</c> at match start to apply
/// <see cref="GoldConfig.StartingGold"/>, replacing the inspector-default value
/// set during initial spawn. Does NOT touch <see cref="GoldEarnedThisWave"/>.
/// </summary>
public void ServerSetGold(int amount)
{
if (!IsServer)
{
Debug.LogError("[PlayerGoldManager] ServerSetGold called on a client. " +
"Only server code should call this directly.");
return;
}
currentGold.Value = Mathf.Max(0, amount);
}
/// <summary>
/// Server-side: resets <see cref="GoldEarnedThisWave"/> back to 0. Called by
/// <c>WaveManager</c> at the start of each new wave so the HUD's top-bar
/// per-wave counter starts fresh.
/// </summary>
public void ServerResetWaveEarnings()
{
if (!IsServer)
{
Debug.LogError("[PlayerGoldManager] ServerResetWaveEarnings called on a client.");
return;
}
goldEarnedThisWave.Value = 0;
}
/// <summary>