Elin Decompiled Documentation EA 23.193 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 }
200 else if (!zone.IsInstance)
201 {
202 cell.zone = zone;
203 cell.obj = zone.icon;
204 }
205 }
206 for (int k = 0; k < h; k++)
207 {
208 for (int l = 0; l < w; l++)
209 {
210 Cell cell2 = cells[l, k];
211 int num = minX + l;
212 int num2 = minY + k;
213 if (cell2.obj != 0)
214 {
215 objmap.SetTile(num, num2, cell2.obj);
216 }
217 if (cell2.zone != null)
218 {
219 if (cell2.zone.UseLight)
220 {
221 AddLight(num, num2);
222 }
223 if (cell2.zone.IsClosed)
224 {
225 extramap.SetTile(num, num2, 333);
226 }
227 }
228 }
229 }
230 extramap.UpdateMeshImmediate();
231 objmap.UpdateMeshImmediate();
232 }
233
234 public void SetZone(int gx, int gy, Zone z, bool updateMesh = false)
235 {
236 Cell cell = GetCell(gx, gy);
237 if (cell == null)
238 {
239 Debug.Log("cell is null:" + gx + "/" + gy);
240 }
241 else if (z == null || cell.obj != z.icon)
242 {
243 cell.obj = z?.icon ?? 0;
244 if (z != null && z.source.tag.Contains("iconFlag"))
245 {
246 cell.obj = 306;
247 }
248 if (cell.zone != null && cell.zone.UseLight)
249 {
250 RemoveLight(gx, gy);
251 }
252 cell.zone = z;
253 if (cell.obj == 0)
254 {
255 objmap.Erase(gx, gy);
256 }
257 else
258 {
259 objmap.SetTile(gx, gy, cell.obj);
260 }
261 if (z != null && z.UseLight)
262 {
263 AddLight(gx, gy);
264 }
265 if (updateMesh)
266 {
267 objmap.UpdateMeshImmediate();
268 }
269 }
270 }
271
272 public Cell GetCell(Point pos)
273 {
274 return GetCell(pos.x + minX, pos.z + minY);
275 }
276
277 public Cell GetCell(int gx, int gy)
278 {
279 if (gx < minX || gy < minY || gx >= minX + w || gy >= minY + h)
280 {
281 return null;
282 }
283 return cells[gx - minX, gy - minY];
284 }
285
286 public TileInfo GetTileInfo(int gx, int gy)
287 {
288 TileInfo t = new TileInfo();
289 bool skip = false;
290 group.Tilemaps.ForeachReverse(delegate(STETilemap m)
291 {
292 if (!(m == fogmap || skip))
293 {
294 int tileIdFromTileData = Tileset.GetTileIdFromTileData(m.GetTileData(gx, gy));
295 TileData tileData = new TileData(m.GetTileData(gx, gy));
296 int tileId = tileData.tileId;
297 if (tileId >= 22 && tileId <= 25)
298 {
299 bool flipHorizontal = tileData.flipHorizontal;
300 bool flipVertical = tileData.flipVertical;
301 bool rot = tileData.rot90;
302 int num = (flipHorizontal ? 1 : 0) + (flipVertical ? 1 : 0) * 2 + (rot ? 1 : 0) * 4;
303 t.isRoad = true;
304 t.roadLeft = tileId == 23 || (tileId == 24 && (num == 4 || num == 0)) || (tileId == 25 && num != 6);
305 t.roadRight = tileId == 23 || (tileId == 24 && (num == 6 || num == 1)) || (tileId == 25 && num != 4);
306 t.roadUp = tileId == 22 || (tileId == 24 && (num == 4 || num == 6)) || (tileId == 25 && num != 0);
307 t.roadDown = tileId == 22 || (tileId == 24 && (num == 0 || num == 1)) || (tileId == 25 && num != 2);
308 }
309 SourceGlobalTile.Row row = EClass.sources.globalTiles.tileAlias.TryGetValue(tileIdFromTileData);
310 if (row != null)
311 {
312 t.source = row;
313 t.sprite = TilemapUtils.GetOrCreateTileSprite(actor.tileset, row.tiles[0]);
314 switch (row.alias)
315 {
316 case "wall":
317 case "rock":
318 t.rock = true;
319 break;
320 case "sea":
321 t.sea = true;
322 break;
323 case "beach":
324 t.shore = true;
325 break;
326 }
327 if (!row.zoneProfile.IsEmpty())
328 {
329 skip = true;
330 }
331 else if (row.attribs[0] == 0)
332 {
333 t.blocked = true;
334 }
335 }
336 }
337 });
338 return t;
339 }
340
341 public List<SourceGlobalTile.Row> GetSources(int gx, int gy)
342 {
343 List<SourceGlobalTile.Row> list = new List<SourceGlobalTile.Row>();
344 foreach (STETilemap tilemap in group.Tilemaps)
345 {
346 if (!(tilemap == fogmap))
347 {
348 int tileIdFromTileData = Tileset.GetTileIdFromTileData(tilemap.GetTileData(gx, gy));
349 if (EClass.sources.globalTiles.tileAlias.ContainsKey(tileIdFromTileData))
350 {
351 list.Add(EClass.sources.globalTiles.tileAlias.TryGetValue(tileIdFromTileData));
352 }
353 }
354 }
355 return list;
356 }
357
358 public bool CanBuildSite(int gx, int gy, int radius = 0, ElomapSiteType type = ElomapSiteType.Nefia)
359 {
360 if (radius != 0)
361 {
362 for (int i = gy - radius; i < gy + radius + 1; i++)
363 {
364 for (int j = gx - radius; j < gx + radius + 1; j++)
365 {
366 if (!CanBuildSite(j, i, 0, type))
367 {
368 return false;
369 }
370 }
371 }
372 return true;
373 }
374 Cell cell = GetCell(gx, gy);
375 if (cell == null || cell.zone != null || cloudmap.GetTileData(gx, gy) != uint.MaxValue)
376 {
377 return false;
378 }
379 SourceGlobalTile.Row row = GetSources(gx, gy).LastItem();
380 if (row == null)
381 {
382 return false;
383 }
384 switch (type)
385 {
386 case ElomapSiteType.NefiaWater:
387 if (row.id != 4)
388 {
389 return false;
390 }
391 break;
392 case ElomapSiteType.Mob:
393 if (row.id == 4 && EClass.rnd(5) == 0)
394 {
395 return false;
396 }
397 if (row.id == 7 && EClass.rnd(2) == 0)
398 {
399 return false;
400 }
401 break;
402 default:
403 if (row == null || !row.tag.Contains("site"))
404 {
405 return false;
406 }
407 if (row.id == 7 && EClass.rnd(5) == 0)
408 {
409 return false;
410 }
411 break;
412 }
413 return true;
414 }
415
416 public bool IsWater(int gx, int gy)
417 {
418 if (GetCell(gx, gy) == null)
419 {
420 return false;
421 }
422 SourceGlobalTile.Row row = GetSources(gx, gy).LastItem();
423 if (row != null)
424 {
425 if (row.id != 4)
426 {
427 return row.id == 15;
428 }
429 return true;
430 }
431 return false;
432 }
433
434 public bool IsSnow(int gx, int gy)
435 {
436 if (GetCell(gx, gy) == null)
437 {
438 return false;
439 }
440 SourceGlobalTile.Row row = GetSources(gx, gy).LastItem();
441 if (row != null)
442 {
443 return row.id == 7;
444 }
445 return false;
446 }
447
449 {
450 return GetZone(p.x + minX, p.z + minY);
451 }
452
453 public Zone GetZone(int gx, int gy)
454 {
455 Zone zone = null;
456 foreach (Spatial child in region.children)
457 {
458 if (child.x == gx && child.y == gy && (child as Zone)?.instance == null && (zone == null || zone is Zone_Field))
459 {
460 zone = child as Zone;
461 }
462 }
463 return zone;
464 }
465
466 public int GetRoadDist(int gx, int gy)
467 {
468 if (!initialized)
469 {
471 }
472 for (int i = 0; i < 100; i++)
473 {
474 for (int j = gy - i; j < gy + i + 1; j++)
475 {
476 for (int k = gx - i; k < gx + i + 1; k++)
477 {
478 if (j == gy - i || j == gy + i || k == gx - i || k == gx + i)
479 {
480 uint tileData = objScatterMap.GetTileData(k, j);
481 if (((tileData != uint.MaxValue) ? ((tileData & 0xFFF0000) >> 16) : 0) == 3)
482 {
483 return i;
484 }
485 tileData = seaMap.GetTileData(k, j);
486 if (((tileData != uint.MaxValue) ? ((tileData & 0xFFF0000) >> 16) : 0) == 3)
487 {
488 return i;
489 }
490 }
491 }
492 }
493 }
494 return 100;
495 }
496
497 public void AddLight(int gx, int gy, string id = "elolight")
498 {
499 SpriteRenderer spriteRenderer = Util.Instantiate<SpriteRenderer>(id, actor.transLight);
501 {
502 sr = spriteRenderer,
503 gx = gx,
504 gy = gy
505 };
506 actor.lights.Add(item);
507 spriteRenderer.transform.position = TilemapUtils.GetGridWorldPos(fogmap, gx, gy);
508 }
509
510 public void RemoveLight(int gx, int gy)
511 {
512 foreach (EloMapLight light in actor.lights)
513 {
514 if (light.gx == gx && light.gy == gy)
515 {
516 Object.DestroyImmediate(light.sr.gameObject);
517 actor.lights.Remove(light);
518 break;
519 }
520 }
521 }
522}
ElomapSiteType
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
Definition: EClass.cs:5
static Scene scene
Definition: EClass.cs:30
static World world
Definition: EClass.cs:40
static int rnd(long a)
Definition: EClass.cs:58
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:272
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:234
STETilemap objmap
Definition: EloMap.cs:102
int minY
Definition: EloMap.cs:114
void RemoveLight(int gx, int gy)
Definition: EloMap.cs:510
bool IsSnow(int gx, int gy)
Definition: EloMap.cs:434
void AddLight(int gx, int gy, string id="elolight")
Definition: EloMap.cs:497
Cell GetCell(int gx, int gy)
Definition: EloMap.cs:277
STETilemap seaMap
Definition: EloMap.cs:98
EloMapActor actor
Definition: EloMap.cs:118
Zone GetZone(Point p)
Definition: EloMap.cs:448
void OnSerializing(StreamingContext context)
Definition: EloMap.cs:125
bool CanBuildSite(int gx, int gy, int radius=0, ElomapSiteType type=ElomapSiteType.Nefia)
Definition: EloMap.cs:358
void Init(EloMapActor _actor)
Definition: EloMap.cs:160
int GetRoadDist(int gx, int gy)
Definition: EloMap.cs:466
bool IsWater(int gx, int gy)
Definition: EloMap.cs:416
TilemapGroup group
Definition: EloMap.cs:94
string idMap
Definition: EloMap.cs:122
List< SourceGlobalTile.Row > GetSources(int gx, int gy)
Definition: EloMap.cs:341
TileInfo GetTileInfo(int gx, int gy)
Definition: EloMap.cs:286
int h
Definition: EloMap.cs:110
int[,] _ints
Definition: EloMap.cs:90
Zone GetZone(int gx, int gy)
Definition: EloMap.cs:453
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:101
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:393
bool IsInstance
Definition: Zone.cs:484