Add attribute system with core stats and gameplay components
This commit is contained in:
39
GameCore/Combat/WeaponSystem.cs
Normal file
39
GameCore/Combat/WeaponSystem.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user