blob: 28d6caaa976c5b788a1f2b30b741c1e747ba361d (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
using Godot;
using TheLegendOfGustav.Entities.Actors;
using TheLegendOfGustav.Magic;
using TheLegendOfGustav.Utils;
namespace TheLegendOfGustav.Entities.Actions;
/// <summary>
/// Ação para quando o jogador joga um feitiço.
/// </summary>
public partial class SpellAction : DirectionalAction
{
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;
if (spell.Type == SpellType.Self)
{
target = Actor;
}
else if (GetTarget() is Actor actor)
{
target = actor;
}
else
{
return false;
}
if (Grid.Distance(Actor.GridPosition, target.GridPosition) > spell.Range)
{
return false;
}
if (Actor.Mp < spell.Cost)
{
return false;
}
Actor.Mp -= spell.Cost;
foreach (SpellEffect effect in spell.Effects)
{
effect.Apply(Actor, target);
}
Actor.Energy -= cost;
return true;
}
}
|