summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actions
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Entities/Actions')
-rw-r--r--scripts/Entities/Actions/ChangeInputStateAction.cs.uid1
-rw-r--r--scripts/Entities/Actions/SpellAction.cs34
2 files changed, 30 insertions, 5 deletions
diff --git a/scripts/Entities/Actions/ChangeInputStateAction.cs.uid b/scripts/Entities/Actions/ChangeInputStateAction.cs.uid
new file mode 100644
index 0000000..c8f6440
--- /dev/null
+++ b/scripts/Entities/Actions/ChangeInputStateAction.cs.uid
@@ -0,0 +1 @@
+uid://bxlakdvr1lovw
diff --git a/scripts/Entities/Actions/SpellAction.cs b/scripts/Entities/Actions/SpellAction.cs
index 086a52a..f8819b9 100644
--- a/scripts/Entities/Actions/SpellAction.cs
+++ b/scripts/Entities/Actions/SpellAction.cs
@@ -1,23 +1,45 @@
using Godot;
using TheLegendOfGustav.Entities.Actors;
using TheLegendOfGustav.Magic;
+using TheLegendOfGustav.Utils;
namespace TheLegendOfGustav.Entities.Actions;
-public partial class SpellCommand(Actor actor, Vector2I offset, SpellResource spell) : DirectionalAction(actor, offset)
+/// <summary>
+/// Ação para quando o jogador joga um feitiço.
+/// </summary>
+public partial class SpellAction : DirectionalAction
{
- private SpellResource spell = spell;
+ private SpellResource spell;
+
+ public SpellAction(Actor actor, Vector2I offset, SpellResource spell) : base(actor, offset)
+ {
+ this.spell = spell;
+
+ Cost = 5;
+ }
public override bool Perform()
{
- Actor target = null;
+ Actor target;
- if (GetTarget() is Actor actor)
+ if (spell.Type == SpellType.Self)
+ {
+ target = Actor;
+ }
+ else if (GetTarget() is Actor actor)
{
target = actor;
}
+ else
+ {
+ return false;
+ }
- if (spell.Type == SpellType.Ranged && target == null) return false;
+ if (Grid.Distance(Actor.GridPosition, target.GridPosition) > spell.Range)
+ {
+ return false;
+ }
if (Actor.Mp < spell.Cost)
{
@@ -28,6 +50,8 @@ public partial class SpellCommand(Actor actor, Vector2I offset, SpellResource sp
{
effect.Apply(Actor, target);
}
+
+ Actor.Energy -= Cost;
return true;
}
}