Add CloseDoorAction and enhance LogicSequenceComponent for activation handling
This commit is contained in:
33
GameCore/Logic/CloseDoorAction.cs
Normal file
33
GameCore/Logic/CloseDoorAction.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user