Elin Decompiled Documentation EA 23.169 Nightly
Loading...
Searching...
No Matches
ThingGen.cs
Go to the documentation of this file.
1using System.Linq;
2using UnityEngine;
3
4public class ThingGen : CardGen
5{
6 public static Thing _Create(string id, int idMat = -1, int lv = -1)
7 {
8 Thing thing = new Thing();
9 CardRow s = EClass.sources.cards.map.TryGetValue(id);
10 if (s == null)
11 {
12 Debug.LogError("exception: Item not found:" + id);
13 id = "869";
14 s = EClass.sources.cards.map.TryGetValue(id);
15 }
16 if (s.isOrigin)
17 {
18 id = SpawnListThing.Get("origin_" + id, (SourceThing.Row a) => a.origin == s).Select(lv)?.id ?? EClass.sources.cards.rows.Where((CardRow a) => a.origin == s).First().id;
19 }
20 if (lv < 1)
21 {
22 lv = 1;
23 }
24 thing.Create(id, idMat, lv);
25 if (thing.trait is TraitAmmo)
26 {
27 thing.SetNum(EClass.rnd(20) + 10);
28 }
29 return thing;
30 }
31
32 public static Thing TestCreate()
33 {
34 return _Create(SpawnList.Get("thing").Select().id);
35 }
36
37 public static Thing CreateCurrency(int a, string id = "money")
38 {
39 return Create(id).SetNum(a);
40 }
41
42 public static Thing CreateParcel(string idLang = null, params Thing[] things)
43 {
44 Thing thing = Create("parcel");
45 foreach (Thing c in things)
46 {
47 thing.AddCard(c);
48 }
49 thing.c_idRefName = idLang.lang();
50 return thing;
51 }
52
53 public static Thing Create(string id, int idMat = -1, int lv = -1)
54 {
55 return _Create(id, idMat, lv);
56 }
57
58 public static Thing Create(string id, string idMat, int lv = -1)
59 {
60 return Create(id, idMat.IsEmpty() ? (-1) : EClass.sources.materials.alias[idMat].id, lv);
61 }
62
63 public static Thing CreateFromFilter(string id, int lv = -1)
64 {
65 return _Create(SpawnList.Get(id).Select(lv).id, -1, lv);
66 }
67
69 {
70 Thing thing = Create(m.thing);
71 thing.ChangeMaterial(m.id);
72 return thing;
73 }
74
75 public static Thing CreateFromCategory(string idCat, int lv = -1)
76 {
77 return _Create(SpawnListThing.Get("cat_" + idCat, (SourceThing.Row s) => EClass.sources.categories.map[s.category].IsChildOf(idCat)).Select(lv).id, -1, lv);
78 }
79
80 public static Thing CreateFromTag(string idTag, int lv = -1)
81 {
82 return _Create(SpawnListThing.Get("tag_" + idTag, (SourceThing.Row s) => s.tag.Contains(idTag)).Select(lv).id, -1, lv);
83 }
84
85 public static Thing CreateBill(int pay, bool tax)
86 {
87 Thing thing = Create(tax ? "bill_tax" : "bill");
88 thing.c_bill = pay;
89 if (tax)
90 {
91 EClass.player.stats.taxBills += thing.c_bill;
93 }
94 else
95 {
96 EClass.player.unpaidBill += thing.c_bill;
97 }
98 return thing;
99 }
100
101 public static Thing CreateBlock(int id, int idMat)
102 {
103 Thing thing = Create(EClass.sources.blocks.rows[id].idThing, idMat);
104 thing.refVal = id;
105 return thing;
106 }
107
108 public static Thing CreateFloor(int id, int idMat, bool platform = false)
109 {
110 _ = EClass.sources.floors.rows[id];
111 Thing thing = Create(platform ? "platform" : "floor", idMat);
112 thing.refVal = id;
113 return thing;
114 }
115
116 public static Thing CreateObj(int id, int idMat)
117 {
118 _ = EClass.sources.objs.rows[id];
119 Thing thing = Create("obj", idMat);
120 thing.refVal = id;
121 return thing;
122 }
123
124 public static Thing CreateMap(string idSource = null, int lv = -1)
125 {
126 if (idSource.IsEmpty())
127 {
129 }
130 if (lv == -1)
131 {
132 lv = 1 + EClass.rnd(EClass.rnd(50) + 1);
133 }
134 return Create("map");
135 }
136
137 public static Thing CreatePlan(int ele)
138 {
139 Thing thing = Create("book_plan");
140 thing.refVal = ele;
141 return thing;
142 }
143
144 public static Thing CreateRecipe(string id)
145 {
146 Thing thing = Create("rp_random");
147 thing.SetStr(53, id);
148 return thing;
149 }
150
151 public static Thing CreateSpellbook(string alias, int num = 1)
152 {
153 return CreateSpellbook(EClass.sources.elements.alias[alias].id, num);
154 }
155
156 public static Thing CreateSpellbook(int ele, int num = 1)
157 {
158 Thing thing = Create("spellbook").SetNum(num);
159 TraitSpellbook.Create(thing, ele);
160 return thing;
161 }
162
163 public static Thing CreateRedBook(string id, int num = 1)
164 {
165 Thing thing = Create("book").SetNum(num);
166 thing.SetStr(53, id);
167 return thing;
168 }
169
170 public static Thing CreateSkillbook(int ele, int num = 1)
171 {
172 Thing thing = Create("book_skill").SetNum(num);
173 thing.refVal = ele;
174 return thing;
175 }
176
177 public static Thing CreateScroll(int ele, int num = 1)
178 {
179 Thing thing = Create("scroll_random").SetNum(num);
180 TraitSpellbook.Create(thing, ele);
181 return thing;
182 }
183
184 public static Thing CreateRod(int ele)
185 {
186 Thing thing = Create("rod");
187 TraitRod.Create(thing, ele);
188 return thing;
189 }
190
191 public static Thing CreatePotion(int ele, int num = 1)
192 {
193 Thing thing = Create("1163").SetNum(num);
194 TraitPotion.Create(thing, ele);
195 return thing;
196 }
197
198 public static Thing CreatePerfume(int ele, int num = 1)
199 {
200 Thing thing = Create("perfume").SetNum(num);
201 TraitPotion.Create(thing, ele);
202 return thing;
203 }
204
205 public static Thing CreateLetter(string idLetter)
206 {
207 Thing thing = Create("letter");
208 thing.SetStr(53, idLetter);
209 return thing;
210 }
211
212 public static Thing CreateCardboardBox(int uidZone = -1)
213 {
214 Thing thing = Create("cardboard_box", new string[5] { "pine", "wood_birch", "wood_acacia", "oak", "cedar" }.RandomItem());
215 thing.things.DestroyAll();
216 Spatial spatial = ((uidZone == -1) ? null : EClass.game.spatials.map.TryGetValue(uidZone));
217 if (spatial != null)
218 {
219 thing.c_idRefName = "sender_header".lang("sender_post".lang(spatial.Name));
220 }
221 return thing;
222 }
223
224 public static Thing CreateTreasure(string id, int lv, TreasureType type = TreasureType.Map)
225 {
226 Thing thing = Create(id, -1, lv);
227 CreateTreasureContent(thing, lv, type, clearContent: true);
228 return thing;
229 }
230
231 public static void CreateTreasureContent(Thing t, int lv, TreasureType type, bool clearContent)
232 {
233 int miracleChance = lv;
234 int num = EClass.curve(lv, 20, 15);
235 bool flag = true;
236 bool flag2 = true;
237 int guaranteedMythical = ((type == TreasureType.BossQuest) ? 1 : 0);
238 ChangeSeed();
239 t.AddEditorTag(EditorTag.PreciousContainer);
240 if (clearContent)
241 {
242 t.things.DestroyAll();
243 }
244 switch (type)
245 {
246 case TreasureType.Map:
247 miracleChance += 50;
248 t.Add("money", EClass.rndHalf(1000 + num * 100));
249 t.Add("money2", EClass.rndHalf(Mathf.Min(3 + num / 10, 10)));
250 t.Add("medal", EClass.rnd(3));
251 break;
252 case TreasureType.BossNefia:
253 case TreasureType.BossQuest:
254 t.Add("money", EClass.rndHalf(500 + num * 50));
255 t.Add("plat", EClass.rndHalf(Mathf.Min(3 + num / 10, 15)));
256 t.Add("rp_random", 1, lv);
257 if (EClass.rnd(5) == 0)
258 {
259 t.Add("medal", EClass.rnd(3));
260 }
261 else if (EClass.rnd(3) == 0)
262 {
263 t.Add("map_treasure", 1, EClass.rndHalf(lv + 10));
264 }
265 else
266 {
267 t.Add("book_skill", 1, lv);
268 }
269 t.c_lockLv /= 2;
270 break;
271 case TreasureType.RandomChest:
272 flag2 = false;
273 miracleChance /= 2;
274 if (miracleChance > 50)
275 {
276 miracleChance = 50;
277 }
278 if (EClass.rnd(2) == 0)
279 {
280 t.Add("money", EClass.rndHalf(10 + num * 25));
281 }
282 else if (EClass.rnd(2) == 0)
283 {
284 t.Add("money2", 1 + EClass.rnd(Mathf.Min(2 + num / 25, 5)));
285 }
286 else
287 {
288 t.Add("plat", 1 + EClass.rnd(Mathf.Min(2 + num / 25, 5)));
289 }
291 {
292 flag = false;
293 break;
294 }
295 if (EClass.rnd(10) == 0)
296 {
297 t.Add("map_treasure", 1, EClass.rndHalf(lv + 10));
298 }
299 if (EClass.rnd(3) == 0)
300 {
301 t.AddCard(Create("rp_random", -1, lv));
302 }
303 if (t.c_lockLv > 0 && EClass.rnd(3) == 0)
304 {
305 t.Add("medal");
306 }
307 break;
308 }
309 if (type == TreasureType.RandomChest && EClass.rnd(2) == 0)
310 {
311 t.AddCard(CreateFromCategory("junk", lv));
312 }
313 else if (EClass.rnd(3) == 0)
314 {
315 t.Add("rp_random", 1, lv);
316 }
317 else if (type != TreasureType.Map && EClass.rnd(2) == 0)
318 {
319 Thing thing = CreateFromCategory("furniture", lv);
320 if (!thing.IsContainer && (t.c_lockLv == 0 || thing.SelfWeight < 10000))
321 {
322 t.AddCard(thing);
323 }
324 }
325 else
326 {
327 t.AddCard(CreateFromCategory("junk", lv));
328 }
329 if (EClass.rnd(3) == 0)
330 {
331 t.Add("book_ancient", 1, lv);
332 }
333 if (t.c_lockLv > 0)
334 {
335 miracleChance += 20 + (int)Mathf.Sqrt(t.c_lockLv * 5);
336 }
337 if (flag)
338 {
339 SetRarity(100);
340 t.AddCard(CreateFromFilter("eq", lv));
341 if (flag2)
342 {
343 SetRarity(20);
344 t.AddCard(CreateFromFilter("eq", lv));
345 }
346 }
347 Rand.SetSeed();
348 static void ChangeSeed()
349 {
352 }
353 void SetRarity(int mtp)
354 {
355 ChangeSeed();
356 Rarity rarity = ((miracleChance * mtp / 100 < EClass.rnd(100)) ? Rarity.Superior : ((EClass.rnd(20) == 0) ? Rarity.Mythical : Rarity.Legendary));
357 if (guaranteedMythical > 0)
358 {
359 guaranteedMythical--;
360 rarity = Rarity.Mythical;
361 }
363 {
364 rarity = rarity
365 });
366 }
367 }
368
369 public static void TryLickChest(Thing chest)
370 {
371 foreach (Chara chara in EClass._map.charas)
372 {
373 if (!chara.HasElement(1412) || chara.Dist(chest) >= 5)
374 {
375 continue;
376 }
377 chara.Say("lick", chara, chest);
378 chest.PlaySound("offering");
379 chest.PlayEffect("mutation");
380 {
381 foreach (Thing thing in chest.things)
382 {
383 thing.TryLickEnchant(chara, msg: false);
384 }
385 break;
386 }
387 }
388 }
389}
EditorTag
Definition: EditorTag.cs:2
Rarity
Definition: Rarity.cs:2
TreasureType
Definition: TreasureType.cs:2
void SetStr(int id, string value=null)
Definition: BaseCard.cs:63
static void Set(CardBlueprint _bp)
CardRow origin
Definition: CardRow.cs:49
string id
Definition: CardRow.cs:7
bool isOrigin
Definition: CardRow.cs:52
bool HasElement(int ele, int req=1)
Definition: Card.cs:5566
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:2957
int c_lockLv
Definition: Card.cs:936
Card AddCard(Card c)
Definition: Card.cs:3006
void AddEditorTag(EditorTag tag)
Definition: Card.cs:2541
Thing SetNum(int a)
Definition: Card.cs:3356
Trait trait
Definition: Card.cs:49
ThingContainer things
Definition: Card.cs:34
int Dist(Card c)
Definition: Card.cs:7235
int c_bill
Definition: Card.cs:1253
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:2997
bool IsContainer
Definition: Card.cs:2025
void Create(string _id, int _idMat=-1, int genLv=-1)
Definition: Card.cs:2660
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6423
Definition: Chara.cs:10
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static int curve(int a, int start, int step, int rate=75)
Definition: EClass.cs:63
static int rnd(int a)
Definition: EClass.cs:58
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static SourceManager sources
Definition: EClass.cs:42
static int rndHalf(int a)
Definition: EClass.cs:82
static Player player
Definition: EClass.cs:12
SpatialManager spatials
Definition: Game.cs:152
new World world
Definition: Game.cs:173
int seed
Definition: Game.cs:197
List< Chara > charas
Definition: Map.cs:81
int seedChest
Definition: Player.cs:867
int taxBills
Definition: Player.cs:831
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:37
SourceZone.Row GetRandomSiteSource()
Definition: Region.cs:180
List< CardRow > rows
Definition: SourceCard.cs:6
Dictionary< string, CardRow > map
Definition: SourceCard.cs:8
SourceMaterial materials
SourceCard cards
SourceObj objs
SourceBlock blocks
SourceCategory categories
SourceElement elements
SourceFloor floors
GlobalSpatialList map
virtual string Name
Definition: Spatial.cs:495
static SpawnList Get(string id, Func< SourceThing.Row, bool > func)
static SpawnList Get(string id, string parent=null, CardFilter filter=null)
Definition: SpawnList.cs:18
CardRow Select(int lv=-1, int levelRange=-1)
Definition: SpawnList.cs:139
void DestroyAll(Func< Thing, bool > funcExclude=null)
static Thing _Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:6
static Thing CreateRawMaterial(SourceMaterial.Row m)
Definition: ThingGen.cs:68
static void TryLickChest(Thing chest)
Definition: ThingGen.cs:369
static Thing CreateTreasure(string id, int lv, TreasureType type=TreasureType.Map)
Definition: ThingGen.cs:224
static Thing CreatePotion(int ele, int num=1)
Definition: ThingGen.cs:191
static Thing CreateFromFilter(string id, int lv=-1)
Definition: ThingGen.cs:63
static Thing CreateMap(string idSource=null, int lv=-1)
Definition: ThingGen.cs:124
static Thing CreatePerfume(int ele, int num=1)
Definition: ThingGen.cs:198
static Thing CreateRod(int ele)
Definition: ThingGen.cs:184
static Thing CreateBlock(int id, int idMat)
Definition: ThingGen.cs:101
static Thing CreateRedBook(string id, int num=1)
Definition: ThingGen.cs:163
static Thing CreateObj(int id, int idMat)
Definition: ThingGen.cs:116
static Thing TestCreate()
Definition: ThingGen.cs:32
static Thing CreateParcel(string idLang=null, params Thing[] things)
Definition: ThingGen.cs:42
static void CreateTreasureContent(Thing t, int lv, TreasureType type, bool clearContent)
Definition: ThingGen.cs:231
static Thing CreateSpellbook(string alias, int num=1)
Definition: ThingGen.cs:151
static Thing CreatePlan(int ele)
Definition: ThingGen.cs:137
static Thing CreateFromTag(string idTag, int lv=-1)
Definition: ThingGen.cs:80
static Thing CreateFloor(int id, int idMat, bool platform=false)
Definition: ThingGen.cs:108
static Thing CreateRecipe(string id)
Definition: ThingGen.cs:144
static Thing CreateSkillbook(int ele, int num=1)
Definition: ThingGen.cs:170
static Thing CreateSpellbook(int ele, int num=1)
Definition: ThingGen.cs:156
static Thing CreateFromCategory(string idCat, int lv=-1)
Definition: ThingGen.cs:75
static Thing CreateLetter(string idLetter)
Definition: ThingGen.cs:205
static Thing CreateScroll(int ele, int num=1)
Definition: ThingGen.cs:177
static Thing CreateBill(int pay, bool tax)
Definition: ThingGen.cs:85
static Thing Create(string id, string idMat, int lv=-1)
Definition: ThingGen.cs:58
static Thing CreateCardboardBox(int uidZone=-1)
Definition: ThingGen.cs:212
static Thing CreateCurrency(int a, string id="money")
Definition: ThingGen.cs:37
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
void TryLickEnchant(Chara c, bool msg=true, Chara tg=null, BodySlot slot=null)
Definition: Thing.cs:1920
override int SelfWeight
Definition: Thing.cs:62
static void Create(Card owner, int ele)
Definition: TraitPotion.cs:15
static void Create(Card owner, int ele)
Definition: TraitRod.cs:76
static void Create(Card owner, int ele)
Region region
Definition: World.cs:23