diff options
Diffstat (limited to 'scripts/Entities/Actions/SpellAction.cs')
| -rw-r--r-- | scripts/Entities/Actions/SpellAction.cs | 34 |
1 files changed, 29 insertions, 5 deletions
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; } } |
