Elin Decompiled Documentation EA 23.319 Nightly Patch 1
Loading...
Searching...
No Matches
SourceMaterial.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5
6public class SourceMaterial : SourceDataInt<SourceMaterial.Row>
7{
8 [Serializable]
9 public class Row : BaseRow
10 {
11 public int id;
12
13 public string alias;
14
15 public string name_JP;
16
17 public string name;
18
19 public string category;
20
21 public string[] tag;
22
23 public string thing;
24
25 public string[] goods;
26
27 public string[] minerals;
28
29 public int decal;
30
31 public int decay;
32
33 public int grass;
34
35 public int defFloor;
36
37 public int defBlock;
38
39 public int edge;
40
41 public int ramp;
42
43 public string idSound;
44
45 public string soundFoot;
46
47 public int hardness;
48
49 public string[] groups;
50
51 public int tier;
52
53 public int chance;
54
55 public int weight;
56
57 public int value;
58
59 public int quality;
60
61 public int atk;
62
63 public int dmg;
64
65 public int dv;
66
67 public int pv;
68
69 public int dice;
70
71 public string[] bits;
72
73 public int[] elements;
74
75 public string[] altName;
76
77 public string[] altName_JP;
78
79 [NonSerialized]
81
82 [NonSerialized]
84
85 public Dictionary<int, int> elementMap;
86
87 public static string[] IDPick = new string[5] { "rock", "ore", "gem", "crystal", "bone" };
88
89 public static string[] IDAxe = new string[1] { "wood" };
90
91 [NonSerialized]
92 public string name_L;
93
94 [NonSerialized]
95 public string detail_L;
96
97 [NonSerialized]
98 public string[] altName_L;
99
100 public override bool UseAlias => true;
101
102 public override string GetAlias => alias;
103
104 public bool UsePick => IDPick.Contains(category);
105
106 public bool UseAxe => IDAxe.Contains(category);
107
108 public override void OnImportData(SourceData data)
109 {
110 base.OnImportData(data);
111 SetTiles();
112 }
113
114 public void Init()
115 {
117 HashSet<string> hashSet = new HashSet<string>(tag) { alias };
118 if (matColors == null)
119 {
120 matColors = new MatColors();
121 foreach (string item in hashSet)
122 {
123 if (item.StartsWith("addColorMain") || item.StartsWith("addCol_Main"))
124 {
125 matColors.main = item.ExtractInBetween('(', ')').ToColor();
126 }
127 else if (item.StartsWith("addColorAlt") || item.StartsWith("addCol_Alt"))
128 {
129 matColors.alt = item.ExtractInBetween('(', ')').ToColor();
130 }
131 }
132 Core.Instance.Colors.matColors[alias] = matColors;
133 Debug.Log($"#mod-content adding new material '{alias}'/{id}, main '{matColors.main}', alt '{matColors.alt}'");
134 }
135 matColor = matColors.main;
136 altColor = matColors.alt;
137 tag = hashSet.ToArray();
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 readonly IReadOnlyDictionary<string, int> RowMapping = new Dictionary<string, int>
325 {
326 ["id"] = 0,
327 ["alias"] = 1,
328 ["name_JP"] = 2,
329 ["name"] = 3,
330 ["category"] = 4,
331 ["tag"] = 5,
332 ["thing"] = 6,
333 ["goods"] = 7,
334 ["minerals"] = 8,
335 ["decal"] = 9,
336 ["decay"] = 10,
337 ["grass"] = 11,
338 ["defFloor"] = 12,
339 ["defBlock"] = 13,
340 ["edge"] = 14,
341 ["ramp"] = 15,
342 ["idSound"] = 16,
343 ["soundFoot"] = 17,
344 ["hardness"] = 18,
345 ["groups"] = 19,
346 ["tier"] = 20,
347 ["chance"] = 21,
348 ["weight"] = 22,
349 ["value"] = 23,
350 ["quality"] = 24,
351 ["atk"] = 25,
352 ["dmg"] = 26,
353 ["dv"] = 27,
354 ["pv"] = 28,
355 ["dice"] = 29,
356 ["bits"] = 30,
357 ["elements"] = 31,
358 ["altName"] = 32,
359 ["altName_JP"] = 33
360 };
361
362 public static readonly IReadOnlyDictionary<string, string> TypeMapping = new Dictionary<string, string>
363 {
364 ["id"] = "int",
365 ["alias"] = "string",
366 ["name_JP"] = "string",
367 ["name"] = "string",
368 ["category"] = "string",
369 ["tag"] = "string[]",
370 ["thing"] = "string",
371 ["goods"] = "string[]",
372 ["minerals"] = "string[]",
373 ["decal"] = "int",
374 ["decay"] = "int",
375 ["grass"] = "int",
376 ["defFloor"] = "int",
377 ["defBlock"] = "int",
378 ["edge"] = "int",
379 ["ramp"] = "int",
380 ["idSound"] = "string",
381 ["soundFoot"] = "string",
382 ["hardness"] = "int",
383 ["groups"] = "string[]",
384 ["tier"] = "int",
385 ["chance"] = "int",
386 ["weight"] = "int",
387 ["value"] = "int",
388 ["quality"] = "int",
389 ["atk"] = "int",
390 ["dmg"] = "int",
391 ["dv"] = "int",
392 ["pv"] = "int",
393 ["dice"] = "int",
394 ["bits"] = "string[]",
395 ["elements"] = "elements",
396 ["altName"] = "string[]",
397 ["altName_JP"] = "string[]"
398 };
399
400 public static Dictionary<string, TierList> tierMap = new Dictionary<string, TierList>();
401
402 public override string[] ImportFields => new string[1] { "altName" };
403
404 public override Row CreateRow()
405 {
406 return new Row
407 {
408 id = SourceData.GetInt(0),
409 alias = SourceData.GetString(1),
410 name_JP = SourceData.GetString(2),
411 name = SourceData.GetString(3),
412 category = SourceData.GetString(4),
413 tag = SourceData.GetStringArray(5),
414 thing = SourceData.GetString(6),
415 goods = SourceData.GetStringArray(7),
416 minerals = SourceData.GetStringArray(8),
417 decal = SourceData.GetInt(9),
418 decay = SourceData.GetInt(10),
419 grass = SourceData.GetInt(11),
420 defFloor = SourceData.GetInt(12),
421 defBlock = SourceData.GetInt(13),
422 edge = SourceData.GetInt(14),
423 ramp = SourceData.GetInt(15),
424 idSound = SourceData.GetString(16),
425 soundFoot = SourceData.GetString(17),
426 hardness = SourceData.GetInt(18),
427 groups = SourceData.GetStringArray(19),
428 tier = SourceData.GetInt(20),
429 chance = SourceData.GetInt(21),
430 weight = SourceData.GetInt(22),
431 value = SourceData.GetInt(23),
432 quality = SourceData.GetInt(24),
433 atk = SourceData.GetInt(25),
434 dmg = SourceData.GetInt(26),
435 dv = SourceData.GetInt(27),
436 pv = SourceData.GetInt(28),
437 dice = SourceData.GetInt(29),
438 bits = SourceData.GetStringArray(30),
439 elements = Core.ParseElements(SourceData.GetStr(31)),
440 altName = SourceData.GetStringArray(32),
441 altName_JP = SourceData.GetStringArray(33)
442 };
443 }
444
445 public override Row CreateRowByMapping(IReadOnlyDictionary<string, int> mapping)
446 {
447 return new Row
448 {
449 id = SourceData.GetInt(mapping["id"]),
450 alias = SourceData.GetString(mapping["alias"]),
451 name_JP = SourceData.GetString(mapping["name_JP"]),
452 name = SourceData.GetString(mapping["name"]),
453 category = SourceData.GetString(mapping["category"]),
454 tag = SourceData.GetStringArray(mapping["tag"]),
455 thing = SourceData.GetString(mapping["thing"]),
456 goods = SourceData.GetStringArray(mapping["goods"]),
457 minerals = SourceData.GetStringArray(mapping["minerals"]),
458 decal = SourceData.GetInt(mapping["decal"]),
459 decay = SourceData.GetInt(mapping["decay"]),
460 grass = SourceData.GetInt(mapping["grass"]),
461 defFloor = SourceData.GetInt(mapping["defFloor"]),
462 defBlock = SourceData.GetInt(mapping["defBlock"]),
463 edge = SourceData.GetInt(mapping["edge"]),
464 ramp = SourceData.GetInt(mapping["ramp"]),
465 idSound = SourceData.GetString(mapping["idSound"]),
466 soundFoot = SourceData.GetString(mapping["soundFoot"]),
467 hardness = SourceData.GetInt(mapping["hardness"]),
468 groups = SourceData.GetStringArray(mapping["groups"]),
469 tier = SourceData.GetInt(mapping["tier"]),
470 chance = SourceData.GetInt(mapping["chance"]),
471 weight = SourceData.GetInt(mapping["weight"]),
472 value = SourceData.GetInt(mapping["value"]),
473 quality = SourceData.GetInt(mapping["quality"]),
474 atk = SourceData.GetInt(mapping["atk"]),
475 dmg = SourceData.GetInt(mapping["dmg"]),
476 dv = SourceData.GetInt(mapping["dv"]),
477 pv = SourceData.GetInt(mapping["pv"]),
478 dice = SourceData.GetInt(mapping["dice"]),
479 bits = SourceData.GetStringArray(mapping["bits"]),
480 elements = Core.ParseElements(SourceData.GetStr(mapping["elements"])),
481 altName = SourceData.GetStringArray(mapping["altName"]),
482 altName_JP = SourceData.GetStringArray(mapping["altName_JP"])
483 };
484 }
485
486 public override void SetRow(Row r)
487 {
488 map[r.id] = r;
489 }
490
491 public override IReadOnlyDictionary<string, int> GetRowMapping()
492 {
493 return RowMapping;
494 }
495
496 public override IReadOnlyDictionary<string, string> GetTypeMapping()
497 {
498 return TypeMapping;
499 }
500
501 public override void OnInit()
502 {
503 Cell.matList = rows;
504 tierMap.Clear();
505 tierMap.Add("gem", new TierList());
506 tierMap.Add("ore", new TierList());
507 foreach (Row row in rows)
508 {
509 row.Init();
510 row.elementMap = Element.GetElementMap(row.elements);
511 if (!row.groups.IsEmpty())
512 {
513 string[] groups = row.groups;
514 foreach (string key in groups)
515 {
516 TierList tierList = tierMap.TryGetValue(key);
517 if (tierList == null)
518 {
519 tierList = new TierList();
520 tierMap[key] = tierList;
521 }
522 Tier obj = tierList.tiers[row.tier];
523 obj.list.Add(row);
524 obj.sum += row.chance;
525 }
526 }
527 string category = row.category;
528 if (!(category == "gem"))
529 {
530 if (category == "ore")
531 {
532 Tier obj2 = tierMap["ore"].tiers[row.tier];
533 obj2.list.Add(row);
534 obj2.sum += row.chance;
535 }
536 }
537 else
538 {
539 Tier obj3 = tierMap["gem"].tiers[row.tier];
540 obj3.list.Add(row);
541 obj3.sum += row.chance;
542 }
543 }
544 }
545
546 public override void OnAfterImportData()
547 {
548 rows.Sort((Row a, Row b) => a.id - b.id);
549 }
550
551 public void OnImportRow(Row r)
552 {
553 List<int> list = new List<int>(r.elements);
554 for (int i = 0; i < r.elements.Length; i += 2)
555 {
556 Add(r.elements[i], r.elements[i + 1]);
557 }
558 Add(13, r.hardness);
559 r.elements = list.ToArray();
560 void Add(int ele, int a)
561 {
562 list.Add(ele);
563 list.Add(a);
564 }
565 }
566}
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:3194
Thing AddThing(string id, int lv=-1)
Definition: Card.cs:3257
void ModNum(int a, bool notify=true)
Definition: Card.cs:3673
bool IsSnowTile
Definition: Cell.cs:790
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:80
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:538
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:2074
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:1011
static string GetString(int id)
Definition: SourceData.cs:1016
static int GetInt(int id)
Definition: SourceData.cs:981
static string GetStr(int id, bool useDefault=false)
Definition: SourceData.cs:1021
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)
override Row CreateRowByMapping(IReadOnlyDictionary< string, int > mapping)
static Dictionary< string, TierList > tierMap
static readonly IReadOnlyDictionary< string, int > RowMapping
override void SetRow(Row r)
override Row CreateRow()
override IReadOnlyDictionary< string, string > GetTypeMapping()
override void OnInit()
static readonly IReadOnlyDictionary< string, string > TypeMapping
override void OnAfterImportData()
override string[] ImportFields
override IReadOnlyDictionary< string, int > GetRowMapping()
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