Elin Decompiled Documentation EA 23.345.1 Nightly
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 [NonSerialized]
404
406
407 public Row this[int id] => Lookup[id];
408
409 public override string[] ImportFields => new string[1] { "altName" };
410
411 public override Row CreateRow()
412 {
413 return new Row
414 {
415 id = SourceData.GetInt(0),
416 alias = SourceData.GetString(1),
417 name_JP = SourceData.GetString(2),
418 name = SourceData.GetString(3),
419 category = SourceData.GetString(4),
420 tag = SourceData.GetStringArray(5),
421 thing = SourceData.GetString(6),
422 goods = SourceData.GetStringArray(7),
423 minerals = SourceData.GetStringArray(8),
424 decal = SourceData.GetInt(9),
425 decay = SourceData.GetInt(10),
426 grass = SourceData.GetInt(11),
427 defFloor = SourceData.GetInt(12),
428 defBlock = SourceData.GetInt(13),
429 edge = SourceData.GetInt(14),
430 ramp = SourceData.GetInt(15),
431 idSound = SourceData.GetString(16),
432 soundFoot = SourceData.GetString(17),
433 hardness = SourceData.GetInt(18),
434 groups = SourceData.GetStringArray(19),
435 tier = SourceData.GetInt(20),
436 chance = SourceData.GetInt(21),
437 weight = SourceData.GetInt(22),
438 value = SourceData.GetInt(23),
439 quality = SourceData.GetInt(24),
440 atk = SourceData.GetInt(25),
441 dmg = SourceData.GetInt(26),
442 dv = SourceData.GetInt(27),
443 pv = SourceData.GetInt(28),
444 dice = SourceData.GetInt(29),
445 bits = SourceData.GetStringArray(30),
446 elements = Core.ParseElements(SourceData.GetStr(31)),
447 altName = SourceData.GetStringArray(32),
448 altName_JP = SourceData.GetStringArray(33)
449 };
450 }
451
452 public override Row CreateRowByMapping(IReadOnlyDictionary<string, int> mapping)
453 {
454 return new Row
455 {
456 id = SourceData.GetInt(mapping["id"]),
457 alias = SourceData.GetString(mapping["alias"]),
458 name_JP = SourceData.GetString(mapping["name_JP"]),
459 name = SourceData.GetString(mapping["name"]),
460 category = SourceData.GetString(mapping["category"]),
461 tag = SourceData.GetStringArray(mapping["tag"]),
462 thing = SourceData.GetString(mapping["thing"]),
463 goods = SourceData.GetStringArray(mapping["goods"]),
464 minerals = SourceData.GetStringArray(mapping["minerals"]),
465 decal = SourceData.GetInt(mapping["decal"]),
466 decay = SourceData.GetInt(mapping["decay"]),
467 grass = SourceData.GetInt(mapping["grass"]),
468 defFloor = SourceData.GetInt(mapping["defFloor"]),
469 defBlock = SourceData.GetInt(mapping["defBlock"]),
470 edge = SourceData.GetInt(mapping["edge"]),
471 ramp = SourceData.GetInt(mapping["ramp"]),
472 idSound = SourceData.GetString(mapping["idSound"]),
473 soundFoot = SourceData.GetString(mapping["soundFoot"]),
474 hardness = SourceData.GetInt(mapping["hardness"]),
475 groups = SourceData.GetStringArray(mapping["groups"]),
476 tier = SourceData.GetInt(mapping["tier"]),
477 chance = SourceData.GetInt(mapping["chance"]),
478 weight = SourceData.GetInt(mapping["weight"]),
479 value = SourceData.GetInt(mapping["value"]),
480 quality = SourceData.GetInt(mapping["quality"]),
481 atk = SourceData.GetInt(mapping["atk"]),
482 dmg = SourceData.GetInt(mapping["dmg"]),
483 dv = SourceData.GetInt(mapping["dv"]),
484 pv = SourceData.GetInt(mapping["pv"]),
485 dice = SourceData.GetInt(mapping["dice"]),
486 bits = SourceData.GetStringArray(mapping["bits"]),
487 elements = Core.ParseElements(SourceData.GetStr(mapping["elements"])),
488 altName = SourceData.GetStringArray(mapping["altName"]),
489 altName_JP = SourceData.GetStringArray(mapping["altName_JP"])
490 };
491 }
492
493 public override void SetRow(Row r)
494 {
495 map[r.id] = r;
496 }
497
498 public override IReadOnlyDictionary<string, int> GetRowMapping()
499 {
500 return RowMapping;
501 }
502
503 public override IReadOnlyDictionary<string, string> GetTypeMapping()
504 {
505 return TypeMapping;
506 }
507
508 public override void OnInit()
509 {
510 Lookup.Build();
511 Cell.matSource = this;
512 Cell.matList = rows;
513 tierMap.Clear();
514 tierMap.Add("gem", new TierList());
515 tierMap.Add("ore", new TierList());
516 foreach (Row row in rows)
517 {
518 row.Init();
519 row.elementMap = Element.GetElementMap(row.elements);
520 int tier = row.tier;
521 if (tier < 0 || tier > 7)
522 {
523 Debug.LogWarning($"#source material {row.id}/{row.alias} tier {row.tier} is not within 0~{7}");
524 row.tier = Mathf.Clamp(row.tier, 0, 7);
525 }
526 if (!row.groups.IsEmpty())
527 {
528 string[] groups = row.groups;
529 foreach (string key in groups)
530 {
531 TierList tierList = tierMap.TryGetValue(key);
532 if (tierList == null)
533 {
534 tierList = new TierList();
535 tierMap[key] = tierList;
536 }
537 Tier obj = tierList.tiers[row.tier];
538 obj.list.Add(row);
539 obj.sum += row.chance;
540 }
541 }
542 string category = row.category;
543 if (!(category == "gem"))
544 {
545 if (category == "ore")
546 {
547 Tier obj2 = tierMap["ore"].tiers[row.tier];
548 obj2.list.Add(row);
549 obj2.sum += row.chance;
550 }
551 }
552 else
553 {
554 Tier obj3 = tierMap["gem"].tiers[row.tier];
555 obj3.list.Add(row);
556 obj3.sum += row.chance;
557 }
558 }
559 }
560
561 public override void OnAfterImportData()
562 {
563 rows.Sort((Row r) => r.id);
564 }
565
566 public void OnImportRow(Row r)
567 {
568 List<int> list = new List<int>(r.elements);
569 for (int i = 0; i < r.elements.Length; i += 2)
570 {
571 Add(r.elements[i], r.elements[i + 1]);
572 }
573 Add(13, r.hardness);
574 r.elements = list.ToArray();
575 void Add(int ele, int a)
576 {
577 list.Add(ele);
578 list.Add(a);
579 }
580 }
581}
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:3217
Thing AddThing(string id, int lv=-1)
Definition: Card.cs:3280
void ModNum(int a, bool notify=true)
Definition: Card.cs:3696
bool IsSnowTile
Definition: Cell.cs:826
UD_String_MatData matColors
Definition: Core.cs:14
static int[] ParseElements(string str)
Definition: Core.cs:737
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:568
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:2169
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)
TileLookup< Row > _lookup
override Row CreateRow()
override IReadOnlyDictionary< string, string > GetTypeMapping()
override void OnInit()
static readonly IReadOnlyDictionary< string, string > TypeMapping
override void OnAfterImportData()
TileLookup< Row > Lookup
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