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(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)); } } }