3836e9c842
Server: HealthApplyDamageSystem marks EnemyTag Dying{UntilTick} (TickUtil.
NonZero, ~54 ticks) on the lethal 0-crossing instead of instant destroy,
zeroes every live cue (replicated AttackWindup, LungeState + IsLunging bit,
KnockbackState), destroys on expiry; plain-world tests keep instant destroy
(no NetworkTime) so the suite's assertions stay meaningful.
Every consumer now ignores corpses (all confirmed entity-count/unfiltered by
the design review): EnemyAISystem all 4 passes, BossAISystem brain + summon
cap, RoomEnemyDirector room-clear + MaxAlive fit, WaveSystem cap + cleared,
CyclePhaseSystem breach wipe + DefendCleared, ThreatDirector timeout cull,
TurretFire targeting, CoreDamage drain, ProjectileDamage snapshot (corpses
are not shields), AbilityFire auto-aim candidates, debug cull + telemetry.
Wipe passes skip Dying to avoid cross-ECB double-destroys.
Client: EnemyAnimationDriveSystem finally drives the controller's IsDead
param (Health.Current<=0 is the replicated death read; corpse locomotion
zeroed); CombatFeedbackSystem moves the kill CRUNCH to the 0-crossing (the
prune-edge timing would land it ~1 s late) - the prune keeps a small
dissolve puff for corpses and the legacy full read for alive-vanish culls.
456/456 EditMode.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
152 lines
7.8 KiB
C#
152 lines
7.8 KiB
C#
using ProjectM.Simulation;
|
|
using Unity.Burst;
|
|
using Unity.Collections;
|
|
using Unity.Entities;
|
|
using Unity.Mathematics;
|
|
using Unity.NetCode;
|
|
using Unity.Transforms;
|
|
|
|
namespace ProjectM.Server
|
|
{
|
|
/// <summary>
|
|
/// Server-only Husk wave/threat director: a state machine that escalates the swarm. In <c>Lull</c> it waits
|
|
/// until the lull timer expires, then starts the next wave (count = <c>BaseCount + (wave-1)*CountPerWave</c>). In
|
|
/// <c>Spawning</c> it spawns one Husk every <c>SpawnIntervalTicks</c> at a deterministic ring slot around the
|
|
/// <see cref="BaseAnchor"/>, round-robin over the <see cref="WaveEnemyPrefab"/> pool, until the wave is fully
|
|
/// spawned; then it waits for the field to be cleared (no live <see cref="EnemyTag"/>) before returning to
|
|
/// <c>Lull</c>. Plain <see cref="SimulationSystemGroup"/>, server-authoritative (Husks are interpolated ghosts).
|
|
/// Replaces the flat <c>EnemySpawnSystem</c> sustain. Tick gating uses the wrap-safe <see cref="NetworkTick"/>
|
|
/// compare + <see cref="TickUtil.NonZero"/>.
|
|
/// </summary>
|
|
[BurstCompile]
|
|
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
|
|
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
|
public partial struct WaveSystem : ISystem
|
|
{
|
|
|
|
[BurstCompile]
|
|
public void OnCreate(ref SystemState state)
|
|
{
|
|
state.RequireForUpdate<WaveDirector>();
|
|
state.RequireForUpdate<WaveState>();
|
|
state.RequireForUpdate<NetworkTime>();
|
|
}
|
|
|
|
[BurstCompile]
|
|
public void OnUpdate(ref SystemState state)
|
|
{
|
|
var serverTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick;
|
|
if (!serverTick.IsValid)
|
|
return;
|
|
uint now = serverTick.TickIndexForValidTick;
|
|
// Player-driven loop: the base-defense wave only spawns during a Siege.
|
|
if (SystemAPI.TryGetSingleton<CycleState>(out var cycle) && cycle.Phase != CyclePhase.Siege)
|
|
return;
|
|
|
|
var director = SystemAPI.GetSingleton<WaveDirector>();
|
|
var directorEntity = SystemAPI.GetSingletonEntity<WaveDirector>();
|
|
var prefabs = SystemAPI.GetBuffer<WaveEnemyPrefab>(directorEntity);
|
|
if (prefabs.Length == 0)
|
|
return;
|
|
|
|
var wave = SystemAPI.GetComponent<WaveState>(directorEntity);
|
|
|
|
// MC-2 fork-4a: the base siege adopts the 4-type weighted mix (BaseCount = the Grunt base). The size
|
|
// curve becomes WaveSlots(wave, bands) — a deliberate, operator-approved redefinition; MaxAlive is the
|
|
// mandatory cap so spitter spits + swarmer packs can't spike the relevancy loop during the END-game climax.
|
|
var bands = new MixBands
|
|
{
|
|
GruntBase = director.BaseCount,
|
|
ChargerBase = director.ChargerBase,
|
|
SpitterBase = director.SpitterBase,
|
|
SwarmerSlotBase = director.SwarmerSlotBase,
|
|
ChargerPerEpoch = director.ChargerPerEpoch,
|
|
SpitterPerEpoch = director.SpitterPerEpoch,
|
|
SwarmerSlotPerEpoch = director.SwarmerSlotPerEpoch,
|
|
SwarmerPackPerEpoch = director.SwarmerPackPerEpoch,
|
|
};
|
|
|
|
// Ring centre on the base plot when present.
|
|
float3 center = new float3(0f, 1f, 0f);
|
|
if (SystemAPI.TryGetSingleton<BaseAnchor>(out var baseAnchor))
|
|
center = BaseGridMath.PlotCenter(baseAnchor);
|
|
|
|
// Due when no action is scheduled yet (NextActionTick 0) or the scheduled tick is at/behind now.
|
|
bool dueNow = wave.NextActionTick == 0 || !new NetworkTick(wave.NextActionTick).IsNewerThan(serverTick);
|
|
|
|
if (wave.Phase == WavePhase.Lull)
|
|
{
|
|
if (dueNow)
|
|
{
|
|
// Start the next (bigger) wave.
|
|
wave.WaveNumber += 1;
|
|
wave.RemainingToSpawn = ZoneEnemyMath.WaveSlots(wave.WaveNumber, bands);
|
|
wave.Phase = WavePhase.Spawning;
|
|
wave.NextActionTick = TickUtil.NonZero(now); // spawn the first Husk this tick
|
|
}
|
|
}
|
|
else // Spawning
|
|
{
|
|
if (wave.RemainingToSpawn > 0)
|
|
{
|
|
if (dueNow)
|
|
{
|
|
int slots = math.max(1, director.RingSlots);
|
|
byte kind = ZoneEnemyMath.KindForSlot(wave.WaveNumber, wave.SpawnCounter, bands);
|
|
int packSize = kind == ZoneEnemyMath.KindSwarmer
|
|
? ZoneEnemyMath.PackSizeForSlot(wave.WaveNumber, wave.SpawnCounter, bands, director.SwarmerPackSize) : 1;
|
|
|
|
// Live BASE husks for the entity cap (expedition zone enemies are EnemyTag too -> excluded).
|
|
int aliveBase = 0;
|
|
foreach (var hr in SystemAPI.Query<RefRO<RegionTag>>().WithAll<EnemyTag>().WithNone<Dying>())
|
|
if (hr.ValueRO.Region == RegionId.Base) aliveBase++;
|
|
|
|
// MaxAlive counts ENTITIES; spawn the whole pack only if it fits (else WAIT — don't consume the slot).
|
|
if (aliveBase + packSize <= math.max(1, director.MaxAlive))
|
|
{
|
|
int prefabIdx = kind;
|
|
if (prefabIdx >= prefabs.Length) prefabIdx = 0; // 4-entry buffer expected; clamp defensively
|
|
float3 packCenter = EnemyAIMath.RingPosition(center, wave.SpawnCounter, slots, director.RingRadius);
|
|
packCenter.y = center.y;
|
|
var baked = state.EntityManager.GetComponentData<LocalTransform>(prefabs[prefabIdx].Prefab);
|
|
|
|
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
|
for (int k = 0; k < packSize; k++)
|
|
{
|
|
float3 pos = packSize > 1
|
|
? EnemyAIMath.ClusterOffset(packCenter, k, packSize, director.ClusterTightRadius) : packCenter;
|
|
pos.y = center.y;
|
|
var husk = ecb.Instantiate(prefabs[prefabIdx].Prefab);
|
|
ecb.SetComponent(husk, baked.WithPosition(pos)); // preserve baked [GhostField] Scale
|
|
ecb.AddComponent(husk, new RegionTag { Region = RegionId.Base });
|
|
}
|
|
ecb.Playback(state.EntityManager);
|
|
ecb.Dispose();
|
|
|
|
wave.SpawnCounter += 1; // ONE slot consumed even for a pack
|
|
wave.RemainingToSpawn -= 1;
|
|
wave.NextActionTick = TickUtil.NonZero(now + (uint)math.max(1, director.SpawnIntervalTicks));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Wave fully spawned: cleared only when no BASE husk remains. Expedition zone enemies are also
|
|
// EnemyTag but RegionTag{Expedition}; they must NOT hold the base siege open (DR-040 BLOCKER 3).
|
|
int baseHusks = 0;
|
|
foreach (var hr in SystemAPI.Query<RefRO<RegionTag>>().WithAll<EnemyTag>().WithNone<Dying>())
|
|
if (hr.ValueRO.Region == RegionId.Base) baseHusks++;
|
|
if (baseHusks == 0)
|
|
{
|
|
// Wave cleared: calm before the next.
|
|
wave.Phase = WavePhase.Lull;
|
|
wave.NextActionTick = TickUtil.NonZero(now + (uint)math.max(1, director.LullTicks));
|
|
}
|
|
}
|
|
}
|
|
|
|
SystemAPI.SetComponent(directorEntity, wave);
|
|
}
|
|
}
|
|
}
|