From b05cfd5577884d1a398dbb226e2082af5fe8f8fa Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 16 Aug 2025 15:56:28 -0300 Subject: Sistema de turnos básico MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/TurnManager.cs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 scripts/TurnManager.cs (limited to 'scripts/TurnManager.cs') diff --git a/scripts/TurnManager.cs b/scripts/TurnManager.cs new file mode 100644 index 0000000..ffb2659 --- /dev/null +++ b/scripts/TurnManager.cs @@ -0,0 +1,61 @@ +using Godot; +using System; +using System.Collections.Generic; +using System.Reflection.Metadata.Ecma335; + +public partial class TurnManager : Node { + [Signal] + public delegate void turnBeginEventHandler(); + [Signal] + public delegate void turnEndEventHandler(); + + private Godot.Collections.Array actors = []; + private int index = 0; + + public int TurnCount { get; private set; } = 1; + + public void Tick() { + EmitSignal(SignalName.turnBegin); + + GD.Print("Turn: " + TurnCount); + + actors.Clear(); + actors = GetTree().GetNodesInGroup("TimeSlave"); + + GD.Print("Actor count: " + actors.Count); + + index = -1; + NextActor(); + } + + private void NextActor() { + index++; + GD.Print("Index: " + index); + if (index >= actors.Count) { + EndTurn(); + return; + } + Actor currentActor = (Actor) actors[index]; + currentActor.Energy += currentActor.Speed; + ActorPerformAction(); + } + + private void ActorPerformAction() { + Actor currentActor = (Actor) actors[index]; + if (currentActor.Energy > 0) { + currentActor.performAction(); + } else { + NextActor(); + } + } + + public void OnActionEnd() { + ActorPerformAction(); + } + + private void EndTurn() { + GD.Print("Turn End"); + TurnCount++; + EmitSignal(SignalName.turnEnd); + } +} -- cgit v1.2.3