62e48a3b0b
The 2026-08-06 audit found the shipping scene was still the abandoned co-op-Hades game with LANTERN combat bolted on, and that a third of the codebase was live code for a direction abandoned on 2026-07-13. Operator chose deletion over freezing: "everything is saved in source control if needed. I want the project to be clean." DELETED (~140 source files, Scripts 335->231, Tests 77->43): - Enemy variants + boss (H3). ChargerAuthoring / SpitterAuthoring / SwarmerAuthoring were attached to ZERO prefabs, so LungeState / SpitterState / SwarmerTag were never baked: ~272 lines of Bursted AI passes, BossAISystem (261 lines) and the whole MixBands escalation curve could not match a single chunk at runtime, while 734 lines of green tests certified them. Both shipping enemy prefabs were already byte-identical in stats. - Run/room lifecycle: RunDirector FSM, RunInfo/RunMap/RoomPlan/RoomTag, route select, portal interact, ready-check, room field/teardown. - Meta shop, prep loadout, boons (incl. KillRewardSystem and DashTrailDamageSystem, which existed only to serve boon flags). - Build palette + structures, shared storage, inventory/equipment (already recorded PAUSED in CLAUDE.md). - The HUD panels driving all of the above (HudSystem 1168 -> 610). KEPT deliberately: BaseGridMath + BaseAnchor (8 systems use PlotCenter for spawn rings, respawn and dynamic light), the resource ledger + StorageMath, the save system, region/relevancy. Three of these were in the delete set until I checked their consumers — worth remembering that the file-level manifest was wrong about them. Also folds in audit finding M5: PlayerClass was a second, server-only copy of the byte FrameId already replicates. It existed for the meta shop; with that gone, FrameId is the single frame identity. Harvest is now single-sink (ledger). HarvestMath keeps its shape so LANTERN's carried-vs-banked cargo split lands in one place, not two. 295/295 EditMode green, zero compile errors. Subscene re-bake and Play validation follow in the next commit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
172 lines
9.7 KiB
C#
172 lines
9.7 KiB
C#
using ProjectM.Simulation;
|
|
using Rukhanka; // FastAnimatorParameter, AnimatorParametersAspect, ParameterValue,
|
|
// AnimatorControllerParameterComponent, AnimatorControllerParameterIndexTableComponent,
|
|
// RukhankaAnimationSystemGroup
|
|
using Unity.Burst;
|
|
using Unity.Collections;
|
|
using Unity.Entities;
|
|
using Unity.Mathematics;
|
|
using Unity.Transforms; // LocalTransform
|
|
|
|
namespace ProjectM.Client
|
|
{
|
|
/// <summary>
|
|
/// Client-only animation driver for Husk ENEMIES. OBSERVES replicated state and writes Rukhanka animator
|
|
/// blend params; never mutates the sim (presentation-only). The enemy mirror of the REMOTE path of
|
|
/// <see cref="PlayerAnimationDriveSystem"/>: a Husk is an OWNERLESS INTERPOLATED ghost (server-moved by
|
|
/// EnemyAISystem, position+rotation via stock LocalTransform replication, no KinematicCharacterBody on the
|
|
/// client) — structurally identical to a remote player — so planar velocity is derived from replicated
|
|
/// <see cref="LocalTransform.Position"/> frame-deltas, facing from the replicated <see cref="LocalTransform.Rotation"/>
|
|
/// (the server faces the target each tick), and the run-blend normalizer from the baked-on-both-worlds
|
|
/// <see cref="EnemyStats.MoveSpeed"/>. The attack telegraph rides the already-replicated
|
|
/// <see cref="AttackWindup"/> [GhostField] (non-zero for the ~0.3s wind-up) — no new [GhostField], no server
|
|
/// change (Rukhanka is stripped server-side by ServerStripAnimationSystem), no ghost-hash change. See DR-023.
|
|
/// <para>
|
|
/// Runs in SimulationSystemGroup via [UpdateBefore(RukhankaAnimationSystemGroup)] so params are set before
|
|
/// Rukhanka's same-frame controller eval (no 1-tick lag) — the same documented exception to the
|
|
/// "all juice = PresentationSystemGroup" rule the player driver uses. Observe-only, never in the predicted loop.
|
|
/// </para>
|
|
/// <para>
|
|
/// NOTE: deliberately NOT [RequireMatchingQueriesForUpdate]. Husks despawn far more often than players, so the
|
|
/// per-frame prevPos prune must run EVERY frame (even with zero live Husks) to reclaim the cache entry of a
|
|
/// just-killed Husk — otherwise one NativeParallelHashMap entry would leak per kill.
|
|
/// </para>
|
|
/// </summary>
|
|
[WorldSystemFilter(WorldSystemFilterFlags.LocalSimulation | WorldSystemFilterFlags.ClientSimulation)]
|
|
[UpdateBefore(typeof(RukhankaAnimationSystemGroup))]
|
|
public partial class EnemyAnimationDriveSystem : SystemBase
|
|
{
|
|
// Perfect-hash keys, built once. Names MUST match AC_EnemyTopDown.controller parameter names exactly.
|
|
static readonly FastAnimatorParameter k_MoveX = new FastAnimatorParameter("MoveX");
|
|
static readonly FastAnimatorParameter k_MoveZ = new FastAnimatorParameter("MoveZ");
|
|
static readonly FastAnimatorParameter k_Speed = new FastAnimatorParameter("Speed");
|
|
static readonly FastAnimatorParameter k_IsAttacking = new FastAnimatorParameter("IsAttacking");
|
|
static readonly FastAnimatorParameter k_IsDead = new FastAnimatorParameter("IsDead"); // B3: the controller's Death state existed but was never driven
|
|
static readonly FastAnimatorParameter k_IsHit = new FastAnimatorParameter("IsHit"); // 07-21 hit-react (G5): pulsed off replicated Health-drop edges
|
|
static readonly FastAnimatorParameter k_IsHitHeavy = new FastAnimatorParameter("IsHitHeavy"); // heavy tier -> HitStagger (aligns with the server's B2 poise break)
|
|
|
|
/// <summary>07-21: per-Husk anim cache -- position (velocity derivation), Health (the hit-react damage
|
|
/// edge), and the active flinch pulse. Pruned every frame (a vanished Husk = a server-authoritative death).</summary>
|
|
struct EnemyAnimCache
|
|
{
|
|
public float3 Pos;
|
|
public float Hp;
|
|
public float ReactUntil; // wall-clock ElapsedTime the flinch pulse ends (0 = none)
|
|
public bool Heavy; // this pulse is the stagger tier
|
|
}
|
|
|
|
NativeParallelHashMap<Entity, EnemyAnimCache> _prevPos;
|
|
|
|
protected override void OnCreate()
|
|
{
|
|
_prevPos = new NativeParallelHashMap<Entity, EnemyAnimCache>(64, Allocator.Persistent);
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
if (_prevPos.IsCreated) _prevPos.Dispose();
|
|
}
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
float dt = SystemAPI.Time.DeltaTime; // wall-frame delta is correct for presentation
|
|
if (dt < 1e-5f) dt = 1e-5f;
|
|
|
|
var seen = new NativeParallelHashSet<Entity>(64, Allocator.TempJob);
|
|
var job = new EnemyDriveJob
|
|
{
|
|
moveX = k_MoveX, moveZ = k_MoveZ, speed = k_Speed, isAttacking = k_IsAttacking, isDead = k_IsDead,
|
|
isHit = k_IsHit, isHitHeavy = k_IsHitHeavy,
|
|
// 07-21 hit-react knobs (read main-thread, passed by value -- never FeelConfig inside Burst)
|
|
el = (float)SystemAPI.Time.ElapsedTime,
|
|
reactSeconds = math.max(0f, FeelConfig.HitReactSeconds),
|
|
staggerSeconds = math.max(0f, FeelConfig.HitStaggerSeconds),
|
|
staggerDamage = math.max(1f, FeelConfig.HitReactStaggerDamage),
|
|
dt = dt,
|
|
prevPos = _prevPos,
|
|
seen = seen,
|
|
|
|
};
|
|
Dependency = job.Schedule(Dependency); // .Schedule (not parallel): mutates _prevPos
|
|
// Prune stale entries (despawned Husks) AFTER the job, on the main thread.
|
|
Dependency.Complete();
|
|
PruneCache(seen);
|
|
seen.Dispose();
|
|
}
|
|
|
|
void PruneCache(NativeParallelHashSet<Entity> seen)
|
|
{
|
|
using var keys = _prevPos.GetKeyArray(Allocator.Temp);
|
|
for (int i = 0; i < keys.Length; i++)
|
|
if (!seen.Contains(keys[i])) _prevPos.Remove(keys[i]);
|
|
}
|
|
|
|
// Husks are ownerless interpolated ghosts: no local/remote split, no Dead enableable. Velocity from
|
|
// LocalTransform.Position delta; facing from LocalTransform.Rotation (server-faced); IsAttacking from the
|
|
// replicated AttackWindup telegraph. The Rukhanka param components match only rigged ghosts.
|
|
[BurstCompile]
|
|
[WithAll(typeof(EnemyTag))]
|
|
partial struct EnemyDriveJob : IJobEntity
|
|
{
|
|
public FastAnimatorParameter moveX, moveZ, speed, isAttacking, isDead, isHit, isHitHeavy;
|
|
public float el, reactSeconds, staggerSeconds, staggerDamage; // 07-21 hit-react (reactSeconds 0 = off)
|
|
|
|
|
|
public float dt;
|
|
public NativeParallelHashMap<Entity, EnemyAnimCache> prevPos;
|
|
public NativeParallelHashSet<Entity> seen;
|
|
|
|
void Execute(
|
|
Entity e,
|
|
AnimatorControllerParameterIndexTableComponent indexTable,
|
|
DynamicBuffer<AnimatorControllerParameterComponent> parametersArr,
|
|
in LocalTransform xform,
|
|
in EnemyStats stats,
|
|
in AttackWindup windup,
|
|
in Health health)
|
|
{
|
|
seen.Add(e);
|
|
float3 cur = xform.Position;
|
|
float3 vel = float3.zero;
|
|
var cache = new EnemyAnimCache { Pos = cur, Hp = health.Current };
|
|
if (prevPos.TryGetValue(e, out var prev))
|
|
{
|
|
vel = (cur - prev.Pos) / dt;
|
|
cache.ReactUntil = prev.ReactUntil;
|
|
cache.Heavy = prev.Heavy;
|
|
// 07-21 hit-react (G5): a replicated Health DROP on a living Husk = the flinch edge. The heavy
|
|
// tier (>= staggerDamage, e.g. the finisher) plays the stagger -- aligned with the server's B2
|
|
// poise break, so the anim never claims an interrupt the sim didn't make.
|
|
float drop = prev.Hp - health.Current;
|
|
if (drop > 0.01f && health.Current > 0f && reactSeconds > 0f)
|
|
{
|
|
cache.Heavy = drop >= staggerDamage;
|
|
cache.ReactUntil = el + (cache.Heavy ? staggerSeconds : reactSeconds);
|
|
}
|
|
}
|
|
prevPos[e] = cache;
|
|
|
|
float2 facing = AnimParamMath.PlanarForward(xform.Rotation);
|
|
float3 p = AnimParamMath.LocomotionParams(vel, facing, stats.MoveSpeed);
|
|
bool attacking = windup.WindUpUntilTick != 0; // the IsLunging OR went with the Charger purge (2026-08-07)
|
|
|
|
// B3: the corpse window — Health.Current is replicated, so <=0 IS the death read. A corpse
|
|
// plays the Death state and nothing else (no jog, no frozen attack).
|
|
bool dead = health.Current <= 0f;
|
|
if (dead) { p = float3.zero; attacking = false; }
|
|
|
|
var a = new AnimatorParametersAspect(parametersArr, indexTable);
|
|
if (a.HasParameter(moveX)) a.SetParameterValue(moveX, p.x);
|
|
if (a.HasParameter(moveZ)) a.SetParameterValue(moveZ, p.y);
|
|
if (a.HasParameter(speed)) a.SetParameterValue(speed, p.z);
|
|
if (a.HasParameter(isAttacking)) a.SetParameterValue(isAttacking, attacking);
|
|
if (a.HasParameter(isDead)) a.SetParameterValue(isDead, dead);
|
|
// 07-21 hit-react pulse (a corpse never flinches; the controller adds the windup-honesty gate).
|
|
bool hitActive = !dead && cache.ReactUntil > 0f && el < cache.ReactUntil;
|
|
if (a.HasParameter(isHit)) a.SetParameterValue(isHit, hitActive);
|
|
if (a.HasParameter(isHitHeavy)) a.SetParameterValue(isHitHeavy, hitActive && cache.Heavy);
|
|
}
|
|
}
|
|
}
|
|
}
|