Add CloseDoorAction and enhance LogicSequenceComponent for activation handling

This commit is contained in:
2025-10-30 02:46:22 +01:00
parent 1a4c4cf4b1
commit bb31c9a39c
3 changed files with 62 additions and 16 deletions

View File

@@ -0,0 +1,33 @@
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));
}
}
}