blob: ffb2659c68b7c37285b8cee513c302b1e6b7d85c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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);
}
}
|