589e712db3
Delete (unreferenced in any scene, per operator decision):
- TrainingDummy* chain (authoring/spawner/system/components/prefab) + UpgradePickup* chain (authoring/spawner/systems/components/prefab); remove TrainingDummyTag from the 3 live combat queries (AbilityFire/Melee/HealthApplyDamage now key on EnemyTag) and repoint HealthApplyDamageSystemTests to EnemyTag.
- Dead RPC RegionTransitSystem + RegionTransitRequest (no sender, ungated) + its test.
- Heartbeat + HeartbeatSystem (no WorldSystemFilter, ran no-op every tick) + its test.
- BuildSendSystem dead conveyor/pylon dev hooks (s_ConveyorDir, [/] rotation, Place{Pylon,Harvester,Conveyor} statics).
- Deprecated CyclePhase alias consts (Expedition/Defend/Build/*Ticks); repoint WaveSystemTests to Siege/Calm.
- Unread FeelConfig fields (HitFlashDurationMs, RumbleHeavy) + dangling HudUi doc-comments + stale crefs.
451/451 EditMode tests pass. CLAUDE.md HeartbeatSystemTests example ref to be repointed in B7.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
187 lines
10 KiB
C#
187 lines
10 KiB
C#
using ProjectM.Simulation;
|
|
using Unity.Burst;
|
|
using Unity.Collections;
|
|
using Unity.Entities;
|
|
using Unity.Mathematics;
|
|
using Unity.NetCode;
|
|
|
|
namespace ProjectM.Server
|
|
{
|
|
/// <summary>
|
|
/// Server-authoritative damage application. Drains each damageable entity's
|
|
/// <see cref="DamageEvent"/> buffer (appended by <see cref="ProjectileDamageSystem"/> earlier
|
|
/// this tick), subtracts the summed amount from <see cref="Health"/>, then clears the buffer so
|
|
/// each hit is applied exactly once. Entities that carry character stats (players) clamp to their
|
|
/// data-driven <see cref="EffectiveCharacterStats.MaxHealth"/> ceiling; others (training dummies)
|
|
/// clamp at zero. A dead <see cref="EnemyTag"/> is destroyed; player death is deferred.
|
|
/// Health.Current is a <c>[GhostField]</c>, so the new value replicates to clients for display.
|
|
///
|
|
/// Runs server-only (<see cref="WorldSystemFilterFlags.ServerSimulation"/>) inside the prediction
|
|
/// group so it shares tick timing with movement/damage, where it executes once per tick. The
|
|
/// single structural change (destroying a dead dummy) is batched through a frame-allocator
|
|
/// <see cref="EntityCommandBuffer"/> that is played back immediately to the entity manager — so a
|
|
/// plain-world EditMode test needs no separate ECB system.
|
|
/// </summary>
|
|
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
|
|
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
|
|
[UpdateAfter(typeof(ProjectileDamageSystem))]
|
|
// Pin the drain AFTER DashSystem: a same-tick player-sourced projectile (ProjectileDamageSystem stamps
|
|
// SourceTick = now and this system drains the SAME tick) must see a dash window STARTED this tick —
|
|
// without the edge the negation at src == StartTick is an unconstrained sorter tiebreak. The Dash chain
|
|
// (StatRecompute→PlayerControl→Dash) and the projectile chain (PlayerAim→AbilityFire→ProjectileMove→
|
|
// ProjectileDamage→here) are otherwise disjoint, so this edge cannot form a cycle (Play-validated).
|
|
[UpdateAfter(typeof(DashSystem))]
|
|
[BurstCompile]
|
|
public partial struct HealthApplyDamageSystem : ISystem
|
|
{
|
|
[BurstCompile]
|
|
public void OnUpdate(ref SystemState state)
|
|
{
|
|
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
|
bool haveTick = SystemAPI.TryGetSingleton<NetworkTime>(out var netTime);
|
|
uint negatedThisTick = 0;
|
|
uint punishesThisTick = 0;
|
|
|
|
foreach (var (health, dmg, entity) in
|
|
SystemAPI.Query<RefRW<Health>, DynamicBuffer<DamageEvent>>()
|
|
.WithEntityAccess())
|
|
{
|
|
if (dmg.Length == 0)
|
|
continue;
|
|
// Dev god-mode: while enabled, this entity ignores ALL damage (server-authoritative, once per tick).
|
|
if (SystemAPI.HasComponent<DebugGodMode>(entity) && SystemAPI.IsComponentEnabled<DebugGodMode>(entity))
|
|
{
|
|
dmg.Clear();
|
|
continue;
|
|
}
|
|
|
|
|
|
// Respawn invulnerability: a freshly-recovered player ignores damage for a window.
|
|
if (haveTick && netTime.ServerTick.IsValid && SystemAPI.HasComponent<RespawnInvuln>(entity))
|
|
{
|
|
uint until = SystemAPI.GetComponent<RespawnInvuln>(entity).UntilTick;
|
|
if (until != 0)
|
|
{
|
|
var untilTick = new NetworkTick(until);
|
|
if (untilTick.IsValid && untilTick.IsNewerThan(netTime.ServerTick))
|
|
{
|
|
dmg.Clear();
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool hasDash = haveTick && netTime.ServerTick.IsValid && SystemAPI.HasComponent<DashState>(entity);
|
|
DashState ds = hasDash ? SystemAPI.GetComponent<DashState>(entity) : default;
|
|
|
|
bool isCharger = haveTick && netTime.ServerTick.IsValid && SystemAPI.HasComponent<LungeState>(entity);
|
|
uint negatedForThisEntity = 0u;
|
|
float total = 0f;
|
|
for (int i = 0; i < dmg.Length; i++)
|
|
{
|
|
uint src = dmg[i].SourceTick;
|
|
if (hasDash && src != 0u && ds.IFrameUntilTick != 0u)
|
|
{
|
|
var srcTick = new NetworkTick(src);
|
|
var startTick = new NetworkTick(ds.StartTick);
|
|
var untilTick = new NetworkTick(ds.IFrameUntilTick);
|
|
// Dash i-frames cover the HALF-OPEN window [StartTick, IFrameUntilTick): negate iff src >= start AND src < until.
|
|
bool atOrAfterStart = srcTick.IsValid && startTick.IsValid && !startTick.IsNewerThan(srcTick);
|
|
bool beforeUntil = untilTick.IsValid && untilTick.IsNewerThan(srcTick);
|
|
if (atOrAfterStart && beforeUntil)
|
|
{
|
|
negatedThisTick++;
|
|
negatedForThisEntity++;
|
|
continue; // dash i-frame negates this hit (per-element, not a whole-buffer clear)
|
|
}
|
|
}
|
|
total += dmg[i].Amount;
|
|
|
|
// MC-1 punish scoring: a player-sourced hit (SourceNetworkId >= 0) landing inside a Charger's
|
|
// whiff-stagger window counts ONCE — zeroing StaggerUntilTick keeps punishes:windows <= 1.
|
|
if (isCharger && dmg[i].SourceNetworkId >= 0)
|
|
{
|
|
var lunge = SystemAPI.GetComponent<LungeState>(entity);
|
|
if (lunge.StaggerUntilTick != 0u)
|
|
{
|
|
var stag = new NetworkTick(lunge.StaggerUntilTick);
|
|
if (stag.IsValid && stag.IsNewerThan(netTime.ServerTick))
|
|
{
|
|
punishesThisTick++;
|
|
lunge.StaggerUntilTick = 0u;
|
|
SystemAPI.SetComponent(entity, lunge);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
dmg.Clear();
|
|
if (negatedForThisEntity != 0u)
|
|
{
|
|
ds.NegatedCount += negatedForThisEntity; // server-side spam signal; DashSystem reads it at window-close
|
|
SystemAPI.SetComponent(entity, ds);
|
|
}
|
|
|
|
float newHp = health.ValueRO.Current - total;
|
|
|
|
// Effective max health (base + modifiers) is the runtime ceiling for entities that carry
|
|
// character stats (players); others just clamp at zero. No auto-heal on a max increase.
|
|
if (SystemAPI.HasComponent<EffectiveCharacterStats>(entity))
|
|
newHp = math.clamp(newHp, 0f, SystemAPI.GetComponent<EffectiveCharacterStats>(entity).MaxHealth);
|
|
else
|
|
newHp = math.max(0f, newHp);
|
|
|
|
health.ValueRW.Current = newHp;
|
|
|
|
// Server-authoritative death: training dummies + EB-1 Destructible structures despawn instantly;
|
|
// player death is deferred (clamp only). A structure carries NO EffectiveCharacterStats, so it took
|
|
// the math.max(0,..) branch above and CAN reach 0 — never give a structure stats (it would clamp to
|
|
// a non-zero floor and become immortal).
|
|
// Phase 1 (B3): ENEMIES get a corpse window instead — mark Dying ONCE on the lethal crossing and
|
|
// zero every live cue (the replicated windup, the lunge state + ghost bit, knockback) so clients
|
|
// never see a corpse telegraphing. Plain-world EditMode tests have no NetworkTime → keep the old
|
|
// instant destroy there so the existing suite still means what it asserts.
|
|
if (health.ValueRO.Current <= 0f)
|
|
{
|
|
if (SystemAPI.HasComponent<EnemyTag>(entity) && haveTick && netTime.ServerTick.IsValid)
|
|
{
|
|
if (!SystemAPI.HasComponent<Dying>(entity))
|
|
{
|
|
ecb.AddComponent(entity, new Dying
|
|
{
|
|
UntilTick = TickUtil.NonZero(netTime.ServerTick.TickIndexForValidTick + Tuning.EnemyDeathWindowTicks),
|
|
});
|
|
if (SystemAPI.HasComponent<AttackWindup>(entity)) SystemAPI.SetComponent(entity, default(AttackWindup));
|
|
if (SystemAPI.HasComponent<KnockbackState>(entity)) SystemAPI.SetComponent(entity, default(KnockbackState));
|
|
if (SystemAPI.HasComponent<LungeState>(entity)) SystemAPI.SetComponent(entity, default(LungeState));
|
|
if (SystemAPI.HasComponent<IsLunging>(entity)) SystemAPI.SetComponentEnabled<IsLunging>(entity, false);
|
|
}
|
|
}
|
|
else if (SystemAPI.HasComponent<EnemyTag>(entity) || SystemAPI.HasComponent<Destructible>(entity))
|
|
ecb.DestroyEntity(entity);
|
|
}
|
|
}
|
|
// Phase 1 (B3): corpse expiry — destroy Dying enemies whose window elapsed (at-most-once: the Dying
|
|
// mark is the only path here, and destruction removes it). NetworkTick compare, never raw uint math.
|
|
if (haveTick && netTime.ServerTick.IsValid)
|
|
{
|
|
foreach (var (dying, entity) in SystemAPI.Query<RefRO<Dying>>().WithEntityAccess())
|
|
{
|
|
var until = new NetworkTick(dying.ValueRO.UntilTick);
|
|
if (until.IsValid && !until.IsNewerThan(netTime.ServerTick))
|
|
ecb.DestroyEntity(entity);
|
|
}
|
|
}
|
|
|
|
if ((negatedThisTick != 0u || punishesThisTick != 0u) && SystemAPI.HasSingleton<DevTelemetry>())
|
|
{
|
|
var telem = SystemAPI.GetSingletonRW<DevTelemetry>();
|
|
telem.ValueRW.DashIFrameNegatedHits += negatedThisTick;
|
|
telem.ValueRW.ChargerWhiffPunishesLanded += punishesThisTick;
|
|
}
|
|
|
|
ecb.Playback(state.EntityManager);
|
|
ecb.Dispose();
|
|
}
|
|
}
|
|
}
|