Elin Decompiled Documentation EA 23.290 Nightly
Loading...
Searching...
No Matches
SourceMaterial.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5public class SourceMaterial : SourceDataInt<SourceMaterial.Row>
6{
7 [Serializable]
8 public class Row : BaseRow
9 {
10 public int id;
11
12 public string alias;
13
14 public string name_JP;
15
16 public string name;
17
18 public string category;
19
20 public string[] tag;
21
22 public string thing;
23
24 public string[] goods;
25
26 public string[] minerals;
27
28 public int decal;
29
30 public int decay;
31
32 public int grass;
33
34 public int defFloor;
35
36 public int defBlock;
37
38 public int edge;
39
40 public int ramp;
41
42 public string idSound;
43
44 public string soundFoot;
45
46 public int hardness;
47
48 public string[] groups;
49
50 public int tier;
51
52 public int chance;
53
54 public int weight;
55
56 public int value;
57
58 public int quality;
59
60 public int atk;
61
62 public int dmg;
63
64 public int dv;
65
66 public int pv;
67
68 public int dice;
69
70 public string[] bits;
71
72 public int[] elements;
73
74 public string[] altName;
75
76 public string[] altName_JP;
77
78 [NonSerialized]
80
81 [NonSerialized]
83
84 public Dictionary<int, int> elementMap;
85
86 public static string[] IDPick = new string[5] { "rock", "ore", "gem", "crystal", "bone" };
87
88 public static string[] IDAxe = new string[1] { "wood" };
89
90 [NonSerialized]
91 public string name_L;
92
93 [NonSerialized]
94 public string detail_L;
95
96 [NonSerialized]
97 public string[] altName_L;
98
99 public override bool UseAlias => true;
100
101 public override string GetAlias => alias;
102
103 public bool UsePick => IDPick.Contains(category);
104
105 public bool UseAxe => IDAxe.Contains(category);
106
107 public override void OnImportData(SourceData data)
108 {
109 base.OnImportData(data);
110 SetTiles();
111 }
112
113 public void Init()
114 {
116 if (matColors == null)
117 {
118 matColors = new MatColors();
119 string[] array = tag;
120 foreach (string text in array)
121 {
122 if (text.StartsWith("addCol"))
123 {
124 if (text.Contains("_Main"))
125 {
126 matColors.main = text.ExtractInBetween('(', ')').ToColor();
127 }
128 if (text.Contains("_Alt"))
129 {
130 matColors.alt = text.ExtractInBetween('(', ')').ToColor();
131 }
132 }
133 }
134 Core.Instance.Colors.matColors[alias] = matColors;
135 }
136 matColor = matColors.main;
137 altColor = matColors.alt;
138 SetTiles();
139 }
140
141 public void SetTiles()
142 {
143 }
144
145 public bool HasEnc(int id)
146 {
147 foreach (int key in elementMap.Keys)
148 {
149 if (key == id)
150 {
151 return true;
152 }
153 }
154 return false;
155 }
156
157 public void AddBlood(Point p, int a = 1)
158 {
159 if (decal == 0)
160 {
161 return;
162 }
163 if (p.cell.IsSnowTile && this != MATERIAL.sourceSnow)
164 {
165 MATERIAL.sourceSnow.AddBlood(p, a);
166 return;
167 }
168 for (int i = 0; i < a; i++)
169 {
170 EClass._map.AddDecal(p.x + ((EClass.rnd(2) != 0) ? (EClass.rnd(3) - 1) : 0), p.z + ((EClass.rnd(2) != 0) ? (EClass.rnd(3) - 1) : 0), decal);
171 }
172 }
173
174 public void PlayHitEffect(Point p, int emit = 2)
175 {
176 Effect.Get("mine2").Play(p).SetParticleColor(GetColor())
177 .Emit(emit + EClass.rnd(4));
178 }
179
181 {
182 return Core.Instance.Colors.matColors[alias].main;
183 }
184
185 public string TryGetSound(string suffx, RenderRow c = null)
186 {
187 string soundImpact = GetSoundImpact(c);
188 if (EClass.Sound.Exist(soundImpact + "_" + suffx))
189 {
190 return soundImpact + "_" + suffx;
191 }
192 return soundImpact;
193 }
194
195 public string GetSoundDead(RenderRow c = null)
196 {
197 return TryGetSound("dead", c);
198 }
199
200 public string GetSoundDrop(RenderRow c = null)
201 {
202 return TryGetSound("drop", c);
203 }
204
205 public string GetSoundCraft(RenderRow c = null)
206 {
207 if (category == "wood")
208 {
209 return "build_progress";
210 }
211 return TryGetSound("craft", c);
212 }
213
214 public string GetSoundImpact(RenderRow c = null)
215 {
216 if (c != null && !c.idSound.IsEmpty())
217 {
218 return "Material/" + c.idSound;
219 }
220 return "Material/" + idSound;
221 }
222
223 public void CreateByProduct(Thing container, int num)
224 {
226 thing.ModNum(num);
227 container.AddThing(thing);
228 C("dye");
229 switch (category)
230 {
231 case "bone":
232 C("glass");
233 C("stick");
234 break;
235 case "crystal":
236 C("glass");
237 C("gem");
238 break;
239 case "ore":
240 C("scrap");
241 C("cutstone");
242 C("ingot");
243 break;
244 case "rock":
245 C("rock");
246 C("pebble");
247 C("cutstone");
248 break;
249 case "soil":
250 C("glass");
251 C("clay");
252 C("brick");
253 break;
254 case "gem":
255 C("cutstone");
256 C("ingot");
257 C("gem");
258 break;
259 case "wood":
260 C("plank");
261 C("stick");
262 C("bark");
263 break;
264 case "fiber":
265 C("thread");
266 C("texture");
267 C("string");
268 break;
269 case "skin":
270 C("texture");
271 break;
272 }
273 string[] array = goods;
274 foreach (string text in array)
275 {
276 C(text);
277 }
278 void C(string _id)
279 {
280 Thing thing2 = ThingGen.Create(_id);
281 thing2.ChangeMaterial(id);
282 thing2.ModNum(num);
283 container.AddThing(thing2);
284 }
285 }
286 }
287
288 public class TierList
289 {
290 public Tier[] tiers;
291
292 public TierList()
293 {
294 tiers = new Tier[8];
295 for (int i = 0; i < 8; i++)
296 {
297 tiers[i] = new Tier();
298 }
299 }
300 }
301
302 public class Tier
303 {
304 public int sum;
305
306 public List<Row> list = new List<Row>();
307
308 public Row Select()
309 {
310 int num = 0;
311 int num2 = EClass.rnd(sum);
312 foreach (Row item in list)
313 {
314 num += item.chance;
315 if (num2 < num)
316 {
317 return item;
318 }
319 }
320 return list.RandomItem();
321 }
322 }
323
324 public static Dictionary<string, TierList> tierMap = new Dictionary<string, TierList>();
325
326 public override string[] ImportFields => new string[1] { "altName" };
327
328 public override Row CreateRow()
329 {
330 return new Row
331 {
332 id = SourceData.GetInt(0),
333 alias = SourceData.GetString(1),
334 name_JP = SourceData.GetString(2),
335 name = SourceData.GetString(3),
336 category = SourceData.GetString(4),
337 tag = SourceData.GetStringArray(5),
338 thing = SourceData.GetString(6),
339 goods = SourceData.GetStringArray(7),
340 minerals = SourceData.GetStringArray(8),
341 decal = SourceData.GetInt(9),
342 decay = SourceData.GetInt(10),
343 grass = SourceData.GetInt(11),
344 defFloor = SourceData.GetInt(12),
345 defBlock = SourceData.GetInt(13),
346 edge = SourceData.GetInt(14),
347 ramp = SourceData.GetInt(15),
348 idSound = SourceData.GetString(16),
349 soundFoot = SourceData.GetString(17),
350 hardness = SourceData.GetInt(18),
351 groups = SourceData.GetStringArray(19),
352 tier = SourceData.GetInt(20),
353 chance = SourceData.GetInt(21),
354 weight = SourceData.GetInt(22),
355 value = SourceData.GetInt(23),
356 quality = SourceData.GetInt(24),
357 atk = SourceData.GetInt(25),
358 dmg = SourceData.GetInt(26),
359 dv = SourceData.GetInt(27),
360 pv = SourceData.GetInt(28),
361 dice = SourceData.GetInt(29),
362 bits = SourceData.GetStringArray(30),
363 elements = Core.ParseElements(SourceData.GetStr(31)),
364 altName = SourceData.GetStringArray(32),
365 altName_JP = SourceData.GetStringArray(33)
366 };
367 }
368
369 public override void SetRow(Row r)
370 {
371 map[r.id] = r;
372 }
373
374 public override void OnInit()
375 {
376 Cell.matList = rows;
377 tierMap.Clear();
378 tierMap.Add("gem", new TierList());
379 tierMap.Add("ore", new TierList());
380 foreach (Row row in rows)
381 {
382 row.Init();
383 row.elementMap = Element.GetElementMap(row.elements);
384 if (!row.groups.IsEmpty())
385 {
386 string[] groups = row.groups;
387 foreach (string key in groups)
388 {
389 TierList tierList = tierMap.TryGetValue(key);
390 if (tierList == null)
391 {
392 tierList = new TierList();
393 tierMap[key] = tierList;
394 }
395 Tier obj = tierList.tiers[row.tier];
396 obj.list.Add(row);
397 obj.sum += row.chance;
398 }
399 }
400 string category = row.category;
401 if (!(category == "gem"))
402 {
403 if (category == "ore")
404 {
405 Tier obj2 = tierMap["ore"].tiers[row.tier];
406 obj2.list.Add(row);
407 obj2.sum += row.chance;
408 }
409 }
410 else
411 {
412 Tier obj3 = tierMap["gem"].tiers[row.tier];
413 obj3.list.Add(row);
414 obj3.sum += row.chance;
415 }
416 }
417 }
418
419 public override void OnAfterImportData()
420 {
421 rows.Sort((Row a, Row b) => a.id - b.id);
422 }
423
424 public void OnImportRow(Row r)
425 {
426 List<int> list = new List<int>(r.elements);
427 for (int i = 0; i < r.elements.Length; i += 2)
428 {
429 Add(r.elements[i], r.elements[i + 1]);
430 }
431 Add(13, r.hardness);
432 r.elements = list.ToArray();
433 void Add(int ele, int a)
434 {
435 list.Add(ele);
436 list.Add(a);
437 }
438 }
439}
list. Add(item3)
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:3117
Thing AddThing(string id, int lv=-1)
Definition: Card.cs:3180
void ModNum(int a, bool notify=true)
Definition: Card.cs:3597
bool IsSnowTile
Definition: Cell.cs:782
UD_String_MatData matColors
Definition: Core.cs:14
static int[] ParseElements(string str)
Definition: Core.cs:726
static new Core Instance
Definition: Core.cs:15
ColorProfile Colors
Definition: Core.cs:53
Definition: EClass.cs:6
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static SoundManager Sound
Definition: EClass.cs:47
Definition: Effect.cs:7
static Effect Get(Effect original)
Definition: Effect.cs:85
void Play(float delay, Point from, float fixY=0f, Point to=null, Sprite sprite=null)
Definition: Effect.cs:100
static Dictionary< int, int > GetElementMap(int[] list)
Definition: ELEMENT.cs:536
static SourceMaterial.Row sourceSnow
Definition: MATERIAL.cs:41
void AddDecal(int x, int z, int id, int amount=1, bool refresh=true)
Definition: Map.cs:2029
Color main
Definition: MatColors.cs:7
Color alt
Definition: MatColors.cs:9
Definition: Point.cs:9
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
Cell cell
Definition: Point.cs:51
static string[] GetStringArray(int id)
Definition: SourceData.cs:912
static string GetString(int id)
Definition: SourceData.cs:917
static int GetInt(int id)
Definition: SourceData.cs:882
static string GetStr(int id, bool useDefault=false)
Definition: SourceData.cs:922
bool HasEnc(int id)
string TryGetSound(string suffx, RenderRow c=null)
static string[] IDAxe
void CreateByProduct(Thing container, int num)
string GetSoundImpact(RenderRow c=null)
static string[] IDPick
string GetSoundCraft(RenderRow c=null)
void AddBlood(Point p, int a=1)
override void OnImportData(SourceData data)
string GetSoundDead(RenderRow c=null)
string GetSoundDrop(RenderRow c=null)
Dictionary< int, int > elementMap
override string GetAlias
override bool UseAlias
void PlayHitEffect(Point p, int emit=2)
static Dictionary< string, TierList > tierMap
override void SetRow(Row r)
override Row CreateRow()
override void OnInit()
override void OnAfterImportData()
override string[] ImportFields
void OnImportRow(Row r)
static Thing CreateRawMaterial(SourceMaterial.Row m)
Definition: ThingGen.cs:68
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
bool TryGetValue(TKey key, out TValue value)
Definition: UDictionary.cs:178