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