using ProjectM.Simulation; using Unity.Entities; using UnityEngine; namespace ProjectM.Authoring { /// /// Authoring for the turret structure ghost prefab (duplicate UpgradePickup.prefab so the ownerless /// interpolated GhostAuthoringComponent comes free). Bakes {Type=Turret} + /// stats. BuildPlaceSystem stamps Cell + LastProcessedTick at placement. /// public class TurretAuthoring : MonoBehaviour { [Min(1f)] public float Range = 10f; [Min(1)] public int CooldownTicks = 30; [Min(1f)] public float Damage = 12f; [Min(1f)] public float MaxHp = 120f; private class TurretBaker : Baker { public override void Bake(TurretAuthoring authoring) { var entity = GetEntity(authoring, TransformUsageFlags.Dynamic); AddComponent(entity, new PlacedStructure { Type = StructureType.Turret, Cell = default, NextTick = 0u, LastProcessedTick = 0u, }); AddComponent(entity, new Turret { Range = authoring.Range, CooldownTicks = authoring.CooldownTicks, Damage = authoring.Damage, }); // EB-1: structures are damageable + destructible (Husks push for them; HealthApplyDamageSystem // destroys a Destructible at Health<=0). The DamageEvent buffer MUST exist on the archetype or an // AI/turret strike crashes at ECB playback. NO HitRadius on purpose -> ProjectileDamageSystem (needs // Health+HitRadius) ignores structures, so player shots never friendly-fire your own turret. AddComponent(entity, new Health { Current = authoring.MaxHp, Max = authoring.MaxHp }); AddBuffer(entity); AddComponent(entity); } } } }