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,69 @@
// Assets/_Project/Scripts/Gameplay/Waves/WaveGroup.cs
using System;
using UnityEngine;
using TD.Core;
namespace TD.Gameplay.Waves
{
/// <summary>
/// One weighted candidate inside a <see cref="WaveGroup"/>: a wave that may be drawn,
/// and how likely it is to be drawn relative to the group's other entries.
/// </summary>
/// <remarks>
/// <b>Weight is RELATIVE, not an absolute probability.</b> The draw normalizes every
/// candidate's weight against the summed weight of the whole candidate set, so three
/// entries at 1.0 each are equally likely (33% apiece) and an entry at 0.5 is half as
/// likely to be drawn as one at 1.0. This is what makes the default sane: new entries
/// start at 1.0, so adding a wave to a group never silently re-weights the others.
///
/// <para>A class rather than a struct specifically so <see cref="Weight"/> can carry a
/// field initializer — Unity runs it when the inspector creates a fresh array element,
/// which is what gives new entries their equal-by-default weighting. Mirrors
/// <see cref="WaveGoldEntry"/>.</para>
/// </remarks>
[Serializable]
public class WavePoolEntry
{
[Tooltip("The wave that may be drawn from this group.")]
public WaveDefinition Wave;
[Tooltip("Relative draw weight within this group's pool. Entries at equal weight are " +
"equally likely; an entry at 0.5 is half as likely as one at 1.0. NOT an " +
"absolute percentage.")]
[PoolWeight("wave")]
public float Weight = 1f;
}
/// <summary>
/// A named, reusable bag of candidate waves. Groups are the unit designers move between
/// phases: dragging a group asset from Phase 1's pool to Phase 2's moves every wave in it
/// (and their weights) in one action.
/// </summary>
/// <remarks>
/// <b>Why weights live on the entry, not on <see cref="WaveDefinition"/>.</b> Weight is a
/// property of "how common is this wave <i>in this pool</i>", not of the wave itself. Keeping
/// it here means the same <see cref="WaveDefinition"/> asset can be a staple of one group and
/// a rarity in another, and a group carries its tuning with it when moved between phases.
///
/// <para><b>Boss groups use the same type.</b> A boss wave is just a
/// <see cref="WaveDefinition"/> whose entries spawn a single powerful enemy, so boss pools
/// are ordinary <see cref="WaveGroup"/>s referenced from
/// <see cref="PhaseDefinition.BossGroups"/>.</para>
/// </remarks>
[CreateAssetMenu(fileName = "WaveGroup", menuName = "TD/Run/Wave Group", order = 10)]
public class WaveGroup : ScriptableObject
{
[Tooltip("Designer-facing name for this group, shown in run-structure validation " +
"messages. Falls back to the asset name when empty.")]
public string DisplayName;
[Tooltip("Candidate waves in this group, each with a relative draw weight.")]
public WavePoolEntry[] Waves;
/// <summary>Name used in validation and log messages. Falls back to the asset name.</summary>
public string Label => string.IsNullOrWhiteSpace(DisplayName) ? name : DisplayName;
/// <summary>Number of entries, including any that are null or zero-weight.</summary>
public int Count => Waves?.Length ?? 0;
}
}