Elin Decompiled Documentation EA 23.309 Nightly Patch 1
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 CreateDeco(int id, int idMat)
117 {
118 _ = EClass.sources.decos.rows[id];
119 Thing thing = Create("deco", idMat);
120 thing.refVal = id;
121 return thing;
122 }
123
124 public static Thing CreateObj(int id, int idMat)
125 {
126 _ = EClass.sources.objs.rows[id];
127 Thing thing = Create("obj", idMat);
128 thing.refVal = id;
129 return thing;
130 }
131
132 public static Thing CreateMap(string idSource = null, int lv = -1)
133 {
134 if (idSource.IsEmpty())
135 {
137 }
138 if (lv == -1)
139 {
140 lv = 1 + EClass.rnd(EClass.rnd(50) + 1);
141 }
142 return Create("map");
143 }
144
145 public static Thing CreatePlan(int ele)
146 {
147 Thing thing = Create("book_plan");
148 thing.refVal = ele;
149 return thing;
150 }
151
152 public static Thing CreateRecipe(string id)
153 {
154 Thing thing = Create("rp_random");
155 thing.SetStr(53, id);
156 return thing;
157 }
158
159 public static Thing CreateSpellbook(string alias, int num = 1)
160 {
161 return CreateSpellbook(EClass.sources.elements.alias[alias].id, num);
162 }
163
164 public static Thing CreateSpellbook(int ele, int num = 1, int charge = -1)
165 {
166 Thing thing = Create("spellbook").SetNum(num);
167 TraitSpellbook.Create(thing, ele);
168 if (charge != -1)
169 {
170 thing.SetCharge(charge);
171 }
172 return thing;
173 }
174
175 public static Thing CreateRedBook(string id, int num = 1)
176 {
177 Thing thing = Create("book").SetNum(num);
178 thing.SetStr(53, id);
179 thing.idSkin = (thing.trait as TraitBook).Item.skin;
180 return thing;
181 }
182
183 public static Thing CreateSkillbook(int ele, int num = 1)
184 {
185 Thing thing = Create("book_skill").SetNum(num);
186 thing.refVal = ele;
187 return thing;
188 }
189
190 public static Thing CreateScroll(int ele, int num = 1)
191 {
192 Thing thing = Create("scroll_random").SetNum(num);
193 TraitSpellbook.Create(thing, ele);
194 return thing;
195 }
196
198 {
200 }
201
203 {
204 Thing thing = Create("1084");
205 thing.c_idRefName = EClass.game.religions.Healing.id;
206 return thing;
207 }
208
209 public static Thing CreateRune(int ele, int v, bool free = false)
210 {
211 Thing thing = Create(free ? "rune_free" : "rune");
212 thing.refVal = ele;
213 thing.encLV = v;
214 return thing;
215 }
216
217 public static Thing CreateRod(int ele, int charge = -1)
218 {
219 Thing thing = Create("rod");
220 TraitRod.Create(thing, ele, charge);
221 return thing;
222 }
223
224 public static Thing CreatePotion(int ele, int num = 1)
225 {
226 Thing thing = Create("1163").SetNum(num);
227 TraitPotion.Create(thing, ele);
228 return thing;
229 }
230
231 public static Thing CreatePerfume(int ele, int num = 1)
232 {
233 Thing thing = Create("perfume").SetNum(num);
234 TraitPotion.Create(thing, ele);
235 return thing;
236 }
237
238 public static Thing CreateCassette(int id)
239 {
240 Thing thing = Create("856");
241 thing.refVal = id;
242 return thing;
243 }
244
245 public static Thing CreateLetter(string idLetter)
246 {
247 Thing thing = Create("letter");
248 thing.SetStr(53, idLetter);
249 return thing;
250 }
251
252 public static Thing CreateCardboardBox(int uidZone = -1)
253 {
254 Thing thing = Create("cardboard_box", new string[5] { "pine", "wood_birch", "wood_acacia", "oak", "cedar" }.RandomItem());
255 thing.things.DestroyAll();
256 Spatial spatial = ((uidZone == -1) ? null : EClass.game.spatials.map.TryGetValue(uidZone));
257 if (spatial != null)
258 {
259 thing.c_idRefName = "sender_header".lang("sender_post".lang(spatial.Name));
260 }
261 return thing;
262 }
263
264 public static Thing CreateTreasure(string id, int lv, TreasureType type = TreasureType.Map)
265 {
266 Thing thing = Create(id, -1, lv);
267 CreateTreasureContent(thing, lv, type, clearContent: true);
268 return thing;
269 }
270
271 public static void CreateTreasureContent(Thing t, int lv, TreasureType type, bool clearContent)
272 {
273 int miracleChance = lv;
274 int num = EClass.curve(lv, 20, 15);
275 bool flag = true;
276 bool flag2 = true;
277 int guaranteedMythical = ((type == TreasureType.BossQuest) ? 1 : 0);
278 ChangeSeed();
279 t.AddEditorTag(EditorTag.PreciousContainer);
280 if (clearContent)
281 {
282 t.things.DestroyAll();
283 }
284 switch (type)
285 {
286 case TreasureType.Map:
287 miracleChance += 50;
288 t.Add("money", EClass.rndHalf(1000 + num * 100));
289 t.Add("money2", EClass.rndHalf(Mathf.Min(3 + num / 10, 10)));
290 t.Add("medal", EClass.rnd(3));
291 break;
292 case TreasureType.BossNefia:
293 case TreasureType.BossQuest:
294 t.Add("money", EClass.rndHalf(500 + num * 50));
295 t.Add("plat", EClass.rndHalf(Mathf.Min(3 + num / 10, 15)));
296 t.Add("rp_random", 1, lv);
297 if (EClass.rnd(5) == 0)
298 {
299 t.Add("medal", EClass.rnd(3));
300 }
301 else if (EClass.rnd(3) == 0)
302 {
303 t.Add("map_treasure", 1, EClass.rndHalf(lv + 10));
304 }
305 else
306 {
307 t.Add("book_skill", 1, lv);
308 }
309 t.c_lockLv /= 2;
310 break;
311 case TreasureType.SurvivalRaid:
312 t.Add("plat", EClass.rndHalf(Mathf.Min(3 + num / 10, 15)));
313 t.Add("money2", EClass.rndHalf(Mathf.Min(3 + num / 10, 10)));
314 t.Add("medal", EClass.rndHalf(8));
315 t.Add("book_skill", 1, lv);
316 t.Add("book_skill", 1, lv);
317 t.c_lockLv /= 3;
318 break;
319 case TreasureType.RandomChest:
320 flag2 = false;
321 miracleChance /= 2;
322 if (miracleChance > 50)
323 {
324 miracleChance = 50;
325 }
326 if (EClass.rnd(2) == 0)
327 {
328 t.Add("money", EClass.rndHalf(10 + num * 25));
329 }
330 else if (EClass.rnd(2) == 0)
331 {
332 t.Add("money2", 1 + EClass.rnd(Mathf.Min(2 + num / 25, 5)));
333 }
334 else
335 {
336 t.Add("plat", 1 + EClass.rnd(Mathf.Min(2 + num / 25, 5)));
337 }
339 {
340 flag = false;
341 break;
342 }
343 if (EClass.rnd(10) == 0)
344 {
345 t.Add("map_treasure", 1, EClass.rndHalf(lv + 10));
346 }
347 if (EClass.rnd(3) == 0)
348 {
349 t.AddCard(Create("rp_random", -1, lv));
350 }
351 if (t.c_lockLv > 0 && EClass.rnd(3) == 0)
352 {
353 t.Add("medal");
354 }
355 break;
356 }
357 if (type == TreasureType.RandomChest && EClass.rnd(2) == 0)
358 {
359 t.AddCard(CreateFromCategory("junk", lv));
360 }
361 else if (EClass.rnd(3) == 0)
362 {
363 t.Add("rp_random", 1, lv);
364 }
365 else if (type != TreasureType.Map && EClass.rnd(2) == 0)
366 {
367 Thing thing = CreateFromCategory("furniture", lv);
368 if (!thing.IsContainer && (t.c_lockLv == 0 || thing.SelfWeight < 10000))
369 {
370 t.AddCard(thing);
371 }
372 }
373 else
374 {
375 t.AddCard(CreateFromCategory("junk", lv));
376 }
377 if (EClass.rnd(3) == 0)
378 {
379 t.Add("book_ancient", 1, lv);
380 }
381 if (t.c_lockLv > 0)
382 {
383 miracleChance += 20 + (int)Mathf.Sqrt(t.c_lockLv * 5);
384 }
385 if (flag)
386 {
387 SetRarity(100);
388 t.AddCard(CreateFromFilter("eq", lv));
389 if (flag2)
390 {
391 SetRarity(20);
392 t.AddCard(CreateFromFilter("eq", lv));
393 }
394 }
395 Rand.SetSeed();
396 static void ChangeSeed()
397 {
400 }
401 void SetRarity(int mtp)
402 {
403 ChangeSeed();
404 Rarity rarity = ((miracleChance * mtp / 100 < EClass.rnd(100)) ? Rarity.Superior : ((EClass.rnd(20) == 0) ? Rarity.Mythical : Rarity.Legendary));
405 if (guaranteedMythical > 0)
406 {
407 guaranteedMythical--;
408 rarity = Rarity.Mythical;
409 }
411 {
412 rarity = rarity
413 });
414 }
415 }
416
417 public static void TryLickChest(Thing chest)
418 {
419 foreach (Chara chara in EClass._map.charas)
420 {
421 if (!chara.HasElement(1412) || chara.Dist(chest) >= 5)
422 {
423 continue;
424 }
425 chara.Say("lick", chara, chest);
426 chest.PlaySound("offering");
427 chest.PlayEffect("mutation");
428 {
429 foreach (Thing thing in chest.things)
430 {
431 thing.TryLickEnchant(chara, msg: false);
432 }
433 break;
434 }
435 }
436 }
437}
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=null)
CardRow origin
Definition: CardRow.cs:49
string id
Definition: CardRow.cs:7
bool isOrigin
Definition: CardRow.cs:52
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:3131
int c_lockLv
Definition: Card.cs:991
Card AddCard(Card c)
Definition: Card.cs:3180
void SetCharge(int a)
Definition: Card.cs:4040
void AddEditorTag(EditorTag tag)
Definition: Card.cs:2659
Thing SetNum(int a)
Definition: Card.cs:3591
Trait trait
Definition: Card.cs:54
ThingContainer things
Definition: Card.cs:39
int Dist(Card c)
Definition: Card.cs:8034
int c_bill
Definition: Card.cs:1321
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:3171
bool IsContainer
Definition: Card.cs:2141
bool HasElement(int ele, bool includeNagative=false)
Definition: Card.cs:6223
void Create(string _id, int _idMat=-1, int genLv=-1)
Definition: Card.cs:2827
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7159
Definition: Chara.cs:10
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static int curve(long _a, int start, int step, int rate=75)
Definition: EClass.cs:69
static Zone _zone
Definition: EClass.cs:21
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static int rndHalf(int a)
Definition: EClass.cs:97
static Player player
Definition: EClass.cs:13
ReligionManager religions
Definition: Game.cs:159
SpatialManager spatials
Definition: Game.cs:153
new World world
Definition: Game.cs:177
int seed
Definition: Game.cs:201
List< Chara > charas
Definition: Map.cs:81
int seedChest
Definition: Player.cs:1011
int taxBills
Definition: Player.cs:975
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:44
SourceZone.Row GetRandomSiteSource()
Definition: Region.cs:200
override string id
ReligionHealing Healing
List< CardRow > rows
Definition: SourceCard.cs:7
Dictionary< string, CardRow > map
Definition: SourceCard.cs:9
SourceMaterial materials
SourceCard cards
SourceObj objs
SourceDeco decos
SourceBlock blocks
SourceCategory categories
SourceElement elements
SourceFloor floors
GlobalSpatialList map
virtual string Name
Definition: Spatial.cs:509
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:417
static Thing CreateRune(int ele, int v, bool free=false)
Definition: ThingGen.cs:209
static Thing CreateTreasure(string id, int lv, TreasureType type=TreasureType.Map)
Definition: ThingGen.cs:264
static Thing CreatePotion(int ele, int num=1)
Definition: ThingGen.cs:224
static Thing CreateFromFilter(string id, int lv=-1)
Definition: ThingGen.cs:63
static Thing CreateMap(string idSource=null, int lv=-1)
Definition: ThingGen.cs:132
static Thing CreatePerfume(int ele, int num=1)
Definition: ThingGen.cs:231
static Thing CreateBlock(int id, int idMat)
Definition: ThingGen.cs:101
static Thing CreateRedBook(string id, int num=1)
Definition: ThingGen.cs:175
static Thing CreateObj(int id, int idMat)
Definition: ThingGen.cs:124
static Thing CreateDeco(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:271
static Thing CreateCassette(int id)
Definition: ThingGen.cs:238
static Thing CreateSpellbook(string alias, int num=1)
Definition: ThingGen.cs:159
static Thing CreatePlan(int ele)
Definition: ThingGen.cs:145
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:152
static Thing CreateSkillbook(int ele, int num=1)
Definition: ThingGen.cs:183
static Thing CreateSpellbook(int ele, int num=1, int charge=-1)
Definition: ThingGen.cs:164
static Thing Createジュアさまの薄い本()
Definition: ThingGen.cs:197
static Thing CreateFromCategory(string idCat, int lv=-1)
Definition: ThingGen.cs:75
static Thing CreateLetter(string idLetter)
Definition: ThingGen.cs:245
static Thing CreateScroll(int ele, int num=1)
Definition: ThingGen.cs:190
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 CreateUsuihon(Religion faith)
Definition: ThingGen.cs:202
static Thing CreateCardboardBox(int uidZone=-1)
Definition: ThingGen.cs:252
static Thing CreateCurrency(int a, string id="money")
Definition: ThingGen.cs:37
static Thing CreateRod(int ele, int charge=-1)
Definition: ThingGen.cs:217
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:2035
override int SelfWeight
Definition: Thing.cs:64
static void Create(Card owner, int ele)
Definition: TraitPotion.cs:15
static void Create(Card owner, int ele, int charge=-1)
Definition: TraitRod.cs:76
static void Create(Card owner, int ele)
Region region
Definition: World.cs:23