33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using GameCore.ECS;
|
|
using GameCore.Events;
|
|
using GameCore.Interaction;
|
|
using GameCore.Logic.Interfaces;
|
|
|
|
namespace GameCore.Logic;
|
|
|
|
public class CloseDoorAction(string targetWorldId) : ITriggerAction
|
|
{
|
|
public void Execute(World world)
|
|
{
|
|
var doorEntity = world.FindEntityByWorldId(targetWorldId);
|
|
if (doorEntity == null)
|
|
{
|
|
world.Logger.Warn($"[CloseDoorAction] Could not find entity with WorldId: {targetWorldId}");
|
|
return;
|
|
}
|
|
|
|
var door = world.GetComponent<DoorComponent>(doorEntity.Value);
|
|
if (door == null)
|
|
{
|
|
world.Logger.Warn($"[CloseDoorAction] Entity '{targetWorldId}' does not have a DoorComponent.");
|
|
return;
|
|
}
|
|
|
|
if (door.CurrentState == DoorComponent.DoorState.Open || door.CurrentState == DoorComponent.DoorState.Opening)
|
|
{
|
|
door.CurrentState = DoorComponent.DoorState.Closing;
|
|
world.Logger.Info($"[CloseDoorAction] Closing door: {targetWorldId}");
|
|
world.PublishEvent(new DoorStateChangedEvent(doorEntity.Value, door.CurrentState));
|
|
}
|
|
}
|
|
} |