UnityTowerDefense/Assets/_Project/Scripts/Dev/DevWaveControls.cs
Matt F 4892d7253d 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>
2026-07-30 17:45:11 -07:00

153 lines
6.5 KiB
C#

// Assets/_Project/Scripts/Dev/DevWaveControls.cs
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using TD.Gameplay;
namespace TD.Dev
{
/// <summary>
/// Editor / testing convenience: shows an OnGUI button in the top-left
/// corner that force-advances the wave on the server. Add this component
/// to any GameObject in the scene (e.g. a "DevTools" empty) during testing,
/// disable or remove for shipping builds.
/// </summary>
/// <remarks>
/// The button calls <see cref="WaveManager.ForceAdvanceToNextWave"/>, which
/// despawns active enemies, stops the current wave's coroutine, and starts
/// the next wave with no prep delay.
///
/// Server-side only — the OnGUI button is gated to <c>NetworkManager.IsServer</c>
/// so clients connected to a remote host don't see it. The hotkey path is
/// also server-gated to avoid surprising results when pressed on a client.
/// </remarks>
public class DevWaveControls : MonoBehaviour
{
[Tooltip("Keyboard shortcut to force-advance to the next wave. " +
"Uses the new Input System (UnityEngine.InputSystem.Key). " +
"Set to Key.None to use the OnGUI button only.")]
[SerializeField] private Key hotkey = Key.F9;
[Tooltip("Keyboard shortcut to grant the local player the next catalog tower not " +
"yet in their deck. Stand-in for the draft system so deck growth can be " +
"verified now. Set to Key.None to use the OnGUI button only.")]
[SerializeField] private Key grantTowerHotkey = Key.F8;
[Tooltip("Keyboard shortcut to skip every remaining encounter in the current phase and " +
"go straight to its boss. Set to Key.None to use the OnGUI button only.")]
[SerializeField] private Key skipToBossHotkey = Key.F7;
private void Update()
{
var kb = Keyboard.current;
if (kb == null) return; // no keyboard connected (e.g. headless server)
if (hotkey != Key.None && kb[hotkey].wasPressedThisFrame)
TryForceNextWave();
if (grantTowerHotkey != Key.None && kb[grantTowerHotkey].wasPressedThisFrame)
TryGrantNextTower();
if (skipToBossHotkey != Key.None && kb[skipToBossHotkey].wasPressedThisFrame)
TrySkipToBoss();
}
private void OnGUI()
{
// Only show the button on the server (host or dedicated). Clients
// calling this from afar would no-op anyway.
if (NetworkManager.Singleton == null || !NetworkManager.Singleton.IsServer)
return;
// IMGUI draws after every runtime UI Toolkit panel, so this box would cover the
// debug console's autocomplete list no matter what sorting order the console's
// PanelSettings uses. Yield to the console while it's open.
if (DebugConsole.IsOpen) return;
// Anchored below the top HUD bar so it doesn't overlap gold/wave/lives.
const float topOffset = 90f;
GUI.Box(new Rect(10, topOffset, 180, 128), "Dev: Wave Controls");
if (GUI.Button(new Rect(20, topOffset + 25, 160, 28), "Force Next Wave"))
TryForceNextWave();
if (GUI.Button(new Rect(20, topOffset + 58, 160, 28), "Grant Next Tower"))
TryGrantNextTower();
if (GUI.Button(new Rect(20, topOffset + 91, 160, 28), "Skip To Boss"))
TrySkipToBoss();
}
// Dev stand-in for the draft system: grants the local player the first catalog
// tower they haven't unlocked yet, so deck growth + the HUD's live rebuild can be
// verified before the real draft exists. Server-only (host); ServerGrantTower
// no-ops elsewhere.
private void TryGrantNextTower()
{
if (NetworkManager.Singleton == null || !NetworkManager.Singleton.IsServer)
{
Debug.LogWarning("[DevWaveControls] Grant-tower requested off the server. Ignored.");
return;
}
var placement = TowerPlacementManager.Instance;
var deck = PlayerTowerDeck.Local;
if (placement == null || deck == null)
{
Debug.LogWarning("[DevWaveControls] Cannot grant tower — TowerPlacementManager " +
"or local PlayerTowerDeck is not ready.");
return;
}
foreach (var (def, typeId) in placement.GetAvailableDefinitions())
{
if (deck.Contains(typeId)) continue;
if (deck.ServerGrantTower(typeId))
Debug.Log($"[DevWaveControls] Granted '{def.DisplayName}' (typeId {typeId}) " +
$"to the local deck.");
return;
}
Debug.Log("[DevWaveControls] Local deck already contains every catalog tower.");
}
private void TryForceNextWave()
{
if (NetworkManager.Singleton == null || !NetworkManager.Singleton.IsServer)
{
Debug.LogWarning("[DevWaveControls] Force-advance requested off the server. Ignored.");
return;
}
var wm = WaveManager.Instance;
if (wm == null)
{
Debug.LogWarning("[DevWaveControls] WaveManager.Instance is null. " +
"Is the scene running with a WaveManager network-spawned?");
return;
}
Debug.Log("[DevWaveControls] Forcing next wave.");
wm.ForceAdvanceToNextWave();
}
// Skips straight to the phase boss so boss content can be tested without playing
// every cycle first. Server-only, like the other cheats.
private void TrySkipToBoss()
{
if (NetworkManager.Singleton == null || !NetworkManager.Singleton.IsServer)
{
Debug.LogWarning("[DevWaveControls] Skip-to-boss requested off the server. Ignored.");
return;
}
var wm = WaveManager.Instance;
if (wm == null)
{
Debug.LogWarning("[DevWaveControls] WaveManager.Instance is null. " +
"Is the scene running with a WaveManager network-spawned?");
return;
}
Debug.Log("[DevWaveControls] Skipping to boss.");
wm.ForceAdvanceToBoss();
}
}
}