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-2020 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.game.fight.turn.action.move; |
21
|
|
|
|
22
|
|
|
import fr.arakne.utils.maps.constant.Direction; |
23
|
|
|
import fr.arakne.utils.maps.path.Path; |
24
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter; |
25
|
|
|
import fr.quatrevieux.araknemu.game.fight.map.FightCell; |
26
|
|
|
import fr.quatrevieux.araknemu.game.fight.turn.FightTurn; |
27
|
|
|
import fr.quatrevieux.araknemu.game.fight.turn.action.ActionType; |
28
|
|
|
import fr.quatrevieux.araknemu.util.Asserter; |
29
|
|
|
import org.checkerframework.checker.index.qual.NonNegative; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Successful move result |
33
|
|
|
* A path can be truncated due to enemies on path, which will also result to a MoveSuccess result |
34
|
|
|
*/ |
35
|
|
|
public final class MoveSuccess implements MoveResult { |
36
|
|
|
private final Fighter performer; |
37
|
|
|
private final Path<FightCell> path; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param performer The current fighter which perform the action |
41
|
|
|
* @param path The new path |
42
|
|
|
*/ |
43
|
1 |
|
public MoveSuccess(Fighter performer, Path<FightCell> path) { |
44
|
1 |
|
this.performer = performer; |
45
|
1 |
|
this.path = path; |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
@Override |
49
|
|
|
public int action() { |
50
|
1 |
|
return ActionType.MOVE.id(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
@Override |
54
|
|
|
public boolean success() { |
55
|
1 |
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
@Override |
59
|
|
|
public boolean secret() { |
60
|
1 |
|
return performer.hidden(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
@Override |
64
|
|
|
public int lostActionPoints() { |
65
|
1 |
|
return 0; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
@Override |
69
|
|
|
public Fighter performer() { |
70
|
1 |
|
return performer; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
@Override |
74
|
|
|
public Object[] arguments() { |
75
|
1 |
|
return new Object[] { path.encodeWithStartCell() }; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
@Override |
79
|
|
|
public FightCell target() { |
80
|
1 |
|
return path.target(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
@Override |
84
|
|
|
public Direction orientation() { |
85
|
1 |
|
return path.last().direction(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
@Override |
89
|
|
|
public @NonNegative int lostMovementPoints() { |
90
|
1 |
|
return Asserter.castNonNegative(path.size() - 1); // The path contains the current fighter's cell |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
@Override |
94
|
|
|
public Path<FightCell> path() { |
95
|
1 |
|
return path; |
96
|
1 |
|
} |
97
|
1 |
|
|
98
|
1 |
|
@Override |
99
|
|
|
public void apply(FightTurn turn) { |
100
|
|
|
turn.points().useMovementPoints(lostMovementPoints()); |
101
|
|
|
performer.move(path.target()); |
102
|
|
|
performer.setOrientation(path.last().direction()); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|