diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-28 17:46:54 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-28 17:46:54 -0300 |
| commit | 2ed63124ef044a223fc9c7b660100c91af6f39b0 (patch) | |
| tree | ea0887e9aec0f88cea1979877f325faf6024a444 /scripts | |
| parent | e17510951f1136f4afeb2afbf76c47df151b299b (diff) | |
Mudança no sistema de turnos.
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Game.cs | 23 | ||||
| -rw-r--r-- | scripts/actors/AI/HostileEnemyAI.cs | 8 | ||||
| -rw-r--r-- | scripts/actors/Actor.cs | 31 | ||||
| -rw-r--r-- | scripts/actors/ActorDefinition.cs | 2 | ||||
| -rw-r--r-- | scripts/actors/actions/Action.cs | 5 | ||||
| -rw-r--r-- | scripts/actors/actions/BumpAction.cs | 4 | ||||
| -rw-r--r-- | scripts/actors/actions/MeleeAction.cs | 1 | ||||
| -rw-r--r-- | scripts/actors/actions/MovementAction.cs | 1 | ||||
| -rw-r--r-- | scripts/actors/actions/WaitAction.cs | 1 |
9 files changed, 70 insertions, 6 deletions
diff --git a/scripts/Game.cs b/scripts/Game.cs index 3a70e0c..b47c154 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -53,10 +53,21 @@ public partial class Game : Node { // Se realmente houve uma ação, computamos um turno. if (action != null) { Vector2I previousPlayerPos = player.GridPosition; + + // Início do turno, o jogador recebe um pouco de energia. + if (player.Energy <= 0) { + player.RechargeEnergy(); + } + // Primeiro executamos a ação do jogador action.Perform(); - // Depois computamos os turnos dos outros atores. - HandleEnemyTurns(); + + // Se o jogador ainda tem energia, ele poderá fazer + // mais um turno sem interrupções. + if (player.Energy <= 0) { + // Depois computamos os turnos dos outros atores. + HandleEnemyTurns(); + } // Por fim, se o jogador mudou de lugar, atualizamos seu campo de visão. if (player.GridPosition != previousPlayerPos) { Map.UpdateFOV(player.GridPosition); @@ -73,7 +84,13 @@ public partial class Game : Node { // Se o ator for um inimigo e estiver vivo, deixamos // que sua IA faça um turno. if (actor is Enemy enemy && enemy.IsAlive) { - enemy.Soul.Perform(); + // Início do turno, inimigo recebe energia. + enemy.RechargeEnergy(); + + // O inimigo poderá fazer quantos turnos sua energia deixar. + while (enemy.Energy > 0) { + enemy.Soul.Perform(); + } } } } diff --git a/scripts/actors/AI/HostileEnemyAI.cs b/scripts/actors/AI/HostileEnemyAI.cs index 3989004..af87360 100644 --- a/scripts/actors/AI/HostileEnemyAI.cs +++ b/scripts/actors/AI/HostileEnemyAI.cs @@ -47,6 +47,8 @@ public partial class HostileEnemyAI : BaseAI Vector2I destination = (Vector2I) path[0]; // Se tiver um outro ator no caminho, paramos o nosso turno aqui. if (body.Map_Data.GetBlockingActorAtPosition(destination) != null) { + action = new WaitAction(body); + action.Perform(); return; } @@ -55,6 +57,12 @@ public partial class HostileEnemyAI : BaseAI action.Perform(); // Podemos remover o passo do caminho. path.RemoveAt(0); + return; } + + // Senão, espere. + action = new WaitAction(body); + action.Perform(); + return; } }
\ No newline at end of file diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs index 642e9fd..b651286 100644 --- a/scripts/actors/Actor.cs +++ b/scripts/actors/Actor.cs @@ -21,7 +21,36 @@ public abstract partial class Actor : Sprite2D /// Se o ator está vivo. /// </summary> public bool IsAlive { get => Hp > 0; } - + + private int energy; + /// <summary> + /// Utilizado no sistema de turnos. + /// Enquanto o ator tiver energia, ele poderá realizar turnos. + /// </summary> + public int Energy + { + get => energy; + set + { + if (value > Speed) { + energy = Speed; + } else { + energy = value; + } + } + } + /// <summary> + /// Taxa de recarga de energia. + /// </summary> + public int Speed { get => definition.Speed; } + + /// <summary> + /// Executado uma vez por turno, + /// </summary> + public void RechargeEnergy() { + Energy += Speed; + } + private Vector2I gridPosition = Vector2I.Zero; /// <summary> /// Posição do ator no mapa do jogo. Diferentemente de Position, GridPosition tem como formato diff --git a/scripts/actors/ActorDefinition.cs b/scripts/actors/ActorDefinition.cs index 7f67787..ab0160b 100644 --- a/scripts/actors/ActorDefinition.cs +++ b/scripts/actors/ActorDefinition.cs @@ -21,6 +21,8 @@ public partial class ActorDefinition : Resource // Se o ator bloqueia movimento. [Export] public bool blocksMovement = true; + [Export] + public int Speed { get; set;} = 10; // Estatísticas padrão do ator. [ExportCategory("Stats")] diff --git a/scripts/actors/actions/Action.cs b/scripts/actors/actions/Action.cs index 0320dd8..f20e262 100644 --- a/scripts/actors/actions/Action.cs +++ b/scripts/actors/actions/Action.cs @@ -11,8 +11,13 @@ public abstract partial class Action : RefCounted { /// </summary> protected Actor actor; + // O custo da ação. + protected int cost; + public Action(Actor actor) { this.actor = actor; + // Custo base, subclasses podem sobreescrever isto se quiserem. + cost = 10; } /// <summary> diff --git a/scripts/actors/actions/BumpAction.cs b/scripts/actors/actions/BumpAction.cs index 0ce7fbe..805520c 100644 --- a/scripts/actors/actions/BumpAction.cs +++ b/scripts/actors/actions/BumpAction.cs @@ -11,10 +11,10 @@ public partial class BumpAction : DirectionalAction { } + // Como esta ação inevitavelmente gera outras ações, + // não faz sentido descontar a energia do ator. public override void Perform() { - Vector2I destination = actor.GridPosition + Offset; - // Declaramos uma ação genérica. Action action; diff --git a/scripts/actors/actions/MeleeAction.cs b/scripts/actors/actions/MeleeAction.cs index c61a803..56a2dc3 100644 --- a/scripts/actors/actions/MeleeAction.cs +++ b/scripts/actors/actions/MeleeAction.cs @@ -32,6 +32,7 @@ public partial class MeleeAction : DirectionalAction attackDesc += $" mas {target.ActorName} tem músculos de aço."; } + actor.Energy -= cost; GD.Print(attackDesc); } } diff --git a/scripts/actors/actions/MovementAction.cs b/scripts/actors/actions/MovementAction.cs index b37f9ae..6cec875 100644 --- a/scripts/actors/actions/MovementAction.cs +++ b/scripts/actors/actions/MovementAction.cs @@ -18,6 +18,7 @@ public partial class MovementAction : DirectionalAction // Na maioria dos casos, essa condição nunca é verdadeira. if (GetTargetActor() != null) return; + actor.Energy -= cost; actor.Walk(Offset); } } diff --git a/scripts/actors/actions/WaitAction.cs b/scripts/actors/actions/WaitAction.cs index 4ad064a..2d3ccc2 100644 --- a/scripts/actors/actions/WaitAction.cs +++ b/scripts/actors/actions/WaitAction.cs @@ -96,6 +96,7 @@ public partial class WaitAction : Action //@@@@@@@@@@@@*====+==++=*@. @ @@* .@* @ .*#. @ @* #: -@ @@% @ -+ =*%@@= @@: @ @ +. #+ *@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@======++====+*%@@@@%%%@@@@%*+#@@@@@%#%@@#=+**=. =**+=***==*#*: :%@@@@@@@@@**=+#*==*###*=. -=**+::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@+==+==++=====++=====++=+++++++++===+++++#% +@@@* :#%= =@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + actor.Energy -= cost; } |
