Elin Decompiled Documentation EA 23.287 Stable Patch 3
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 }
135 matColor = matColors.main;
136 altColor = matColors.alt;
137 SetTiles();
138 }
139
140 public void SetTiles()
141 {
142 }
143
144 public bool HasEnc(int id)
145 {
146 foreach (int key in elementMap.Keys)
147 {
148 if (key == id)
149 {
150 return true;
151 }
152 }
153 return false;
154 }
155
156 public void AddBlood(Point p, int a = 1)
157 {
158 if (decal == 0)
159 {
160 return;
161 }
162 if (p.cell.IsSnowTile && this != MATERIAL.sourceSnow)
163 {
164 MATERIAL.sourceSnow.AddBlood(p, a);
165 return;
166 }
167 for (int i = 0; i < a; i++)
168 {
169 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);
170 }
171 }
172
173 public void PlayHitEffect(Point p, int emit = 2)
174 {
175 Effect.Get("mine2").Play(p).SetParticleColor(GetColor())
176 .Emit(emit + EClass.rnd(4));
177 }
178
180 {
181 return Core.Instance.Colors.matColors[alias].main;
182 }
183
184 public string TryGetSound(string suffx, RenderRow c = null)
185 {
186 string soundImpact = GetSoundImpact(c);
187 if (EClass.Sound.Exist(soundImpact + "_" + suffx))
188 {
189 return soundImpact + "_" + suffx;
190 }
191 return soundImpact;
192 }
193
194 public string GetSoundDead(RenderRow c = null)
195 {
196 return TryGetSound("dead", c);
197 }
198
199 public string GetSoundDrop(RenderRow c = null)
200 {
201 return TryGetSound("drop", c);
202 }
203
204 public string GetSoundCraft(RenderRow c = null)
205 {
206 if (category == "wood")
207 {
208 return "build_progress";
209 }
210 return TryGetSound("craft", c);
211 }
212
213 public string GetSoundImpact(RenderRow c = null)
214 {
215 if (c != null && !c.idSound.IsEmpty())
216 {
217 return "Material/" + c.idSound;
218 }
219 return "Material/" + idSound;
220 }
221
222 public void CreateByProduct(Thing container, int num)
223 {
225 thing.ModNum(num);
226 container.AddThing(thing);
227 C("dye");
228 switch (category)
229 {
230 case "bone":
231 C("glass");
232 C("stick");
233 break;
234 case "crystal":
235 C("glass");
236 C("gem");
237 break;
238 case "ore":
239 C("scrap");
240 C("cutstone");
241 C("ingot");
242 break;
243 case "rock":
244 C("rock");
245 C("pebble");
246 C("cutstone");
247 break;
248 case "soil":
249 C("glass");
250 C("clay");
251 C("brick");
252 break;
253 case "gem":
254 C("cutstone");
255 C("ingot");
256 C("gem");
257 break;
258 case "wood":
259 C("plank");
260 C("stick");
261 C("bark");
262 break;
263 case "fiber":
264 C("thread");
265 C("texture");
266 C("string");
267 break;
268 case "skin":
269 C("texture");
270 break;
271 }
272 string[] array = goods;
273 foreach (string text in array)
274 {
275 C(text);
276 }
277 void C(string _id)
278 {
279 Thing thing2 = ThingGen.Create(_id);
280 thing2.ChangeMaterial(id);
281 thing2.ModNum(num);
282 container.AddThing(thing2);
283 }
284 }
285 }
286
287 public class TierList
288 {
289 public Tier[] tiers;
290
291 public TierList()
292 {
293 tiers = new Tier[8];
294 for (int i = 0; i < 8; i++)
295 {
296 tiers[i] = new Tier();
297 }
298 }
299 }
300
301 public class Tier
302 {
303 public int sum;
304
305 public List<Row> list = new List<Row>();
306
307 public Row Select()
308 {
309 int num = 0;
310 int num2 = EClass.rnd(sum);
311 foreach (Row item in list)
312 {
313 num += item.chance;
314 if (num2 < num)
315 {
316 return item;
317 }
318 }
319 return list.RandomItem();
320 }
321 }
322
323 public static Dictionary<string, TierList> tierMap = new Dictionary<string, TierList>();
324
325 public override string[] ImportFields => new string[1] { "altName" };
326
327 public override Row CreateRow()
328 {
329 return new Row
330 {
331 id = SourceData.GetInt(0),
332 alias = SourceData.GetString(1),
333 name_JP = SourceData.GetString(2),
334 name = SourceData.GetString(3),
335 category = SourceData.GetString(4),
336 tag = SourceData.GetStringArray(5),
337 thing = SourceData.GetString(6),
338 goods = SourceData.GetStringArray(7),
339 minerals = SourceData.GetStringArray(8),
340 decal = SourceData.GetInt(9),
341 decay = SourceData.GetInt(10),
342 grass = SourceData.GetInt(11),
343 defFloor = SourceData.GetInt(12),
344 defBlock = SourceData.GetInt(13),
345 edge = SourceData.GetInt(14),
346 ramp = SourceData.GetInt(15),
347 idSound = SourceData.GetString(16),
348 soundFoot = SourceData.GetString(17),
349 hardness = SourceData.GetInt(18),
350 groups = SourceData.GetStringArray(19),
351 tier = SourceData.GetInt(20),
352 chance = SourceData.GetInt(21),
353 weight = SourceData.GetInt(22),
354 value = SourceData.GetInt(23),
355 quality = SourceData.GetInt(24),
356 atk = SourceData.GetInt(25),
357 dmg = SourceData.GetInt(26),
358 dv = SourceData.GetInt(27),
359 pv = SourceData.GetInt(28),
360 dice = SourceData.GetInt(29),
361 bits = SourceData.GetStringArray(30),
362 elements = Core.ParseElements(SourceData.GetStr(31)),
363 altName = SourceData.GetStringArray(32),
364 altName_JP = SourceData.GetStringArray(33)
365 };
366 }
367
368 public override void SetRow(Row r)
369 {
370 map[r.id] = r;
371 }
372
373 public override void OnInit()
374 {
375 Cell.matList = rows;
376 tierMap.Clear();
377 tierMap.Add("gem", new TierList());
378 tierMap.Add("ore", new TierList());
379 foreach (Row row in rows)
380 {
381 row.Init();
382 row.elementMap = Element.GetElementMap(row.elements);
383 if (!row.groups.IsEmpty())
384 {
385 string[] groups = row.groups;
386 foreach (string key in groups)
387 {
388 TierList tierList = tierMap.TryGetValue(key);
389 if (tierList == null)
390 {
391 tierList = new TierList();
392 tierMap[key] = tierList;
393 }
394 Tier obj = tierList.tiers[row.tier];
395 obj.list.Add(row);
396 obj.sum += row.chance;
397 }
398 }
399 string category = row.category;
400 if (!(category == "gem"))
401 {
402 if (category == "ore")
403 {
404 Tier obj2 = tierMap["ore"].tiers[row.tier];
405 obj2.list.Add(row);
406 obj2.sum += row.chance;
407 }
408 }
409 else
410 {
411 Tier obj3 = tierMap["gem"].tiers[row.tier];
412 obj3.list.Add(row);
413 obj3.sum += row.chance;
414 }
415 }
416 }
417
418 public override void OnAfterImportData()
419 {
420 rows.Sort((Row a, Row b) => a.id - b.id);
421 }
422
423 public void OnImportRow(Row r)
424 {
425 List<int> list = new List<int>(r.elements);
426 for (int i = 0; i < r.elements.Length; i += 2)
427 {
428 Add(r.elements[i], r.elements[i + 1]);
429 }
430 Add(13, r.hardness);
431 r.elements = list.ToArray();
432 void Add(int ele, int a)
433 {
434 list.Add(ele);
435 list.Add(a);
436 }
437 }
438}
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