|
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.module; |
|
21
|
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.core.event.Listener; |
|
23
|
|
|
import fr.quatrevieux.araknemu.game.fight.Fight; |
|
24
|
|
|
import fr.quatrevieux.araknemu.game.fight.castable.effect.EffectsHandler; |
|
25
|
|
|
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.shifting.RaulebaqueHandler; |
|
26
|
|
|
import fr.quatrevieux.araknemu.game.fight.event.FightStarted; |
|
27
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; |
|
28
|
|
|
import fr.quatrevieux.araknemu.game.fight.map.FightCell; |
|
29
|
|
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; |
|
30
|
|
|
|
|
31
|
|
|
import java.util.HashMap; |
|
32
|
|
|
import java.util.Map; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Module for handle Raulebaque spell |
|
36
|
|
|
* |
|
37
|
|
|
* This spell will reset all fighters position to the initial one |
|
38
|
|
|
*/ |
|
39
|
|
|
public final class RaulebaqueModule implements FightModule { |
|
40
|
|
|
private final Fight fight; |
|
41
|
|
|
|
|
42
|
|
|
private @MonotonicNonNull Map<Fighter, FightCell> startPositions; |
|
43
|
|
|
|
|
44
|
1 |
|
public RaulebaqueModule(Fight fight) { |
|
45
|
1 |
|
this.fight = fight; |
|
46
|
1 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
@Override |
|
49
|
|
|
public void effects(EffectsHandler handler) { |
|
50
|
1 |
|
handler.register(784, new RaulebaqueHandler(fight, this)); |
|
51
|
1 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get all start positions of fighters |
|
55
|
|
|
* The map key is the fighter, and the value is the start cell |
|
56
|
|
|
*/ |
|
57
|
|
|
public Map<Fighter, FightCell> startPositions() { |
|
58
|
1 |
|
if (startPositions == null) { |
|
59
|
1 |
|
throw new IllegalStateException("Positions must be loaded at fight start"); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
return startPositions; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
@Override |
|
66
|
|
|
public Listener[] listeners() { |
|
67
|
1 |
|
return new Listener[] { |
|
68
|
1 |
|
new Listener<FightStarted>() { |
|
69
|
|
|
@Override |
|
70
|
|
|
public void on(FightStarted event) { |
|
71
|
1 |
|
loadStartPositions(); |
|
72
|
1 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
@Override |
|
75
|
|
|
public Class<FightStarted> event() { |
|
76
|
1 |
|
return FightStarted.class; |
|
77
|
|
|
} |
|
78
|
|
|
}, |
|
79
|
|
|
}; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Load the start positions |
|
84
|
|
|
*/ |
|
85
|
|
|
private void loadStartPositions() { |
|
86
|
1 |
|
startPositions = new HashMap<>(); |
|
87
|
|
|
|
|
88
|
1 |
|
for (Fighter fighter : fight.fighters()) { |
|
89
|
1 |
|
startPositions.put(fighter, fighter.cell()); |
|
90
|
1 |
|
} |
|
91
|
1 |
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|