36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using GameCore.Combat;
|
|
using GameCore.ECS;
|
|
using GameCore.ECS.Interfaces;
|
|
using GameCore.Events;
|
|
using GameCore.Physics;
|
|
using GameCore.Player;
|
|
|
|
namespace GameCore.Inventory;
|
|
|
|
public class PickupSystem : ISystem
|
|
{
|
|
public void Update(World world, float deltaTime)
|
|
{
|
|
var entitiesWithCollisions = world.GetEntitiesWith<CollisionEventComponent>();
|
|
var withCollisions = entitiesWithCollisions.ToList();
|
|
foreach (var entity in withCollisions)
|
|
{
|
|
if (world.GetComponent<PlayerComponent>(entity) == null) return;
|
|
|
|
var collision = world.GetComponent<CollisionEventComponent>(entity);
|
|
if (collision == null) continue;
|
|
|
|
var pickup = world.GetComponent<PickupComponent>(entity);
|
|
var inventory = world.GetComponent<InventoryComponent>(entity);
|
|
|
|
if (pickup == null || inventory == null) continue;
|
|
|
|
var item = new Item(pickup.ItemId, pickup.Quantity);
|
|
// In the future, handle IsInstantUse items here
|
|
world.PublishEvent(new AddItemToInventoryEvent(entity, item));
|
|
world.AddComponent(collision.OtherEntity, new DeathComponent());
|
|
}
|
|
|
|
foreach (var entity in withCollisions) world.RemoveComponent<CollisionEventComponent>(entity);
|
|
}
|
|
} |