Files
kronic a74b761363 Dev tool: switch player class (Warrior/Ranger) at runtime for testing
Editor-only class swap via the existing scalar dev-RPC family (new DebugOp.SetClass): F1/F2 keybind (ClassSwitchHotkeySystem), DebugOverlay '- Class -' buttons, and DebugCommandSendSystem.SetWarrior/SetRanger/SetClass statics. Server (DebugCommandReceiveSystem) swaps class in place on the spawned player: strips+re-seeds the ClassTraits StatModifier seeds, swaps the AbilityRef Fire slot, resets the ability cooldown, and heals a LIVING player to the new max (dead players skip the heal so respawn isn't raced). Server-authoritative + prediction-correct (same buffer-mutation path as GrantUpgrade); wire type unchanged so the RpcCollection hash is unaffected.

ClassTraits gains a shared Seeds core (spawn + swap can't drift), ClassSeedCount, IsClassSeed, a DynamicBuffer AppendSeeds overload, and Reapply. +3 EditMode tests (exact-count round-trip, value-equality fold, boundary/foreign-mod preservation); 351/351 green; Warrior<->Ranger round-trip Play-validated (server+client agree).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 21:23:33 -07:00

155 lines
8.0 KiB
C#

#if UNITY_EDITOR
using ProjectM.Simulation;
using UnityEngine;
namespace ProjectM.Client
{
/// <summary>
/// EDITOR-ONLY in-game dev-tools overlay (IMGUI dev overlay). Buttons enqueue
/// <see cref="DebugCommandRequest"/> RPCs through <see cref="DebugCommandSendSystem"/>, so they drive the REAL
/// server-authoritative paths (and work over a live connection too, not just in-editor). Drop it on a
/// GameObject in the DevSandbox (or Game) scene. While open it forces the OS cursor visible
/// (<see cref="AimPresentation.ForceCursorVisible"/>) so its buttons stay clickable even while aiming.
/// Stripped from player builds (#if UNITY_EDITOR).
/// </summary>
public class DebugOverlay : MonoBehaviour
{
bool _open = true;
int _siegeSize = 5;
int _grantAmount = 50;
bool _tuningOpen;
Vector2 _scroll;
void OnDisable() => AimPresentation.ForceCursorVisible = false;
void OnGUI()
{
if (GUI.Button(new Rect(Screen.width - 96, 10, 86, 24), _open ? "DEV ▲" : "DEV ▼"))
_open = !_open;
AimPresentation.ForceCursorVisible = _open;
if (!_open)
return;
float panelH = Mathf.Min(760f, Screen.height - 50f);
GUILayout.BeginArea(new Rect(Screen.width - 232, 40, 222, panelH), GUI.skin.box);
GUILayout.Label("DEV TOOLS");
_scroll = GUILayout.BeginScrollView(_scroll);
GUILayout.Label("- World -");
_siegeSize = IntField("Siege size", _siegeSize);
if (GUILayout.Button("Spawn Wave / Force Siege")) DebugCommandSendSystem.SpawnWave(_siegeSize);
if (GUILayout.Button("End Siege")) DebugCommandSendSystem.EndSiege();
if (GUILayout.Button("Clear Enemies")) DebugCommandSendSystem.ClearEnemies();
if (GUILayout.Button("Force Calm")) DebugCommandSendSystem.SetCalm();
if (GUILayout.Button("Advance Goal +1")) DebugCommandSendSystem.AdvanceGoal(1);
GUILayout.Space(6);
GUILayout.Label("- Resources -");
_grantAmount = IntField("Amount", _grantAmount);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Aether")) DebugCommandSendSystem.GrantResource(ResourceId.Aether, _grantAmount);
if (GUILayout.Button("Ore")) DebugCommandSendSystem.GrantResource(ResourceId.Ore, _grantAmount);
if (GUILayout.Button("Bio")) DebugCommandSendSystem.GrantResource(ResourceId.Biomass, _grantAmount);
GUILayout.EndHorizontal();
if (GUILayout.Button("Grant Damage Upgrade")) DebugCommandSendSystem.GrantUpgrade();
GUILayout.Space(6);
GUILayout.Label("- Player -");
GUILayout.BeginHorizontal();
if (GUILayout.Button("Heal")) DebugCommandSendSystem.Heal();
if (GUILayout.Button("Kill")) DebugCommandSendSystem.Kill();
if (GUILayout.Button("God")) DebugCommandSendSystem.ToggleGod();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Go Base")) DebugCommandSendSystem.Teleport(RegionId.Base);
if (GUILayout.Button("Go Expedition")) DebugCommandSendSystem.Teleport(RegionId.Expedition);
GUILayout.EndHorizontal();
GUILayout.Space(6);
GUILayout.Label("- Class (F1/F2) -");
GUILayout.BeginHorizontal();
if (GUILayout.Button("Warrior")) DebugCommandSendSystem.SetWarrior();
if (GUILayout.Button("Ranger")) DebugCommandSendSystem.SetRanger();
GUILayout.EndHorizontal();
GUILayout.Space(6);
GUILayout.Label("- Telemetry (MC-0) -");
if (DevTelemetryReadout.HasData)
{
var t = DevTelemetryReadout.Latest;
GUILayout.Label($"tick {t.LastSampleTick} husks {t.LiveEnemyCount}");
GUILayout.Label($"dash neg {t.DashIFrameNegatedHits} / wasted {t.DashesWasted}");
GUILayout.Label($"whiff open {t.ChargerWhiffWindowsOpened} / punish {t.ChargerWhiffPunishesLanded}");
}
else
{
GUILayout.Label("(waiting for server telemetry...)");
}
GUILayout.Space(6);
_tuningOpen = GUILayout.Toggle(_tuningOpen, "- Tuning (MC-0) -");
if (_tuningOpen)
{
TuningRow("Dash dist", TuningKnob.DashDistance, 0.5f, "0.0");
TuningRow("Dash iframe t", TuningKnob.IFrameWindowTicks, 1f, "0");
TuningRow("Dash recover t", TuningKnob.RecoverTailTicks, 1f, "0");
TuningRow("Dash cd t", TuningKnob.DashCooldownTicks, 1f, "0");
TuningRow("Dash sharp", TuningKnob.DashSharpness, 25f, "0");
TuningRow("Chgr windup t", TuningKnob.ChargerWindupTicks, 1f, "0");
TuningRow("Chgr lunge spd", TuningKnob.ChargerLungeSpeed, 1f, "0.0");
TuningRow("Chgr lunge t", TuningKnob.ChargerLungeDurationTicks, 1f, "0");
TuningRow("Chgr stagger t", TuningKnob.ChargerWhiffStaggerTicks, 1f, "0");
TuningRow("Grunt windup t", TuningKnob.GruntWindupTicks, 1f, "0");
GUILayout.Space(4);
TuningRow("Melee dmg", TuningKnob.MeleeDamage, 1f, "0.0");
TuningRow("Melee range", TuningKnob.MeleeRange, 0.2f, "0.0");
TuningRow("Melee cone rad", TuningKnob.MeleeConeHalfAngleRad, 0.05f, "0.00");
TuningRow("Melee recover t", TuningKnob.MeleeRecoverTicks, 1f, "0");
TuningRow("Melee chain t", TuningKnob.MeleeChainGraceTicks, 1f, "0");
TuningRow("Melee move x", TuningKnob.MeleeSwingMoveScale, 0.05f, "0.00");
TuningRow("Melee knock spd", TuningKnob.MeleeKnockbackSpeed, 1f, "0.0");
TuningRow("Melee finish x", TuningKnob.MeleeFinisherMult, 0.1f, "0.0");
TuningRow("Melee combo len", TuningKnob.MeleeComboLength, 1f, "0");
GUILayout.Space(4);
TuningRow("Struct aggro w", TuningKnob.StructureAggroWeight, 0.1f, "0.00"); // EB-1: <1 prefers structures
TuningRow("Core dmg/husk", TuningKnob.CoreDamagePerHusk, 1f, "0"); // END-1: integrity per breaching Husk
TuningRow("Core regen int", TuningKnob.CoreRegenIntervalTicks, 1f, "0"); // END-1: ticks between +1 in Calm
TuningRow("Core overrun %", TuningKnob.CoreOverrunDrainPct, 0.05f, "0.00"); // END-1: ledger fraction lost on breach
}
GUILayout.EndScrollView();
GUILayout.EndArea();
}
static int IntField(string label, int value)
{
GUILayout.BeginHorizontal();
GUILayout.Label(label, GUILayout.Width(70));
string s = GUILayout.TextField(value.ToString(), GUILayout.Width(60));
GUILayout.EndHorizontal();
return int.TryParse(s, out var v) ? v : value;
}
// One live-tuning row: shows the current value (from the readout) + step buttons. A nudge fires the
// authoritative server RPC AND an optimistic local apply (so the tuner's own predicted dash uses it now).
static void TuningRow(string label, byte knob, float step, string fmt)
{
float cur = ProjectM.Simulation.TuningConfig.Get(TuningReadout.Current, knob);
GUILayout.BeginHorizontal();
GUILayout.Label(label, GUILayout.Width(92));
GUILayout.Label(cur.ToString(fmt), GUILayout.Width(40));
if (GUILayout.Button("-", GUILayout.Width(26))) Nudge(knob, cur - step);
if (GUILayout.Button("+", GUILayout.Width(26))) Nudge(knob, cur + step);
GUILayout.EndHorizontal();
}
static void Nudge(byte knob, float value)
{
DebugCommandSendSystem.SetTuning(knob, value); // authoritative (server applies + broadcasts; clamped)
TuningReadout.SetLocal(knob, value); // optimistic local (instant feel for the tuner; clamped)
}
}
}
#endif