Add attribute system with core stats and gameplay components

This commit is contained in:
2025-10-13 12:10:45 +02:00
commit ce3596efaa
55 changed files with 1161 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using GameCore.Attributes;
using GameCore.ECS;
using GameCore.ECS.Interfaces;
using GameCore.Events;
using Attribute = GameCore.Attributes.Attribute;
namespace GameCore.Combat;
public class DamageSystem : ISystem
{
private readonly World _world;
public DamageSystem(World world)
{
_world = world;
world.Subscribe<DamageDealtEvent>(OnDamageDealt);
}
public void Update(World world, float deltaTime)
{
var entitiesWithHealth = world.GetEntitiesWith<AttributeComponent>();
foreach (var entity in entitiesWithHealth)
{
if (world.GetComponent<DeathComponent>(entity) != null) continue;
var attributes = world.GetComponent<AttributeComponent>(entity);
if (attributes == null) continue;
if (attributes.GetValue(Attribute.Health) <= 0) world.AddComponent(entity, new DeathComponent());
}
}
private void OnDamageDealt(DamageDealtEvent e)
{
var targetAttributes = _world.GetComponent<AttributeComponent>(e.Target);
targetAttributes?.ModifyValue(Attribute.Health, -e.Amount);
}
}