diff options
| author | matheus20337 <149222182+matheus20337@users.noreply.github.com> | 2025-08-16 20:32:15 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-16 20:32:15 +0000 |
| commit | 7f6f4df85368a328ce69fb0b244a706b7dbfc6aa (patch) | |
| tree | 26961e5c63e87c5d1c17422cdf6ab4493b2d8f55 /scripts/TurnManager.cs | |
| parent | e159be9bbbf005785bd2d60af8b5c3df608f28b2 (diff) | |
| parent | b05cfd5577884d1a398dbb226e2082af5fe8f8fa (diff) | |
Merge pull request #1 from Simplesmente-O-Grupo/Matheus
Sistema de turnos
Diffstat (limited to 'scripts/TurnManager.cs')
| -rw-r--r-- | scripts/TurnManager.cs | 61 |
1 files changed, 61 insertions, 0 deletions
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<Node> 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); + } +} |
