using GameCore.Combat.Effects; using GameCore.ECS; using GameCore.ECS.Interfaces; using GameCore.Events; using GameCore.Input; using GameCore.Movement; using GameCore.Physics; namespace GameCore.Combat; public class WeaponSystem : ISystem { public void Update(World world, float deltaTime) { var entities = world.GetEntitiesWith(); foreach (var entity in entities) { var input = world.GetComponent(entity); var weapon = world.GetComponent(entity); var position = world.GetComponent(entity); var rotation = world.GetComponent(entity); if (input == null || weapon == null || position == null || rotation == null) continue; if (weapon.CooldownTimer > 0f) weapon.CooldownTimer -= deltaTime; if (input.IsFiring && weapon.CooldownTimer <= 0f) { var context = new EffectContext { World = world, Owner = entity }; var canFire = true; foreach (var cost in weapon.FireCosts) if (!cost.CanAfford(context)) { canFire = false; world.PublishEvent(new WeaponFireFailedEvent()); break; } if (!canFire) continue; foreach (var cost in weapon.FireCosts) cost.Execute(context); foreach (var effect in weapon.OnFireEffects) effect.Execute(context); world.PublishEvent(new WeaponFiredEvent(entity, input.MuzzlePosition)); weapon.CooldownTimer = 1f / weapon.FireRate; } } } }