summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actions
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Entities/Actions')
-rw-r--r--scripts/Entities/Actions/SpellAction.cs33
-rw-r--r--scripts/Entities/Actions/SpellAction.cs.uid1
2 files changed, 34 insertions, 0 deletions
diff --git a/scripts/Entities/Actions/SpellAction.cs b/scripts/Entities/Actions/SpellAction.cs
new file mode 100644
index 0000000..086a52a
--- /dev/null
+++ b/scripts/Entities/Actions/SpellAction.cs
@@ -0,0 +1,33 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actors;
+using TheLegendOfGustav.Magic;
+
+namespace TheLegendOfGustav.Entities.Actions;
+
+public partial class SpellCommand(Actor actor, Vector2I offset, SpellResource spell) : DirectionalAction(actor, offset)
+{
+ private SpellResource spell = spell;
+
+ public override bool Perform()
+ {
+ Actor target = null;
+
+ if (GetTarget() is Actor actor)
+ {
+ target = actor;
+ }
+
+ if (spell.Type == SpellType.Ranged && target == null) return false;
+
+ if (Actor.Mp < spell.Cost)
+ {
+ return false;
+ }
+
+ foreach (SpellEffect effect in spell.Effects)
+ {
+ effect.Apply(Actor, target);
+ }
+ return true;
+ }
+}
diff --git a/scripts/Entities/Actions/SpellAction.cs.uid b/scripts/Entities/Actions/SpellAction.cs.uid
new file mode 100644
index 0000000..6f85025
--- /dev/null
+++ b/scripts/Entities/Actions/SpellAction.cs.uid
@@ -0,0 +1 @@
+uid://b18wblvggpev0