41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
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<InputStateComponent>();
|
|
foreach (var entity in entities)
|
|
{
|
|
var input = world.GetComponent<InputStateComponent>(entity);
|
|
var weapon = world.GetComponent<WeaponComponent>(entity);
|
|
var position = world.GetComponent<PositionComponent>(entity);
|
|
var rotation = world.GetComponent<RotationComponent>(entity);
|
|
|
|
if (input == null || weapon == null || position == null || rotation == null)
|
|
continue;
|
|
|
|
if (weapon.CooldownTimer > 0f) weapon.CooldownTimer -= deltaTime;
|
|
|
|
if (input.IsFiring && weapon.CooldownTimer <= 0f)
|
|
{
|
|
// Check for ammo if applicable
|
|
|
|
var context = new EffectContext { World = world, Owner = entity };
|
|
|
|
foreach (var effect in weapon.OnFireEffects) effect.Execute(context);
|
|
|
|
world.PublishEvent(new WeaponFiredEvent(entity, input.MuzzlePosition));
|
|
weapon.CooldownTimer = 1f / weapon.FireRate;
|
|
}
|
|
}
|
|
}
|
|
} |