diff --git a/GameCore/Interaction/InteractionSystem.cs b/GameCore/Interaction/InteractionSystem.cs index d6e86f8..b8659c0 100644 --- a/GameCore/Interaction/InteractionSystem.cs +++ b/GameCore/Interaction/InteractionSystem.cs @@ -52,7 +52,7 @@ public class InteractionSystem(float interactionRange) : ISystem switch (door.CurrentState) { case DoorComponent.DoorState.Locked: - if (CheckRequirements(world, interactor, door.Requirements)) + if (door.Requirements.Count > 0 && CheckRequirements(world, interactor, door.Requirements)) { world.Logger.Info($"Door {doorEntity.Id} requirements met. Unlocking door."); door.CurrentState = DoorComponent.DoorState.Opening; diff --git a/GameCore/Logic/OpenDoorAction.cs b/GameCore/Logic/OpenDoorAction.cs new file mode 100644 index 0000000..c0779a5 --- /dev/null +++ b/GameCore/Logic/OpenDoorAction.cs @@ -0,0 +1,34 @@ +using GameCore.ECS; +using GameCore.Events; +using GameCore.Interaction; +using GameCore.Logic.Interfaces; + +namespace GameCore.Logic; + +public class OpenDoorAction(string targetWorldId) : ITriggerAction +{ + public void Execute(World world) + { + var doorEntity = world.FindEntityByWorldId(targetWorldId); + if (doorEntity == null) + { + world.Logger.Warn($"[OpenDoorAction] Could not find entity with WorldId: {targetWorldId}"); + return; + } + + var door = world.GetComponent(doorEntity.Value); + if (door == null) + { + world.Logger.Warn($"[OpenDoorAction] Entity '{targetWorldId}' does not have a DoorComponent."); + return; + } + + if (door.CurrentState == DoorComponent.DoorState.Locked || door.CurrentState == DoorComponent.DoorState.Closed) + { + door.Requirements.Clear(); + door.CurrentState = DoorComponent.DoorState.Opening; + world.Logger.Info($"[OpenDoorAction] Unlocking and opening door: {targetWorldId}"); + world.PublishEvent(new DoorStateChangedEvent(doorEntity.Value, door.CurrentState)); + } + } +} \ No newline at end of file