60e1e21dd3
Adds CoreIntegrity{[GhostField] Current,Max,OverrunTick} on the GLOBAL
CycleDirector ghost (no new ghost/relevancy). CoreDamageSystem (server,
after EnemyAISystem): a Husk within ~3u of PlotCenter drains + is consumed;
CoreRestoreSystem regenerates only in Calm. The SOFT-loss edge lives inside
CyclePhaseSystem (sole Phase writer): Current<=0 in Siege flips to Calm with
NO goal reward, StorageMath.DrainFraction drains the shared ledger, all Husks
despawn, and OverrunTick is stamped (a transient HUD-flash pulse, not a
latching outcome - the Victory latch is END-2's). EnemyAISystem treats the
Core as a FALLBACK target so an undefended base is overrun instead of idling.
SaveData -> v4 persists CoreCurrent (0 -> born full, the EB-1 HP sentinel);
3 live TuningConfig knobs + a red HUD Core bar. Soft-loss + targeting +
breach-resolution forks operator-locked.
See DR-034.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
100 lines
4.8 KiB
C#
100 lines
4.8 KiB
C#
using ProjectM.Simulation;
|
|
using Unity.Burst;
|
|
using Unity.Collections;
|
|
using Unity.Entities;
|
|
using Unity.NetCode;
|
|
using Unity.Transforms;
|
|
|
|
namespace ProjectM.Server
|
|
{
|
|
/// <summary>
|
|
/// Server-only, one-shot spawner for the GLOBAL cycle-director ghost (mirrors SharedStorageSpawnSystem,
|
|
/// but MINUS the RegionTag — the director must stay global so GhostRelevancy keeps it relevant to every
|
|
/// region). On its first update it reads the baked <see cref="CycleDirectorSpawner"/> + NetworkTime,
|
|
/// instantiates the ghost, initializes <see cref="CycleState"/> (Expedition, cycle 1, PhaseEndTick =
|
|
/// now + <see cref="CyclePhase.ExpeditionTicks"/>), adds the server-only <see cref="CycleRuntime"/>, and
|
|
/// places it at the base center (preserving the prefab's baked LocalTransform scale — FromPosition would
|
|
/// reset the replicated Scale GhostField), then destroys the spawner so it idles.
|
|
/// </summary>
|
|
[BurstCompile]
|
|
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
|
|
public partial struct CycleDirectorSpawnSystem : ISystem
|
|
{
|
|
[BurstCompile]
|
|
public void OnCreate(ref SystemState state)
|
|
{
|
|
state.RequireForUpdate<CycleDirectorSpawner>();
|
|
state.RequireForUpdate<NetworkTime>();
|
|
}
|
|
|
|
[BurstCompile]
|
|
public void OnUpdate(ref SystemState state)
|
|
{
|
|
var serverTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick;
|
|
if (!serverTick.IsValid)
|
|
return;
|
|
|
|
var spawnerEntity = SystemAPI.GetSingletonEntity<CycleDirectorSpawner>();
|
|
var spawner = SystemAPI.GetComponent<CycleDirectorSpawner>(spawnerEntity);
|
|
|
|
var ecb = new EntityCommandBuffer(Allocator.Temp);
|
|
|
|
if (spawner.Prefab != Entity.Null)
|
|
{
|
|
var director = ecb.Instantiate(spawner.Prefab);
|
|
|
|
// Place at the base center, preserving the prefab's baked scale/rotation.
|
|
var xform = SystemAPI.GetComponent<LocalTransform>(spawner.Prefab);
|
|
if (SystemAPI.TryGetSingleton<BaseAnchor>(out var anchor))
|
|
xform.Position = BaseGridMath.PlotCenter(anchor);
|
|
ecb.SetComponent(director, xform);
|
|
|
|
// Boot the run-state in Calm (the persistent default) — no timer; ThreatDirector arms sieges.
|
|
ecb.SetComponent(director, new CycleState
|
|
{
|
|
Phase = CyclePhase.Calm,
|
|
CycleNumber = 1,
|
|
PhaseEndTick = 0u,
|
|
});
|
|
ecb.AddComponent(director, new CycleRuntime { DefendStartWave = 0 });
|
|
ecb.AddComponent(director, new ThreatState());
|
|
|
|
// Born-correct load: if the menu staged a save (Continue), apply it AT SPAWN so the director
|
|
// ghost never serializes a default GoalProgress / empty ledger to clients (no replication flicker).
|
|
if (SystemAPI.TryGetSingletonEntity<PendingSave>(out var pendingEntity))
|
|
{
|
|
var pending = SystemAPI.GetComponent<PendingSave>(pendingEntity);
|
|
if (pending.HasData != 0)
|
|
{
|
|
ecb.SetComponent(director, new GoalProgress { Charge = pending.GoalCharge, Target = pending.GoalTarget });
|
|
var srcLedger = SystemAPI.GetBuffer<PendingSaveLedgerRow>(pendingEntity);
|
|
var destLedger = ecb.SetBuffer<StorageEntry>(director);
|
|
SaveApply.WriteLedger(srcLedger, destLedger);
|
|
|
|
// END-1: born-correct the Engine Core. Max comes from the BAKED prefab (never the save); a
|
|
// persisted wounded Current (>0) restores clamped to Max, else (0 = pre-v4 save) born full.
|
|
if (SystemAPI.HasComponent<CoreIntegrity>(spawner.Prefab))
|
|
{
|
|
var bakedCore = SystemAPI.GetComponent<CoreIntegrity>(spawner.Prefab);
|
|
int restoredCore = pending.CoreCurrent > 0
|
|
? (pending.CoreCurrent < bakedCore.Max ? pending.CoreCurrent : bakedCore.Max)
|
|
: bakedCore.Max;
|
|
ecb.SetComponent(director, new CoreIntegrity { Current = restoredCore, Max = bakedCore.Max, OverrunTick = 0u });
|
|
}
|
|
|
|
}
|
|
ecb.DestroyEntity(pendingEntity);
|
|
}
|
|
|
|
// Host-only autosave flag; SaveWriteSystem consumes it on the Siege->Calm checkpoint.
|
|
ecb.AddComponent(director, new SaveRequest { Pending = 0 });
|
|
}
|
|
|
|
// One-shot: remove the spawner so RequireForUpdate fails and the system idles.
|
|
ecb.DestroyEntity(spawnerEntity);
|
|
|
|
ecb.Playback(state.EntityManager);
|
|
}
|
|
}
|
|
}
|