30 lines
768 B
C#
30 lines
768 B
C#
using GameCore.ECS;
|
|
using GameCore.ECS.Interfaces;
|
|
using GameCore.Events;
|
|
|
|
namespace GameCore.Inventory;
|
|
|
|
public class InventorySystem : ISystem
|
|
{
|
|
private readonly World _world;
|
|
|
|
public InventorySystem(World world)
|
|
{
|
|
_world = world;
|
|
_world.Subscribe<AddItemToInventoryEvent>(OnAddItem);
|
|
}
|
|
|
|
public void Update(World world, float deltaTime)
|
|
{
|
|
}
|
|
|
|
private void OnAddItem(AddItemToInventoryEvent e)
|
|
{
|
|
var inventory = _world.GetComponent<InventoryComponent>(e.Target);
|
|
if (inventory == null) return;
|
|
inventory.AddItem(e.Item);
|
|
|
|
var newQuantity = inventory.GetItemCount(e.Item.ItemId);
|
|
_world.PublishEvent(new InventoryItemChangedEvent(e.Target, e.Item.ItemId, newQuantity));
|
|
}
|
|
} |