Add CloseDoorAction and enhance LogicSequenceComponent for activation handling

This commit is contained in:
2025-10-30 02:46:22 +01:00
parent 1a4c4cf4b1
commit bb31c9a39c
3 changed files with 62 additions and 16 deletions

View File

@@ -25,27 +25,38 @@ public class LogicSequenceSystem : ISystem
foreach (var entity in logicEntities)
{
var logic = _world.GetComponent<LogicSequenceComponent>(entity);
if (logic == null || (logic.IsOneTimeTrigger && logic.HasTriggered)) continue;
if (logic == null) continue;
if (logic.RequiredChannels.Contains(e.ChannelId))
if (!logic.RequiredChannels.Contains(e.ChannelId)) continue;
if (e.NewState)
logic.ActivatedChannels.Add(e.ChannelId);
else
logic.ActivatedChannels.Remove(e.ChannelId);
_world.Logger.Info(
$"[LogicSequenceSystem] Channel '{e.ChannelId}' activated. Total {logic.ActivatedChannels.Count}/{logic.RequiredChannels.Count}");
var allConditionsMet = logic.ActivatedChannels.Count == logic.RequiredChannels.Count;
if (allConditionsMet && !logic.IsCurrentlyActive)
{
if (e.NewState)
logic.ActivatedChannels.Add(e.ChannelId);
else
logic.ActivatedChannels.Remove(e.ChannelId);
if (logic.IsOneTimeTrigger && logic.HasTriggered) continue;
_world.Logger.Info(
$"[LogicSequenceSystem] Channel '{e.ChannelId}' activated. Total {logic.ActivatedChannels.Count}/{logic.RequiredChannels.Count}");
_world.Logger.Info("[LogicSequenceSystem] All channels activated. Executing OnActivateActions.");
foreach (var action in logic.OnActivateActions) action.Execute(_world);
if (logic.ActivatedChannels.Count == logic.RequiredChannels.Count)
{
_world.Logger.Info("[LogicSequenceSystem] All channels activated. Executing actions.");
foreach (var action in logic.OnCompleteActions) action.Execute(_world);
logic.IsCurrentlyActive = true;
logic.HasTriggered = true;
}
else if (!allConditionsMet && logic.IsCurrentlyActive)
{
if (logic.IsOneTimeTrigger) continue;
if (logic.IsOneTimeTrigger) logic.HasTriggered = true;
_world.Logger.Info("[LogicSequenceSystem] Channels deactivated. Executing OnDeactivateActions.");
foreach (var action in logic.OnDeactivateActions) action.Execute(_world);
logic.ActivatedChannels.Clear();
}
logic.IsCurrentlyActive = false;
}
}
}