Add attribute system with core stats and gameplay components
This commit is contained in:
23
GameCore/Attributes/AttributeSystem.cs
Normal file
23
GameCore/Attributes/AttributeSystem.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
|
||||
namespace GameCore.Attributes;
|
||||
|
||||
public class AttributeSystem : ISystem
|
||||
{
|
||||
public void Update(World world, float deltaTime)
|
||||
{
|
||||
var entities = world.GetEntitiesWith<AttributeComponent>();
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
var attributes = world.GetComponent<AttributeComponent>(entity);
|
||||
if (attributes == null) continue;
|
||||
|
||||
var maxHealth = attributes.GetValue(Attribute.MaxHealth);
|
||||
var currentHealth = attributes.GetValue(Attribute.Health);
|
||||
|
||||
if (currentHealth > maxHealth) attributes.SetCurrentValue(Attribute.Health, maxHealth);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user