summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actions/MovementAction.cs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Entities/Actions/MovementAction.cs')
-rw-r--r--scripts/Entities/Actions/MovementAction.cs30
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/Entities/Actions/MovementAction.cs b/scripts/Entities/Actions/MovementAction.cs
new file mode 100644
index 0000000..0ac842c
--- /dev/null
+++ b/scripts/Entities/Actions/MovementAction.cs
@@ -0,0 +1,30 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actors;
+using TheLegendOfGustav.Map;
+
+namespace TheLegendOfGustav.Entities.Actions;
+
+/// <summary>
+/// Ação de movimento. Movimenta o ator para a direção de seu Offset.
+/// </summary>
+public partial class MovementAction : DirectionalAction
+{
+ public MovementAction(Actor actor, Vector2I offset) : base(actor, offset)
+ {
+ }
+
+ public override bool Perform()
+ {
+ // Não anda se o destino for um tile sólido.
+ if (!MapData.GetTile(Destination).IsWalkable) return true;
+
+ // Não anda se o destino for oculpado por um ator.
+ // Na maioria dos casos, essa condição nunca é verdadeira.
+ if (GetTarget() != null) return true;
+
+ Actor.Walk(Offset);
+ Actor.Energy -= Cost;
+
+ return true;
+ }
+}