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