Files
Project-M/Assets/_Project/Scripts/Server/Debug/DebugModifierInjectionSystem.cs
T
kronic 4a8220ad3e LANTERN purge B6: delete the legacy single-ability path (sockets are THE ability model)
AbilityRef, AbilityCooldown, EffectiveAbilityStats, DefaultAbility deleted.
GoInGameServerSystem seeds the per-frame 4-socket Spark loadout UNCONDITIONALLY
(was gym-only); ClassSelectReceiveSystem + DebugOp.SetClass swap FrameId +
re-seed sockets + zero SocketCooldown; ClassSwapUtil.Apply drops newAbilityId;
EquipSystem weapons become stat-sticks (GrantedAbilityId removed from the item
blob/authoring); StatRecomputeSystem folds CharacterStatsRef + sockets only;
HUD cooldown bar reads socket 0 of SocketCooldown/EffectiveSocketStats; class
HUD readers are FrameId-only (ClassForAbility/AbilityFor deleted);
DebugModifierInjectionSystem drops CycleAbility.

390 tests green; Play-verified: a non-gym spawn gets frame=2 with Sparks
[7,8,6,9] and no console errors.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 15:47:12 -07:00

73 lines
2.8 KiB
C#

#if UNITY_EDITOR
using System.Collections.Generic;
using ProjectM.Simulation;
using Unity.Entities;
using Unity.NetCode;
namespace ProjectM.Server
{
/// <summary>
/// Editor-only debug hook (mirrors ProjectM.Client.DebugInputInjectionSystem's static-poke pattern)
/// for driving the server-authoritative modifier stack from MCP execute_code. Because modifiers are
/// server-authoritative, a client-side append would be stomped by the next snapshot, so this runs in
/// the SERVER world: the change flows back through the snapshot and is prediction-correct on the
/// client. In-editor single-process only (client + server worlds in one process). Poke from execute_code:
/// DebugModifierInjectionSystem.AddModifier((byte)StatTarget.Damage, (byte)ModOp.Flat, 50f);
/// DebugModifierInjectionSystem.AddModifier((byte)StatTarget.MoveSpeed, (byte)ModOp.PercentAdd, 0.5f);
/// DebugModifierInjectionSystem.ClearModifiers();
/// All applied to the first player on the next server tick.
/// </summary>
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial class DebugModifierInjectionSystem : SystemBase
{
struct PendingModifier { public byte Target; public byte Op; public float Value; }
static readonly List<PendingModifier> s_Pending = new List<PendingModifier>();
static bool s_Clear;
/// <summary>Queue a modifier to append to the first player on the next server tick.</summary>
public static void AddModifier(byte target, byte op, float value)
{
s_Pending.Add(new PendingModifier { Target = target, Op = op, Value = value });
}
/// <summary>Clear the first player's whole modifier stack on the next server tick.</summary>
public static void ClearModifiers() => s_Clear = true;
protected override void OnUpdate()
{
if (s_Pending.Count == 0 && !s_Clear)
return;
Entity player = Entity.Null;
foreach (var (tag, e) in
SystemAPI.Query<RefRO<PlayerTag>>().WithAll<StatModifier>().WithEntityAccess())
{
player = e;
break;
}
if (player == Entity.Null)
return;
if (s_Clear)
{
EntityManager.GetBuffer<StatModifier>(player).Clear();
s_Clear = false;
}
if (s_Pending.Count > 0)
{
var buffer = EntityManager.GetBuffer<StatModifier>(player);
for (int i = 0; i < s_Pending.Count; i++)
{
var m = s_Pending[i];
buffer.Add(new StatModifier { Target = m.Target, Op = m.Op, Value = m.Value, SourceId = 0u });
}
s_Pending.Clear();
}
}
}
}
#endif