1
|
|
|
/* |
2
|
|
|
* This file is part of ArakneLangLoader. |
3
|
|
|
* |
4
|
|
|
* ArakneLangLoader 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
|
|
|
* ArakneLangLoader 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 ArakneLangLoader. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2020 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.arakne.swflangloader.lang.maps; |
21
|
|
|
|
22
|
|
|
import java.util.Arrays; |
23
|
|
|
import java.util.Collection; |
24
|
|
|
import java.util.Objects; |
25
|
|
|
import java.util.stream.Collectors; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Dofus map sub area |
29
|
|
|
*/ |
30
|
1 |
|
final public class MapSubArea { |
31
|
|
|
private int id; |
32
|
|
|
private MapsFile maps; |
33
|
|
|
|
34
|
|
|
private String n; |
35
|
|
|
private int a; |
36
|
|
|
private Integer[] m; |
37
|
|
|
private int[] v; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return The sub area id. Unique on the maps file |
41
|
|
|
*/ |
42
|
|
|
public int id() { |
43
|
1 |
|
return id; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return The sub area name |
48
|
|
|
*/ |
49
|
|
|
public String name() { |
50
|
1 |
|
return n; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return The parent area id |
55
|
|
|
*/ |
56
|
|
|
public int areaId() { |
57
|
1 |
|
return a; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return The parent area instance |
62
|
|
|
*/ |
63
|
|
|
public MapArea area() { |
64
|
1 |
|
return maps.area(a); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return Available musics. May contains null elements |
69
|
|
|
*/ |
70
|
|
|
public Integer[] musics() { |
71
|
1 |
|
return m; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return Array of adjacent (i.e. accessible) sub areas ids |
76
|
|
|
*/ |
77
|
|
|
public int[] adjacentSubAreaIds() { |
78
|
1 |
|
return v; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return Array of adjacent (i.e. accessible) sub areas instances |
83
|
|
|
*/ |
84
|
|
|
public MapSubArea[] adjacentSubAreas() { |
85
|
1 |
|
return Arrays.stream(v).mapToObj(maps::subArea).toArray(MapSubArea[]::new); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Check if the other sub area is adjacent to the current one |
90
|
|
|
* |
91
|
|
|
* @param other The other sub area to check |
92
|
|
|
* |
93
|
|
|
* @return true if adjacent |
94
|
|
|
*/ |
95
|
|
|
public boolean isAdjacent(MapSubArea other) { |
96
|
1 |
|
for (int sa : v) { |
97
|
1 |
|
if (sa == other.id) { |
98
|
1 |
|
return true; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
return false; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return All maps of the current sub area |
107
|
|
|
*/ |
108
|
|
|
public Collection<MapPosition> maps() { |
109
|
1 |
|
return maps.allMapPositions().stream().filter(mapPosition -> mapPosition.subAreaId() == id).collect(Collectors.toList()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
@Override |
113
|
|
|
public boolean equals(Object o) { |
114
|
1 |
|
if (this == o) return true; |
115
|
1 |
|
if (o == null || getClass() != o.getClass()) return false; |
116
|
1 |
|
MapSubArea that = (MapSubArea) o; |
117
|
1 |
|
return id == that.id; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
@Override |
121
|
|
|
public int hashCode() { |
122
|
1 |
|
return Objects.hash(id); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
@Override |
126
|
|
|
public String toString() { |
127
|
1 |
|
return "MapSubArea{" + n + " (" + id + "), area=" + area().name() + " (" + a + ")}"; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
void setId(int id) { |
131
|
1 |
|
this.id = id; |
132
|
1 |
|
} |
133
|
|
|
|
134
|
|
|
void setMaps(MapsFile maps) { |
135
|
1 |
|
this.maps = maps; |
136
|
1 |
|
} |
137
|
|
|
} |
138
|
|
|
|