2710d680b4
GymSub bakes no WaveDirector (why sandbox enemies never spawned); the sandbox's combat target is now a TargetDummyTag'd enemy ghost all five EnemyAISystem passes exclude (planted; knockback stamps inert), spawned at player+3m with 400 HP by an editor-only scene-gated server system, dying through the normal Dying path and respawning 1.5s after the corpse. EnemyTag-reuse audited: sandbox-only by design (cleared-checks would count it elsewhere). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
86 lines
4.0 KiB
C#
86 lines
4.0 KiB
C#
#if UNITY_EDITOR
|
|
using ProjectM.Simulation;
|
|
using Unity.Collections;
|
|
using Unity.Entities;
|
|
using Unity.Mathematics;
|
|
using Unity.Transforms;
|
|
|
|
namespace ProjectM.Server
|
|
{
|
|
/// <summary>
|
|
/// 07-20 sandbox combat target: keeps ONE planted <see cref="TargetDummyTag"/> dummy alive in the DevSandbox
|
|
/// (scene-name gate — the established dev-script convention; GymSub bakes no WaveDirector, so this is the
|
|
/// sandbox's enemy source by design). The dummy is a real enemy ghost instantiated from a baked prefab
|
|
/// (grunt-shaped preferred), parked at the first player's position + a fixed offset, HP fat enough to eat a
|
|
/// few chains; it dies through the NORMAL death path (Dying corpse window → destroy → kill pop on the client)
|
|
/// and respawns at the same anchor shortly after — kill feedback stays testable on repeat. Editor-only.
|
|
/// </summary>
|
|
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
|
|
public partial class TargetDummySpawnSystem : SystemBase
|
|
{
|
|
const float RespawnDelaySec = 1.5f;
|
|
const float DummyHealth = 400f;
|
|
static readonly float3 AnchorOffset = new float3(3f, 0f, 1.5f);
|
|
|
|
float _respawnTimer;
|
|
float3 _anchor;
|
|
bool _anchored;
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name != "DevSandbox")
|
|
return;
|
|
|
|
// A dummy exists (alive OR in its Dying corpse window) -> nothing to do; the corpse window
|
|
// conveniently delays the respawn timer until the body is gone.
|
|
var dummyQ = SystemAPI.QueryBuilder().WithAll<TargetDummyTag>().Build();
|
|
if (!dummyQ.IsEmpty) { _respawnTimer = 0f; return; }
|
|
|
|
// Anchor once on the first player seen (spawn point + offset = a consistent training spot).
|
|
if (!_anchored)
|
|
{
|
|
foreach (var xf in SystemAPI.Query<RefRO<LocalTransform>>().WithAll<PlayerTag>())
|
|
{
|
|
_anchor = xf.ValueRO.Position + AnchorOffset;
|
|
_anchored = true;
|
|
break;
|
|
}
|
|
if (!_anchored) return; // no player yet (world still connecting)
|
|
}
|
|
|
|
_respawnTimer += SystemAPI.Time.DeltaTime; // wall-frame is fine: dev spawner in the plain server group
|
|
if (_respawnTimer < RespawnDelaySec) return;
|
|
_respawnTimer = 0f;
|
|
|
|
// Grunt-shaped prefab preferred (no lunge/spit machinery on a training dummy); fall back to any enemy.
|
|
var prefQ = EntityManager.CreateEntityQuery(new EntityQueryDesc
|
|
{
|
|
All = new ComponentType[] { typeof(EnemyTag), typeof(Prefab) },
|
|
None = new ComponentType[] { typeof(LungeState), typeof(SpitterState) },
|
|
Options = EntityQueryOptions.IncludePrefab,
|
|
});
|
|
var prefabs = prefQ.ToEntityArray(Allocator.Temp);
|
|
if (prefabs.Length == 0)
|
|
{
|
|
prefabs.Dispose();
|
|
var anyQ = EntityManager.CreateEntityQuery(new EntityQueryDesc
|
|
{
|
|
All = new ComponentType[] { typeof(EnemyTag), typeof(Prefab) },
|
|
Options = EntityQueryOptions.IncludePrefab,
|
|
});
|
|
prefabs = anyQ.ToEntityArray(Allocator.Temp);
|
|
if (prefabs.Length == 0) { prefabs.Dispose(); return; } // no enemy ghosts in this world
|
|
}
|
|
var prefab = prefabs[0];
|
|
prefabs.Dispose();
|
|
|
|
var inst = EntityManager.Instantiate(prefab);
|
|
var baked = EntityManager.GetComponentData<LocalTransform>(prefab);
|
|
EntityManager.SetComponentData(inst, baked.WithPosition(_anchor)); // WithPosition: never FromPosition (Scale reset)
|
|
EntityManager.SetComponentData(inst, new Health { Current = DummyHealth, Max = DummyHealth });
|
|
EntityManager.AddComponent<TargetDummyTag>(inst); // server-only: plants it (every AI pass excludes the tag)
|
|
}
|
|
}
|
|
}
|
|
#endif
|