1
|
|
|
/* |
2
|
|
|
* This file is part of Araknemu. |
3
|
|
|
* |
4
|
|
|
* Araknemu is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* Araknemu is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with Araknemu. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2017-2019 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.game.fight.turn.action.cast; |
21
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.game.fight.castable.FightCastScope; |
23
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; |
24
|
|
|
import fr.quatrevieux.araknemu.game.fight.map.FightCell; |
25
|
|
|
import fr.quatrevieux.araknemu.game.fight.turn.FightTurn; |
26
|
|
|
import fr.quatrevieux.araknemu.game.fight.turn.action.ActionResult; |
27
|
|
|
import fr.quatrevieux.araknemu.game.fight.turn.action.ActionType; |
28
|
|
|
import fr.quatrevieux.araknemu.game.fight.turn.action.event.SpellCasted; |
29
|
|
|
import fr.quatrevieux.araknemu.game.spell.Spell; |
30
|
|
|
import fr.quatrevieux.araknemu.game.spell.effect.SpellEffect; |
31
|
|
|
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect; |
32
|
|
|
|
33
|
|
|
import java.util.List; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Result for successfully spell cast |
37
|
|
|
*/ |
38
|
|
|
public final class CastSuccess implements ActionResult { |
39
|
|
|
private final Cast action; |
40
|
|
|
private final Fighter caster; |
41
|
|
|
private final Spell spell; |
42
|
|
|
private final FightCell target; |
43
|
|
|
private final boolean critical; |
44
|
|
|
|
45
|
1 |
|
public CastSuccess(Cast action, Fighter caster, Spell spell, FightCell target, boolean critical) { |
46
|
1 |
|
this.action = action; |
47
|
1 |
|
this.caster = caster; |
48
|
1 |
|
this.spell = spell; |
49
|
1 |
|
this.target = target; |
50
|
1 |
|
this.critical = critical; |
51
|
1 |
|
} |
52
|
|
|
|
53
|
|
|
@Override |
54
|
|
|
public int action() { |
55
|
1 |
|
return ActionType.CAST.id(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
@Override |
59
|
|
|
public Fighter performer() { |
60
|
1 |
|
return caster; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
@Override |
64
|
|
|
public Object[] arguments() { |
65
|
1 |
|
return new Object[] {spell.id(), target.id(), spell.spriteId(), spell.level(), spell.spriteArgs()}; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
@Override |
69
|
|
|
public boolean success() { |
70
|
1 |
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
@Override |
74
|
|
|
public boolean secret() { |
75
|
1 |
|
return false; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Is a critical hit ? |
80
|
|
|
*/ |
81
|
|
|
public boolean critical() { |
82
|
1 |
|
return critical; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the spell effects |
87
|
|
|
*/ |
88
|
|
|
public List<SpellEffect> effects() { |
89
|
1 |
|
return critical ? spell.criticalEffects() : spell.effects(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
@Override |
93
|
|
|
public void apply(FightTurn turn) { |
94
|
1 |
|
if (critical) { |
95
|
1 |
|
caster.fight().send(ActionEffect.criticalHitSpell(caster, spell)); |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
turn.points().useActionPoints(spell.apCost()); |
99
|
1 |
|
turn.fight().effects().apply(FightCastScope.probable(spell, caster, target, effects())); |
100
|
|
|
|
101
|
1 |
|
turn.fight().dispatch(new SpellCasted(action)); |
102
|
1 |
|
} |
103
|
|
|
} |
104
|
|
|
|