Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
EloMap.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Runtime.Serialization;
3using CreativeSpore.SuperTilemapEditor;
4using Newtonsoft.Json;
5using UnityEngine;
6
7public class EloMap : EClass
8{
9 public class Cell
10 {
11 public Zone zone;
12
13 public int obj;
14
15 public Cell()
16 {
17 }
18
19 public Cell(int i)
20 {
21 obj = i / 10;
22 }
23
24 public int GetInt()
25 {
26 return obj * 10;
27 }
28 }
29
30 public class TileInfo
31 {
32 public Sprite sprite;
33
34 public bool blocked;
35
36 public bool isRoad;
37
38 public bool roadLeft;
39
40 public bool roadRight;
41
42 public bool roadUp;
43
44 public bool roadDown;
45
46 public bool rock;
47
48 public bool sea;
49
50 public bool shore;
51
53
54 public bool IsSnow
55 {
56 get
57 {
58 if (!(idSurface == "snow_edge"))
59 {
60 return idSurface == "snow";
61 }
62 return true;
63 }
64 }
65
66 public string idSurface => source?.alias ?? "";
67
68 public string idZoneProfile => source.zoneProfile;
69
70 public string name => source.GetName();
71
72 public bool CanEmbark => idZoneProfile != null;
73
74 public bool IsBridge => idSurface == "bridge";
75
76 public bool IsNeighborRoad
77 {
78 get
79 {
80 if (!roadLeft && !roadRight && !roadUp)
81 {
82 return roadDown;
83 }
84 return true;
85 }
86 }
87 }
88
89 [JsonProperty]
90 public int[,] _ints;
91
92 public Cell[,] cells;
93
94 public TilemapGroup group;
95
96 public STETilemap fogmap;
97
98 public STETilemap seaMap;
99
100 public STETilemap objScatterMap;
101
102 public STETilemap objmap;
103
104 public STETilemap extramap;
105
106 public STETilemap cloudmap;
107
108 public int w;
109
110 public int h;
111
112 public int minX;
113
114 public int minY;
115
116 public bool initialized;
117
119
121
122 public string idMap => "map_ntyris";
123
125 internal void OnSerializing(StreamingContext context)
126 {
127 if (cells == null)
128 {
129 return;
130 }
131 _ints = new int[w, h];
132 for (int i = 0; i < h; i++)
133 {
134 for (int j = 0; j < w; j++)
135 {
136 _ints[j, i] = cells[j, i].GetInt();
137 }
138 }
139 }
140
142 internal void OnDeserialized(StreamingContext context)
143 {
144 if (_ints == null || _ints.GetLength(0) <= 0)
145 {
146 return;
147 }
148 w = _ints.GetLength(0);
149 h = _ints.GetLength(1);
150 cells = new Cell[w, h];
151 for (int i = 0; i < h; i++)
152 {
153 for (int j = 0; j < w; j++)
154 {
155 cells[j, i] = new Cell(_ints[j, i]);
156 }
157 }
158 }
159
160 public void Init(EloMapActor _actor)
161 {
162 if (initialized)
163 {
164 return;
165 }
166 actor = _actor;
167 initialized = true;
168 group = actor.transMap.GetComponentInChildren<TilemapGroup>();
169 seaMap = group.Tilemaps[0];
170 cloudmap = group.Tilemaps[7];
171 extramap = group.Tilemaps[6];
172 fogmap = group.Tilemaps[5];
173 objmap = group.Tilemaps[4];
174 objScatterMap = group.Tilemaps[3];
175 w = fogmap.GridWidth;
176 h = fogmap.GridHeight;
177 minX = fogmap.MinGridX;
178 minY = fogmap.MinGridY;
179 if (cells == null)
180 {
181 cells = new Cell[w, h];
182 for (int i = 0; i < h; i++)
183 {
184 for (int j = 0; j < w; j++)
185 {
186 cells[j, i] = new Cell();
187 }
188 }
189 }
190 foreach (Spatial child in region.children)
191 {
192 int x = child.x;
193 int y = child.y;
194 Zone zone = child as Zone;
195 Cell cell = GetCell(x, y);
196 if (cell == null)
197 {
198 Debug.Log("cell is null:" + x + "/" + y);
199 continue;
200 }
201 cell.zone = zone;
202 if (!zone.IsInstance)
203 {
204 cell.obj = zone.icon;
205 }
206 }
207 for (int k = 0; k < h; k++)
208 {
209 for (int l = 0; l < w; l++)
210 {
211 Cell cell2 = cells[l, k];
212 int num = minX + l;
213 int num2 = minY + k;
214 if (cell2.obj != 0)
215 {
216 objmap.SetTile(num, num2, cell2.obj);
217 }
218 if (cell2.zone != null)
219 {
220 if (cell2.zone.UseLight)
221 {
222 AddLight(num, num2);
223 }
224 if (cell2.zone.IsClosed)
225 {
226 extramap.SetTile(num, num2, 333);
227 }
228 }
229 }
230 }
231 extramap.UpdateMeshImmediate();
232 objmap.UpdateMeshImmediate();
233 }
234
235 public void SetZone(int gx, int gy, Zone z, bool updateMesh = false)
236 {
237 Cell cell = GetCell(gx, gy);
238 if (cell == null)
239 {
240 Debug.Log("cell is null:" + gx + "/" + gy);
241 }
242 else if (z == null || cell.obj != z.icon)
243 {
244 cell.obj = z?.icon ?? 0;
245 if (z != null && z.source.tag.Contains("iconFlag"))
246 {
247 cell.obj = 306;
248 }
249 if (cell.zone != null && cell.zone.UseLight)
250 {
251 RemoveLight(gx, gy);
252 }
253 cell.zone = z;
254 if (cell.obj == 0)
255 {
256 objmap.Erase(gx, gy);
257 }
258 else
259 {
260 objmap.SetTile(gx, gy, cell.obj);
261 }
262 if (z != null && z.UseLight)
263 {
264 AddLight(gx, gy);
265 }
266 if (updateMesh)
267 {
268 objmap.UpdateMeshImmediate();
269 }
270 }
271 }
272
273 public Cell GetCell(Point pos)
274 {
275 return GetCell(pos.x + minX, pos.z + minY);
276 }
277
278 public Cell GetCell(int gx, int gy)
279 {
280 if (gx < minX || gy < minY || gx >= minX + w || gy >= minY + h)
281 {
282 return null;
283 }
284 return cells[gx - minX, gy - minY];
285 }
286
287 public TileInfo GetTileInfo(int gx, int gy)
288 {
289 TileInfo t = new TileInfo();
290 bool skip = false;
291 group.Tilemaps.ForeachReverse(delegate(STETilemap m)
292 {
293 if (!(m == fogmap || skip))
294 {
295 int tileIdFromTileData = Tileset.GetTileIdFromTileData(m.GetTileData(gx, gy));
296 TileData tileData = new TileData(m.GetTileData(gx, gy));
297 int tileId = tileData.tileId;
298 if (tileId >= 22 && tileId <= 25)
299 {
300 bool flipHorizontal = tileData.flipHorizontal;
301 bool flipVertical = tileData.flipVertical;
302 bool rot = tileData.rot90;
303 int num = (flipHorizontal ? 1 : 0) + (flipVertical ? 1 : 0) * 2 + (rot ? 1 : 0) * 4;
304 t.isRoad = true;
305 t.roadLeft = tileId == 23 || (tileId == 24 && (num == 4 || num == 0)) || (tileId == 25 && num != 6);
306 t.roadRight = tileId == 23 || (tileId == 24 && (num == 6 || num == 1)) || (tileId == 25 && num != 4);
307 t.roadUp = tileId == 22 || (tileId == 24 && (num == 4 || num == 6)) || (tileId == 25 && num != 0);
308 t.roadDown = tileId == 22 || (tileId == 24 && (num == 0 || num == 1)) || (tileId == 25 && num != 2);
309 }
310 SourceGlobalTile.Row row = EClass.sources.globalTiles.tileAlias.TryGetValue(tileIdFromTileData);
311 if (row != null)
312 {
313 t.source = row;
314 t.sprite = TilemapUtils.GetOrCreateTileSprite(actor.tileset, row.tiles[0]);
315 switch (row.alias)
316 {
317 case "wall":
318 case "rock":
319 t.rock = true;
320 break;
321 case "sea":
322 t.sea = true;
323 break;
324 case "beach":
325 t.shore = true;
326 break;
327 }
328 if (!row.zoneProfile.IsEmpty())
329 {
330 skip = true;
331 }
332 else if (row.attribs[0] == 0)
333 {
334 t.blocked = true;
335 }
336 }
337 }
338 });
339 return t;
340 }
341
342 public List<SourceGlobalTile.Row> GetSources(int gx, int gy)
343 {
344 List<SourceGlobalTile.Row> list = new List<SourceGlobalTile.Row>();
345 foreach (STETilemap tilemap in group.Tilemaps)
346 {
347 if (!(tilemap == fogmap))
348 {
349 int tileIdFromTileData = Tileset.GetTileIdFromTileData(tilemap.GetTileData(gx, gy));
350 if (EClass.sources.globalTiles.tileAlias.ContainsKey(tileIdFromTileData))
351 {
352 list.Add(EClass.sources.globalTiles.tileAlias.TryGetValue(tileIdFromTileData));
353 }
354 }
355 }
356 return list;
357 }
358
359 public bool CanBuildSite(int gx, int gy, int radius = 0, ElomapSiteType type = ElomapSiteType.Nefia)
360 {
361 if (radius != 0)
362 {
363 for (int i = gy - radius; i < gy + radius + 1; i++)
364 {
365 for (int j = gx - radius; j < gx + radius + 1; j++)
366 {
367 if (!CanBuildSite(j, i))
368 {
369 return false;
370 }
371 }
372 }
373 return true;
374 }
375 Cell cell = GetCell(gx, gy);
376 if (cell == null || cell.zone != null || cloudmap.GetTileData(gx, gy) != uint.MaxValue)
377 {
378 return false;
379 }
380 SourceGlobalTile.Row row = GetSources(gx, gy).LastItem();
381 if (type == ElomapSiteType.Mob)
382 {
383 if (row.id == 4 && EClass.rnd(5) == 0)
384 {
385 return false;
386 }
387 if (row.id == 7 && EClass.rnd(2) == 0)
388 {
389 return false;
390 }
391 }
392 else
393 {
394 if (row == null || !row.tag.Contains("site"))
395 {
396 return false;
397 }
398 if (row.id == 7 && EClass.rnd(5) == 0)
399 {
400 return false;
401 }
402 }
403 return true;
404 }
405
406 public bool IsSnow(int gx, int gy)
407 {
408 if (GetCell(gx, gy) == null)
409 {
410 return false;
411 }
412 SourceGlobalTile.Row row = GetSources(gx, gy).LastItem();
413 if (row != null)
414 {
415 return row.id == 7;
416 }
417 return false;
418 }
419
421 {
422 return GetZone(p.x + minX, p.z + minY);
423 }
424
425 public Zone GetZone(int gx, int gy)
426 {
427 Zone zone = null;
428 foreach (Spatial child in region.children)
429 {
430 if (child.x == gx && child.y == gy && (child as Zone)?.instance == null && (zone == null || zone is Zone_Field))
431 {
432 zone = child as Zone;
433 }
434 }
435 return zone;
436 }
437
438 public int GetRoadDist(int gx, int gy)
439 {
440 if (!initialized)
441 {
443 }
444 for (int i = 0; i < 100; i++)
445 {
446 for (int j = gy - i; j < gy + i + 1; j++)
447 {
448 for (int k = gx - i; k < gx + i + 1; k++)
449 {
450 if (j == gy - i || j == gy + i || k == gx - i || k == gx + i)
451 {
452 uint tileData = objScatterMap.GetTileData(k, j);
453 if (((tileData != uint.MaxValue) ? ((tileData & 0xFFF0000) >> 16) : 0) == 3)
454 {
455 return i;
456 }
457 tileData = seaMap.GetTileData(k, j);
458 if (((tileData != uint.MaxValue) ? ((tileData & 0xFFF0000) >> 16) : 0) == 3)
459 {
460 return i;
461 }
462 }
463 }
464 }
465 }
466 return 100;
467 }
468
469 public void AddLight(int gx, int gy, string id = "elolight")
470 {
471 SpriteRenderer spriteRenderer = Util.Instantiate<SpriteRenderer>(id, actor.transLight);
473 {
474 sr = spriteRenderer,
475 gx = gx,
476 gy = gy
477 };
478 actor.lights.Add(item);
479 spriteRenderer.transform.position = TilemapUtils.GetGridWorldPos(fogmap, gx, gy);
480 }
481
482 public void RemoveLight(int gx, int gy)
483 {
484 foreach (EloMapLight light in actor.lights)
485 {
486 if (light.gx == gx && light.gy == gy)
487 {
488 Object.DestroyImmediate(light.sr.gameObject);
489 actor.lights.Remove(light);
490 break;
491 }
492 }
493 }
494}
ElomapSiteType
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
Definition: EClass.cs:5
static Scene scene
Definition: EClass.cs:30
static int rnd(int a)
Definition: EClass.cs:50
static World world
Definition: EClass.cs:40
static SourceManager sources
Definition: EClass.cs:42
Transform transMap
Definition: EloMapActor.cs:9
Transform transLight
Definition: EloMapActor.cs:11
void Initialize(EloMap _elomap)
Definition: EloMapActor.cs:28
Tileset tileset
Definition: EloMapActor.cs:15
List< EloMapLight > lights
Definition: EloMapActor.cs:19
SpriteRenderer sr
Definition: EloMapLight.cs:5
Cell(int i)
Definition: EloMap.cs:19
Zone zone
Definition: EloMap.cs:11
int GetInt()
Definition: EloMap.cs:24
int obj
Definition: EloMap.cs:13
string name
Definition: EloMap.cs:70
bool IsNeighborRoad
Definition: EloMap.cs:77
bool roadLeft
Definition: EloMap.cs:38
string idZoneProfile
Definition: EloMap.cs:68
bool roadUp
Definition: EloMap.cs:42
bool IsSnow
Definition: EloMap.cs:55
bool blocked
Definition: EloMap.cs:34
bool isRoad
Definition: EloMap.cs:36
bool shore
Definition: EloMap.cs:50
SourceGlobalTile.Row source
Definition: EloMap.cs:52
bool IsBridge
Definition: EloMap.cs:74
bool CanEmbark
Definition: EloMap.cs:72
string idSurface
Definition: EloMap.cs:66
bool roadDown
Definition: EloMap.cs:44
bool roadRight
Definition: EloMap.cs:40
Sprite sprite
Definition: EloMap.cs:32
Definition: EloMap.cs:8
STETilemap extramap
Definition: EloMap.cs:104
void OnDeserialized(StreamingContext context)
Definition: EloMap.cs:142
Cell[,] cells
Definition: EloMap.cs:92
Cell GetCell(Point pos)
Definition: EloMap.cs:273
int minX
Definition: EloMap.cs:112
STETilemap fogmap
Definition: EloMap.cs:96
int w
Definition: EloMap.cs:108
void SetZone(int gx, int gy, Zone z, bool updateMesh=false)
Definition: EloMap.cs:235
STETilemap objmap
Definition: EloMap.cs:102
int minY
Definition: EloMap.cs:114
void RemoveLight(int gx, int gy)
Definition: EloMap.cs:482
bool IsSnow(int gx, int gy)
Definition: EloMap.cs:406
void AddLight(int gx, int gy, string id="elolight")
Definition: EloMap.cs:469
Cell GetCell(int gx, int gy)
Definition: EloMap.cs:278
STETilemap seaMap
Definition: EloMap.cs:98
EloMapActor actor
Definition: EloMap.cs:118
Zone GetZone(Point p)
Definition: EloMap.cs:420
void OnSerializing(StreamingContext context)
Definition: EloMap.cs:125
bool CanBuildSite(int gx, int gy, int radius=0, ElomapSiteType type=ElomapSiteType.Nefia)
Definition: EloMap.cs:359
void Init(EloMapActor _actor)
Definition: EloMap.cs:160
int GetRoadDist(int gx, int gy)
Definition: EloMap.cs:438
TilemapGroup group
Definition: EloMap.cs:94
string idMap
Definition: EloMap.cs:122
List< SourceGlobalTile.Row > GetSources(int gx, int gy)
Definition: EloMap.cs:342
TileInfo GetTileInfo(int gx, int gy)
Definition: EloMap.cs:287
int h
Definition: EloMap.cs:110
int[,] _ints
Definition: EloMap.cs:90
Zone GetZone(int gx, int gy)
Definition: EloMap.cs:425
STETilemap objScatterMap
Definition: EloMap.cs:100
bool initialized
Definition: EloMap.cs:116
Region region
Definition: EloMap.cs:120
STETilemap cloudmap
Definition: EloMap.cs:106
Definition: Point.cs:9
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
Definition: Region.cs:7
EloMap elomap
Definition: Region.cs:8
EloMapActor elomapActor
Definition: Scene.cs:97
Dictionary< int, Row > tileAlias
SourceGlobalTile globalTiles
int icon
Definition: Spatial.cs:82
bool IsClosed
Definition: Spatial.cs:445
SourceZone.Row source
Definition: Spatial.cs:441
int y
Definition: Spatial.cs:106
int x
Definition: Spatial.cs:94
List< Spatial > children
Definition: Spatial.cs:37
Region region
Definition: World.cs:23
Definition: Zone.cs:12
virtual bool UseLight
Definition: Zone.cs:391
bool IsInstance
Definition: Zone.cs:480