37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
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>(collision.OtherEntity);
|
|
var inventory = world.GetComponent<InventoryComponent>(entity);
|
|
|
|
if (pickup == null || inventory == null) continue;
|
|
|
|
world.PublishEvent(new ItemPickupAttemptEvent(
|
|
entity,
|
|
collision.OtherEntity,
|
|
pickup.ItemId,
|
|
pickup.Quantity
|
|
));
|
|
}
|
|
|
|
foreach (var entity in withCollisions) world.RemoveComponent<CollisionEventComponent>(entity);
|
|
}
|
|
} |