|
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
|
|
|
* Non walkable fight cell |
|
31
|
|
|
*/ |
|
32
|
|
|
public final class UnwalkableFightCell implements FightCell { |
|
33
|
|
|
private final FightMap map; |
|
34
|
|
|
private final CellData template; |
|
35
|
|
|
private final int id; |
|
36
|
1 |
|
private final CoordinateCell<FightCell> coordinate; |
|
37
|
1 |
|
|
|
38
|
1 |
|
public UnwalkableFightCell(FightMap map, CellData template, int id) { |
|
39
|
1 |
|
this.map = map; |
|
40
|
1 |
|
this.template = template; |
|
41
|
|
|
this.id = id; |
|
42
|
|
|
this.coordinate = new CoordinateCell<>(this); |
|
43
|
|
|
} |
|
44
|
1 |
|
|
|
45
|
|
|
@Override |
|
46
|
|
|
public FightMap map() { |
|
47
|
|
|
return map; |
|
48
|
|
|
} |
|
49
|
1 |
|
|
|
50
|
|
|
@Override |
|
51
|
|
|
public int id() { |
|
52
|
|
|
return id; |
|
53
|
|
|
} |
|
54
|
1 |
|
|
|
55
|
|
|
@Override |
|
56
|
|
|
public boolean walkable() { |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
1 |
|
|
|
60
|
|
|
@Override |
|
61
|
|
|
public boolean walkableIgnoreFighter() { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
1 |
|
|
|
65
|
|
|
@Override |
|
66
|
|
|
public boolean sightBlocking() { |
|
67
|
|
|
return !template.lineOfSight(); |
|
68
|
|
|
} |
|
69
|
1 |
|
|
|
70
|
|
|
@Override |
|
71
|
|
|
public CoordinateCell<FightCell> coordinate() { |
|
72
|
|
|
return coordinate; |
|
73
|
|
|
} |
|
74
|
1 |
|
|
|
75
|
|
|
@Override |
|
76
|
|
|
public Optional<PassiveFighter> fighter() { |
|
77
|
|
|
return Optional.empty(); |
|
78
|
|
|
} |
|
79
|
1 |
|
|
|
80
|
|
|
@Override |
|
81
|
|
|
public void set(PassiveFighter fighter) { |
|
82
|
|
|
throw new FightMapException("Cannot add fighter on unwalkable cell"); |
|
83
|
|
|
} |
|
84
|
1 |
|
|
|
85
|
|
|
@Override |
|
86
|
|
|
public void removeFighter() { |
|
87
|
|
|
throw new FightMapException("Cannot remove fighter on unwalkable cell"); |
|
88
|
|
|
} |
|
89
|
1 |
|
|
|
90
|
1 |
|
@Override |
|
91
|
|
|
public int hashCode() { |
|
92
|
|
|
return id; |
|
93
|
1 |
|
} |
|
94
|
1 |
|
|
|
95
|
|
|
@Override |
|
96
|
|
|
public boolean equals(Object o) { |
|
97
|
1 |
|
if (this == o) { |
|
98
|
|
|
return true; |
|
99
|
1 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
if (o == null || getClass() != o.getClass()) { |
|
102
|
|
|
return false; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
final UnwalkableFightCell that = (UnwalkableFightCell) o; |
|
106
|
|
|
|
|
107
|
|
|
return id == that.id && map == that.map; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|