Add OpenDoorAction to handle unlocking and opening doors with event publishing
This commit is contained in:
@@ -52,7 +52,7 @@ public class InteractionSystem(float interactionRange) : ISystem
|
|||||||
switch (door.CurrentState)
|
switch (door.CurrentState)
|
||||||
{
|
{
|
||||||
case DoorComponent.DoorState.Locked:
|
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.");
|
world.Logger.Info($"Door {doorEntity.Id} requirements met. Unlocking door.");
|
||||||
door.CurrentState = DoorComponent.DoorState.Opening;
|
door.CurrentState = DoorComponent.DoorState.Opening;
|
||||||
|
|||||||
34
GameCore/Logic/OpenDoorAction.cs
Normal file
34
GameCore/Logic/OpenDoorAction.cs
Normal file
@@ -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<DoorComponent>(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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user