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,10 @@
using GameCore.ECS;
using GameCore.Events.Interfaces;
namespace GameCore.Events;
public readonly struct DamageDealtEvent(Entity target, float amount) : IEvent
{
public readonly Entity Target = target;
public readonly float Amount = amount;
}

View File

@@ -0,0 +1,9 @@
using GameCore.ECS;
using GameCore.Events.Interfaces;
namespace GameCore.Events;
public readonly struct EntityDiedEvent(Entity entity) : IEvent
{
public readonly Entity Entity = entity;
}

View File

@@ -0,0 +1,11 @@
using GameCore.ECS;
using GameCore.Events.Interfaces;
namespace GameCore.Events;
public readonly struct EntitySpawnedEvent(Entity newEntity, Entity owner, string archetypeId) : IEvent
{
public readonly Entity NewEntity = newEntity;
public readonly Entity Owner = owner;
public readonly string ArchetypeId = archetypeId;
}

View File

@@ -0,0 +1,46 @@
using GameCore.Events.Interfaces;
namespace GameCore.Events;
public class EventBus
{
private readonly Queue<IEvent> _eventQueue = new();
private readonly Dictionary<Type, List<Action<IEvent>>> _subscribers = new();
public void Subscribe<T>(Action<T> listener) where T : IEvent
{
var eventType = typeof(T);
if (!_subscribers.ContainsKey(eventType)) _subscribers[eventType] = [];
_subscribers[eventType].Add(e => listener((T)e));
}
public void Unsubscribe<T>(Action<T> listener) where T : IEvent
{
var eventType = typeof(T);
if (!_subscribers.TryGetValue(eventType, out var listeners)) return;
listeners.RemoveAll(e => e.Equals((Action<IEvent>)(e1 => listener((T)e1))));
if (listeners.Count == 0) _subscribers.Remove(eventType);
}
public void Publish(IEvent gameEvent)
{
_eventQueue.Enqueue(gameEvent);
}
public void ProcessEvents()
{
while (_eventQueue.Count > 0)
{
var gameEvent = _eventQueue.Dequeue();
var eventType = gameEvent.GetType();
if (!_subscribers.TryGetValue(eventType, out var listeners)) continue;
foreach (var listener in listeners)
listener.Invoke(gameEvent);
}
}
}

View File

@@ -0,0 +1,6 @@
namespace GameCore.Events.Interfaces;
public interface IEvent
{
}

View File

@@ -0,0 +1,20 @@
using GameCore.ECS;
using GameCore.Events.Interfaces;
using GameCore.Math;
namespace GameCore.Events;
public readonly struct SpawnEntityEvent(
string archetypeId,
Vector3 position,
Vector3 rotation,
Entity owner,
Vector3? initialVelocity = null)
: IEvent
{
public readonly string ArchetypeId = archetypeId;
public readonly Vector3 Position = position;
public readonly Vector3 Rotation = rotation;
public readonly Entity Owner = owner;
public readonly Vector3? InitialVelocity = initialVelocity;
}

View File

@@ -0,0 +1,11 @@
using GameCore.ECS;
using GameCore.Events.Interfaces;
using GameCore.Math;
namespace GameCore.Events;
public readonly struct WeaponFiredEvent(Entity owner, Vector3 muzzlePosition) : IEvent
{
public readonly Entity Owner = owner;
public readonly Vector3 MuzzlePosition = muzzlePosition;
}