summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actions/SpellAction.cs
blob: 086a52a03424e5069c7a5ba7b7982ed086e8052a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
	}
}