|
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.map; |
|
21
|
|
|
|
|
22
|
|
|
import fr.arakne.utils.maps.CoordinateCell; |
|
23
|
|
|
import fr.arakne.utils.maps.serializer.CellData; |
|
24
|
|
|
import fr.quatrevieux.araknemu.game.fight.exception.FightMapException; |
|
25
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter; |
|
26
|
|
|
|
|
27
|
|
|
import java.util.Optional; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Base fight cell |
|
31
|
|
|
*/ |
|
32
|
|
|
public final class WalkableFightCell implements FightCell { |
|
33
|
|
|
private final FightMap map; |
|
34
|
|
|
private final CellData template; |
|
35
|
|
|
private final int id; |
|
36
|
|
|
private final CoordinateCell<FightCell> coordinate; |
|
37
|
|
|
|
|
38
|
1 |
|
private PassiveFighter fighter; |
|
39
|
1 |
|
|
|
40
|
1 |
|
public WalkableFightCell(FightMap map, CellData template, int id) { |
|
41
|
1 |
|
this.map = map; |
|
42
|
1 |
|
this.template = template; |
|
43
|
|
|
this.id = id; |
|
44
|
|
|
this.coordinate = new CoordinateCell<>(this); |
|
45
|
|
|
} |
|
46
|
1 |
|
|
|
47
|
|
|
@Override |
|
48
|
|
|
public int id() { |
|
49
|
|
|
return id; |
|
50
|
|
|
} |
|
51
|
1 |
|
|
|
52
|
|
|
@Override |
|
53
|
|
|
public FightMap map() { |
|
54
|
|
|
return map; |
|
55
|
|
|
} |
|
56
|
1 |
|
|
|
57
|
|
|
@Override |
|
58
|
|
|
public boolean walkable() { |
|
59
|
|
|
return fighter == null; |
|
60
|
|
|
} |
|
61
|
1 |
|
|
|
62
|
|
|
@Override |
|
63
|
|
|
public boolean walkableIgnoreFighter() { |
|
64
|
|
|
return true; |
|
65
|
|
|
} |
|
66
|
1 |
|
|
|
67
|
|
|
@Override |
|
68
|
|
|
public boolean sightBlocking() { |
|
69
|
|
|
return !template.lineOfSight() || fighter != null; |
|
70
|
|
|
} |
|
71
|
1 |
|
|
|
72
|
|
|
@Override |
|
73
|
|
|
public CoordinateCell<FightCell> coordinate() { |
|
74
|
|
|
return coordinate; |
|
75
|
|
|
} |
|
76
|
1 |
|
|
|
77
|
1 |
|
@Override |
|
78
|
|
|
public Optional<PassiveFighter> fighter() { |
|
79
|
|
|
return Optional.ofNullable(fighter); |
|
80
|
1 |
|
} |
|
81
|
1 |
|
|
|
82
|
|
|
@Override |
|
83
|
|
|
public void set(PassiveFighter fighter) { |
|
84
|
|
|
if (this.fighter != null) { |
|
85
|
1 |
|
throw new FightMapException("A fighter is already set on this cell (" + id + ")"); |
|
86
|
1 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
this.fighter = fighter; |
|
89
|
1 |
|
} |
|
90
|
1 |
|
|
|
91
|
|
|
@Override |
|
92
|
|
|
public void removeFighter() { |
|
93
|
|
|
if (this.fighter == null) { |
|
94
|
1 |
|
throw new FightMapException("No fighter found on cell " + id); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
this.fighter = null; |
|
98
|
|
|
} |
|
99
|
1 |
|
|
|
100
|
1 |
|
@Override |
|
101
|
|
|
public int hashCode() { |
|
102
|
|
|
return id; |
|
103
|
1 |
|
} |
|
104
|
|
|
|
|
105
|
|
|
@Override |
|
106
|
|
|
public boolean equals(Object o) { |
|
107
|
1 |
|
if (this == o) { |
|
108
|
|
|
return true; |
|
109
|
1 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (o == null || getClass() != o.getClass()) { |
|
112
|
|
|
return false; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
final WalkableFightCell that = (WalkableFightCell) o; |
|
116
|
|
|
|
|
117
|
|
|
return id == that.id && map == that.map; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|