Files
brick-framework/GameCore/Logic/OpenDoorAction.cs

34 lines
1.2 KiB
C#

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