Elin Modding Docs Doc
Loading...
Searching...
No Matches
MapPiece.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using UnityEngine;
5
6// Token: 0x02000697 RID: 1687
7public class MapPiece : EScriptable
8{
9 // Token: 0x17000E23 RID: 3619
10 // (get) Token: 0x06003104 RID: 12548 RVA: 0x0011210D File Offset: 0x0011030D
11 public static MapPiece Instance
12 {
13 get
14 {
15 MapPiece result;
16 if ((result = MapPiece._Instance) == null)
17 {
18 result = (MapPiece._Instance = Resources.Load<MapPiece>("World/Map/MapPiece"));
19 }
20 return result;
21 }
22 }
23
24 // Token: 0x17000E24 RID: 3620
25 // (get) Token: 0x06003105 RID: 12549 RVA: 0x00112128 File Offset: 0x00110328
26 public static bool IsEditor
27 {
28 get
29 {
30 return EClass.debug.enableMapPieceEditor;
31 }
32 }
33
34 // Token: 0x06003106 RID: 12550 RVA: 0x00112134 File Offset: 0x00110334
35 public PartialMap GetMap(MapPiece.Type type, string tag, float ruin)
36 {
37 this.Init();
38 MapPiece.Item item = this.items.RandomItemWeighted(delegate(MapPiece.Item a)
39 {
40 if (a.chance != 0f || !(type.ToString() == a.id))
41 {
42 return a.chance * (float)((type == MapPiece.Type.Any || type.ToString() == a.id) ? 1 : 0);
43 }
44 return 1f;
45 });
46 if (item.paths.Count == 0)
47 {
48 Debug.Log("no path");
49 return null;
50 }
51 string[] array = tag.IsEmpty() ? null : tag.Split(',', StringSplitOptions.None);
52 List<MapPiece.MapPath> list = new List<MapPiece.MapPath>();
53 foreach (MapPiece.MapPath mapPath in item.paths)
54 {
55 if (mapPath.tag.IsEmpty() || (array != null && array.Contains(tag)))
56 {
57 list.Add(mapPath);
58 }
59 }
60 if (list.Count == 0)
61 {
62 return null;
63 }
64 string path = list.RandomItem<MapPiece.MapPath>().path;
65 Debug.Log("Loading PartialMap:" + path);
66 PartialMap partialMap = MapPiece.CacheMap.TryGetValue(path, null);
67 if (partialMap == null)
68 {
69 partialMap = PartialMap.Load(path);
70 MapPiece.CacheMap.Add(path, partialMap);
71 }
72 if (partialMap.allowRotate)
73 {
74 partialMap.dir = EScriptable.rnd(4);
75 }
76 partialMap.procedural = true;
77 partialMap.ruinChance = ruin;
78 return partialMap;
79 }
80
81 // Token: 0x06003107 RID: 12551 RVA: 0x00112280 File Offset: 0x00110480
82 public void Init()
83 {
84 if (MapPiece.initialized)
85 {
86 return;
87 }
88 foreach (MapPiece.Item item in this.items)
89 {
90 item.paths.Clear();
91 foreach (string text in Directory.GetFiles(CorePath.MapPieceSave + item.id, "*", SearchOption.AllDirectories))
92 {
93 if (text.EndsWith("mp"))
94 {
95 DirectoryInfo directory = new FileInfo(text).Directory;
96 string tag = (directory.Parent.Name != item.id) ? "" : directory.Name;
97 item.paths.Add(new MapPiece.MapPath
98 {
99 path = text,
100 tag = tag
101 });
102 }
103 }
104 }
105 MapPiece.initialized = true;
106 }
107
108 // Token: 0x06003108 RID: 12552 RVA: 0x00112380 File Offset: 0x00110580
109 public void Reset()
110 {
111 MapPiece.initialized = false;
112 }
113
114 // Token: 0x04001B16 RID: 6934
115 private static MapPiece _Instance;
116
117 // Token: 0x04001B17 RID: 6935
118 public static bool initialized;
119
120 // Token: 0x04001B18 RID: 6936
121 public List<MapPiece.Item> items;
122
123 // Token: 0x04001B19 RID: 6937
124 public static Dictionary<string, PartialMap> CacheMap = new Dictionary<string, PartialMap>();
125
126 // Token: 0x02000BFA RID: 3066
127 public class MapPath
128 {
129 // Token: 0x04002FB9 RID: 12217
130 public string path;
131
132 // Token: 0x04002FBA RID: 12218
133 public string tag;
134 }
135
136 // Token: 0x02000BFB RID: 3067
137 public enum Type
138 {
139 // Token: 0x04002FBC RID: 12220
140 Any,
141 // Token: 0x04002FBD RID: 12221
142 Deco,
143 // Token: 0x04002FBE RID: 12222
144 Treasure,
145 // Token: 0x04002FBF RID: 12223
146 Trap,
147 // Token: 0x04002FC0 RID: 12224
148 Concert,
149 // Token: 0x04002FC1 RID: 12225
150 Farm
151 }
152
153 // Token: 0x02000BFC RID: 3068
154 [Serializable]
155 public class Item
156 {
157 // Token: 0x04002FC2 RID: 12226
158 public string id;
159
160 // Token: 0x04002FC3 RID: 12227
161 public float chance;
162
163 // Token: 0x04002FC4 RID: 12228
164 [HideInInspector]
165 [NonSerialized]
166 public List<MapPiece.MapPath> paths = new List<MapPiece.MapPath>();
167 }
168}