First pass at full refactor to 2.0 design

Restructures the game around the cyclical run loop from Game Design Doc V2:
5 waves = a cycle, 3 cycles = a phase, each phase ends in a boss.

- New TD.Gameplay.Waves: WaveGroup / PhaseDefinition / RunDefinition author the
  run as draggable weighted pools; RunState owns phase/cycle position, the drawn
  wave slots, and the per-slot enemy buff sets. WaveManager's flat wave array is
  gone -- it now only runs the encounter RunState points at.
- New TD.Gameplay.EnemyUpgrades: the post-wave enemy-buff vote, with public
  live-replicated ballots so the HUD can show who voted for what.
- Inter-wave flow is now strictly sequential: draft -> vote -> build, each stage
  ending early once every player has acted.
- Enemy abilities inverted from per-instance random rolls to deterministic,
  stacking per-wave-slot sets. Six cards ship: Split (reworked), Flight, Blink,
  No Bounty, Gold Theft, Double Up.
- Tower upgrades are a two-step tree: a draft pick unlocks a node, gold converts
  an already-placed tower in place.
- Boss encounters flag their enemies and drive a boss HP bar.
- Player cap reduced to 3 via MatchRules.MaxPlayers.
- GoldConfig is now keyed by global encounter number rather than wave index.

Compiles clean; NOT yet verified in-engine. Editor wiring still required --
see Docs/2.0_Setup_Checklist.md.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Matt F 2026-07-30 17:45:11 -07:00
parent 7e5c3a8279
commit 4892d7253d
64 changed files with 4023 additions and 344 deletions

View file

@ -0,0 +1,94 @@
// Assets/_Project/Scripts/Gameplay/EnemyUpgrades/EnemyUpgradePool.cs
using System.Collections.Generic;
using UnityEngine;
namespace TD.Gameplay.EnemyUpgrades
{
/// <summary>
/// Scene singleton holding every <see cref="EnemyUpgradeOption"/> that can appear anywhere in
/// this match. The array index is the option's <c>EnemyUpgradeOptionId</c> — the stable
/// identifier used to replicate vote offers, ballots, and the upgrades recorded on wave slots.
/// </summary>
/// <remarks>
/// <b>Why a flat pool <i>and</i> per-phase groups.</b> The pool supplies network identity: one
/// array, one index per card, identical on every peer. <c>PhaseDefinition.EnemyUpgradeGroups</c>
/// supplies gating: which of those cards a given phase may offer. Folding gating into the pool
/// would make ids phase-relative and therefore unstable across a phase change, which is
/// exactly when replicated slot upgrades are being cleared and rewritten.
///
/// <para>Plain MonoBehaviour — identical assets on every peer, so there is nothing to sync.
/// The server reads it to generate and resolve votes; clients read it to render vote cards
/// from replicated ids.</para>
/// </remarks>
public class EnemyUpgradePool : MonoBehaviour
{
public static EnemyUpgradePool Instance { get; private set; }
[Tooltip("Every EnemyUpgradeOption asset that can appear this match. Array index is the " +
"id used over the network — reordering mid-development is fine, but not between " +
"a host and its clients.")]
[SerializeField] private EnemyUpgradeOption[] options;
private void Awake()
{
if (Instance != null && Instance != this)
{
Debug.LogError("[EnemyUpgradePool] Multiple instances detected. Only one per scene.");
return;
}
Instance = this;
}
private void OnDestroy()
{
if (Instance == this) Instance = null;
}
/// <summary>Number of options in the pool.</summary>
public int Count => options?.Length ?? 0;
/// <summary>Returns the option at <paramref name="id"/>, or null if out of range.</summary>
public EnemyUpgradeOption Get(int id)
=> (options != null && id >= 0 && id < options.Length) ? options[id] : null;
/// <summary>Resolves an option asset back to its pool id, or -1 if it isn't in the pool.</summary>
public int GetId(EnemyUpgradeOption option)
{
if (options == null || option == null) return -1;
for (int i = 0; i < options.Length; i++)
if (options[i] == option) return i;
return -1;
}
/// <summary>
/// Collects the pool ids of every card the given phase groups allow. Cards missing from
/// the pool are reported once and skipped — an authored group referencing an unpooled
/// card is a wiring mistake that would otherwise silently shrink the vote.
/// </summary>
public void CollectAllowedIds(EnemyUpgradeGroup[] phaseGroups,
List<EnemyUpgradePoolEntry> entryScratch,
List<int> intoIds,
List<float> intoWeights)
{
intoIds.Clear();
intoWeights.Clear();
EnemyUpgradeGroup.CollectCandidates(phaseGroups, entryScratch);
foreach (var entry in entryScratch)
{
int id = GetId(entry.Option);
if (id < 0)
{
Debug.LogWarning($"[EnemyUpgradePool] '{entry.Option.name}' is referenced by a " +
$"phase's upgrade groups but is not in the pool — it can " +
$"never be offered. Add it to the pool's options array.");
continue;
}
intoIds.Add(id);
intoWeights.Add(entry.Weight);
}
}
}
}