Elin Decompiled Documentation EA 23.351.2 Nightly
Loading...
Searching...
No Matches
Props.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using Newtonsoft.Json;
4using UnityEngine;
5
6public class Props : EClass
7{
8 public PropSet all = new PropSet();
9
10 public Dictionary<string, PropSet> cardMap = new Dictionary<string, PropSet>();
11
12 public Dictionary<string, PropSetCategory> categoryMap = new Dictionary<string, PropSetCategory>();
13
14 public Dictionary<string, PropSet> raceMap = new Dictionary<string, PropSet>();
15
16 public Dictionary<string, PropSet> workMap = new Dictionary<string, PropSet>();
17
19
20 public List<Thing> things = new List<Thing>();
21
22 public List<Thing> containers = new List<Thing>();
23
24 [JsonProperty]
25 public int maxWeight = 100;
26
27 public int weight;
28
29 public virtual bool IsStocked => false;
30
31 public virtual bool IsRoaming => false;
32
33 public virtual bool IsInstalled => false;
34
35 public virtual PlaceState state => PlaceState.roaming;
36
37 public List<Thing> Things => things;
38
39 public int Count => all.Count;
40
41 public void Init()
42 {
43 if (categoryMap.Count > 0)
44 {
45 return;
46 }
47 foreach (SourceCategory.Row row in EClass.sources.categories.rows)
48 {
49 categoryMap.Add(row.id, new PropSetCategory
50 {
51 source = row
52 });
53 }
54 foreach (PropSetCategory value in categoryMap.Values)
55 {
56 if (value.source.parent != null)
57 {
58 value.parent = categoryMap[value.source.parent.id];
59 }
60 }
61 }
62
63 public void Add(Card t)
64 {
65 if (all.Contains(t))
66 {
67 Debug.Log(t.props);
68 Debug.Log(t.parent);
69 Debug.Log(things.Contains(t) + "/" + cardMap.ContainsKey(t.id));
70 Debug.LogError(t?.ToString() + " alreadin in " + this);
71 return;
72 }
73 if (t.props != null)
74 {
75 t.props.Remove(t);
76 }
77 t.props = this;
78 t.placeState = state;
79 if (t.isChara)
80 {
81 raceMap.GetOrCreate(t.Chara.race.id).Add(t);
82 return;
83 }
84 foreach (Thing thing in t.things)
85 {
86 if (t.placeState != PlaceState.roaming)
87 {
88 EClass._map.Stocked.Add(thing);
89 }
90 }
91 weight += t.Num;
92 all.Add(t);
93 things.Add(t.Thing);
94 cardMap.GetOrCreate(t.id).Add(t);
95 if (t.sourceCard.origin != null)
96 {
97 cardMap.GetOrCreate(t.sourceCard.origin.id).Add(t);
98 }
99 categoryMap[t.category.id].Add(t);
100 if (!t.Thing.source.workTag.IsEmpty())
101 {
102 workMap.GetOrCreate(t.Thing.source.workTag).Add(t);
103 }
104 if (t.IsContainer)
105 {
106 containers.Add(t.Thing);
107 }
108 traits.OnAddCard(t);
109 if (t.isDeconstructing)
110 {
112 }
113 }
114
115 public void Remove(Card t)
116 {
117 t.props = null;
118 t.placeState = PlaceState.roaming;
119 if (t.isChara)
120 {
121 raceMap[t.Chara.race.id].Remove(t);
122 return;
123 }
124 foreach (Thing thing in t.things)
125 {
126 if (thing.props != null)
127 {
128 thing.props.Remove(thing);
129 }
130 }
131 if (!all.Contains(t))
132 {
133 Debug.LogError(t?.ToString() + " isn't in " + this);
134 return;
135 }
136 weight -= t.Num;
137 all.Remove(t);
138 things.RemoveFromEnd(t.Thing);
139 cardMap.TryGetValue(t.id)?.Remove(t);
140 if (t.sourceCard.origin != null)
141 {
142 cardMap.TryGetValue(t.sourceCard.origin.id)?.Remove(t);
143 }
144 categoryMap[t.category.id].Remove(t);
145 if (!t.Thing.source.workTag.IsEmpty())
146 {
147 workMap[t.Thing.source.workTag].Remove(t);
148 }
149 if (t.IsContainer)
150 {
151 containers.RemoveFromEnd(t.Thing);
152 }
154 if (t.isDeconstructing)
155 {
157 }
158 }
159
160 public void OnNumChange(Card c, int a)
161 {
162 if (!c.isChara)
163 {
164 weight += a;
165 categoryMap[c.category.id].OnChangeNum(a);
166 cardMap[c.id].OnChangeNum(a);
167 if (!c.Thing.source.workTag.IsEmpty())
168 {
169 workMap[c.Thing.source.workTag].OnChangeNum(a);
170 }
171 }
172 }
173
175 {
176 if (!(t.parent is Card card))
177 {
178 return false;
179 }
180 if (card.isSale || !card.trait.CanUseContent)
181 {
182 return false;
183 }
184 return !t.c_isImportant;
185 }
186
187 public Thing GetAvailableThing(string id, int idMat)
188 {
189 PropSet propSet = cardMap.TryGetValue(id);
190 if (propSet == null)
191 {
192 return null;
193 }
194 foreach (Card item in propSet)
195 {
196 if (item.idMaterial == idMat)
197 {
198 return item as Thing;
199 }
200 }
201 return null;
202 }
203
205 {
206 string id = ing.id;
207 int idMat = -1;
208 string tag = (ing.tag.IsEmpty() ? null : ing.tag);
209 ThingStack stack = new ThingStack
210 {
211 val = idMat
212 };
213 _ = EClass.pc.pos.cell.room;
214 if (ing.useCat)
215 {
216 FindCat(id);
217 foreach (string item in ing.idOther)
218 {
219 FindCat(item);
220 }
221 }
222 else
223 {
224 Find(id);
225 foreach (string item2 in ing.idOther)
226 {
227 Find(item2);
228 }
229 }
230 if (ing.ingType == Recipe.IngType.CreativeFood)
231 {
232 FindAnyFood();
233 }
234 return stack;
235 void Find(string text)
236 {
237 bool isOrigin = EClass.sources.cards.map[text].isOrigin;
238 EClass.pc.things.Foreach(delegate(Thing t)
239 {
240 if (!t.isEquipped && (!(t.id != text) || (isOrigin && t.source._origin == text)))
241 {
242 TryAdd(t);
243 }
244 });
246 {
247 foreach (Card item3 in cardMap.GetOrCreate(text))
248 {
249 if (!(item3.parent is Thing thing) || (thing.c_lockLv == 0 && thing.trait.CanUseContent))
250 {
251 TryAdd(item3.Thing);
252 }
253 }
254 }
255 }
256 void FindAnyFood()
257 {
258 EClass.pc.things.Foreach(delegate(Thing t)
259 {
260 if (!t.isEquipped)
261 {
262 TryAdd2(t);
263 }
264 });
266 {
267 foreach (Card item4 in all)
268 {
269 if (!(item4.parent is Thing thing) || (thing.c_lockLv == 0 && thing.trait.CanUseContent))
270 {
271 TryAdd2(item4.Thing);
272 }
273 }
274 }
275 }
276 void FindCat(string key)
277 {
279 EClass.pc.things.Foreach(delegate(Thing t)
280 {
281 if (!t.isEquipped && t.category.IsChildOf(cat.id) && !t.IsExcludeFromCraft(ing) && !stack.list.Contains(t))
282 {
283 stack.Add(t);
284 }
285 });
287 {
288 foreach (PropSetCategory value in categoryMap.Values)
289 {
290 if (value.source.IsChildOf(cat))
291 {
292 foreach (Card item5 in value)
293 {
294 Thing thing = item5.Thing;
295 Card obj = thing.parent as Card;
296 if (obj != null && obj.c_lockLv == 0 && !thing.IsExcludeFromCraft(ing) && !stack.list.Contains(thing))
297 {
298 stack.Add(thing);
299 }
300 }
301 }
302 }
303 }
304 }
305 void TryAdd(Thing t)
306 {
307 if ((tag == null || t.Thing.material.tag.Contains(tag)) && (idMat == -1 || t.material.id == idMat) && !t.IsExcludeFromCraft(ing) && !stack.list.Contains(t))
308 {
309 stack.Add(t);
310 }
311 }
312 void TryAdd2(Thing t)
313 {
314 if (t.HasElement(10) && !(t.trait is TraitFoodFishSlice) && !t.category.IsChildOf("seasoning") && !t.category.IsChildOf("meal") && !t.category.IsChildOf("drink") && !t.IsExcludeFromCraft(ing) && !stack.list.Contains(t))
315 {
316 stack.Add(t.Thing);
317 }
318 }
319 }
320
322 {
323 List<Thing> list = new List<Thing>();
324 foreach (Thing thing in Things)
325 {
326 if (thing.category.IsChildOf(cat))
327 {
328 list.Add(thing);
329 }
330 }
331 return list;
332 }
333
334 public Dictionary<string, ThingStack> ListThingStacksInCategory(SourceCategory.Row cat)
335 {
336 Dictionary<string, ThingStack> dictionary = new Dictionary<string, ThingStack>();
337 foreach (Thing thing in Things)
338 {
339 ListThingStacksInCategory(cat, dictionary, thing);
340 }
341 return dictionary;
342 }
343
344 private void ListThingStacksInCategory(SourceCategory.Row cat, Dictionary<string, ThingStack> stacks, Thing t)
345 {
346 if (EClass.sources.categories.map[t.source.category].IsChildOf(cat))
347 {
348 ThingStack thingStack = stacks.TryGetValue(t.id);
349 if (thingStack == null)
350 {
351 thingStack = new ThingStack();
352 stacks.Add(t.id, thingStack);
353 }
354 thingStack.count += t.Num;
355 thingStack.list.Add(t);
356 }
357 }
358
359 public Thing Find<T>() where T : Trait
360 {
361 foreach (Thing thing in Things)
362 {
363 if (thing.trait is T)
364 {
365 return thing;
366 }
367 }
368 return null;
369 }
370
372 {
373 foreach (Thing thing in Things)
374 {
375 if (thing.trait is T && !thing.things.IsFull())
376 {
377 return thing;
378 }
379 }
380 return null;
381 }
382
383 public Thing FindEmptyContainer<T>(Thing target) where T : Trait
384 {
385 foreach (Thing thing in Things)
386 {
387 if (thing.trait is T && !thing.things.IsFull(target))
388 {
389 return thing;
390 }
391 }
392 return null;
393 }
394
395 public Thing Find(int uid)
396 {
397 foreach (Thing thing in Things)
398 {
399 if (thing.uid == uid)
400 {
401 return thing;
402 }
403 }
404 return null;
405 }
406
407 public Thing FindShared(string id)
408 {
409 return Find(id, -1, -1, shared: true);
410 }
411
412 public Thing Find(string id, string idMat)
413 {
414 return Find(id, idMat.IsEmpty() ? (-1) : EClass.sources.materials.alias[idMat].id);
415 }
416
417 public Thing Find(string id, int idMat = -1, int refVal = -1, bool shared = false)
418 {
419 PropSet propSet = cardMap.TryGetValue(id);
420 if (propSet != null)
421 {
422 foreach (Card item in propSet)
423 {
424 if ((!shared || item.parent is Thing { IsSharedContainer: not false }) && (idMat == -1 || item.material.id == idMat) && (refVal == -1 || item.refVal == refVal))
425 {
426 return item as Thing;
427 }
428 }
429 }
430 return null;
431 }
432
433 public int GetNum(string id, bool onlyShared = false)
434 {
435 int num = 0;
436 foreach (Card item in cardMap.GetOrCreate(id))
437 {
438 if (!onlyShared || (item.parentThing != null && item.parentThing.IsSharedContainer))
439 {
440 num += item.Num;
441 }
442 }
443 return num;
444 }
445
446 public static int GetNumStockedAndRoaming(string id)
447 {
448 return EClass._map.Stocked.cardMap.GetOrCreate(id).num + EClass._map.Roaming.GetNum(id);
449 }
450
451 public void Validate()
452 {
453 foreach (KeyValuePair<string, PropSet> item in cardMap)
454 {
455 int num = 0;
456 foreach (Card item2 in item.Value)
457 {
458 num += item2.Num;
459 }
460 if (num != item.Value.num)
461 {
462 Debug.LogError("prop num:" + item.Key + " " + item.Value.num + "/" + num);
463 }
464 }
465 }
466}
PlaceState
Definition: PlaceState.cs:2
StockSearchMode
void Add(Act a, string s="")
Definition: ActPlan.cs:11
Definition: Card.cs:11
Props props
Definition: Card.cs:52
virtual Chara Chara
Definition: Card.cs:2122
string id
Definition: Card.cs:36
bool IsExcludeFromCraft(Recipe.Ingredient ing)
Definition: Card.cs:2662
SourceMaterial.Row material
Definition: Card.cs:2103
int c_lockLv
Definition: Card.cs:991
ICardParent parent
Definition: Card.cs:56
Point pos
Definition: Card.cs:60
int uid
Definition: Card.cs:125
Trait trait
Definition: Card.cs:54
bool c_isImportant
Definition: Card.cs:1051
ThingContainer things
Definition: Card.cs:39
virtual bool isChara
Definition: Card.cs:2135
virtual Thing Thing
Definition: Card.cs:2110
int Num
Definition: Card.cs:161
SourceCategory.Row category
Definition: Card.cs:2101
bool HasElement(int ele, bool includeNagative=false)
Definition: Card.cs:6383
Room room
Definition: Cell.cs:122
SourceRace.Row race
Definition: Chara.cs:468
bool enable
Definition: CoreDebug.cs:302
Definition: EClass.cs:6
static Zone _zone
Definition: EClass.cs:21
static Map _map
Definition: EClass.cs:19
static SourceManager sources
Definition: EClass.cs:43
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
PropsRoaming Roaming
Definition: Map.cs:130
PropsManager props
Definition: Map.cs:94
PropsStocked Stocked
Definition: Map.cs:126
Cell cell
Definition: Point.cs:51
SourceCategory.Row source
new void Add(Card c)
Definition: PropSet.cs:7
new void Remove(Card c)
Definition: PropSet.cs:13
List< Card > deconstructing
Definition: PropsManager.cs:12
Definition: Props.cs:7
virtual PlaceState state
Definition: Props.cs:35
virtual bool IsInstalled
Definition: Props.cs:33
int weight
Definition: Props.cs:27
TraitManager traits
Definition: Props.cs:18
int Count
Definition: Props.cs:39
List< Thing > ListThingsInCategory(SourceCategory.Row cat)
Definition: Props.cs:321
List< Thing > Things
Definition: Props.cs:37
Dictionary< string, PropSet > raceMap
Definition: Props.cs:14
void Add(Card t)
Definition: Props.cs:63
int maxWeight
Definition: Props.cs:25
List< Thing > things
Definition: Props.cs:20
void OnNumChange(Card c, int a)
Definition: Props.cs:160
Dictionary< string, ThingStack > ListThingStacksInCategory(SourceCategory.Row cat)
Definition: Props.cs:334
Thing Find(int uid)
Definition: Props.cs:395
Dictionary< string, PropSet > cardMap
Definition: Props.cs:10
void Validate()
Definition: Props.cs:451
Thing Find(string id, string idMat)
Definition: Props.cs:412
void Remove(Card t)
Definition: Props.cs:115
void Init()
Definition: Props.cs:41
List< Thing > containers
Definition: Props.cs:22
virtual bool IsRoaming
Definition: Props.cs:31
static int GetNumStockedAndRoaming(string id)
Definition: Props.cs:446
Dictionary< string, PropSet > workMap
Definition: Props.cs:16
Thing GetAvailableThing(string id, int idMat)
Definition: Props.cs:187
void ListThingStacksInCategory(SourceCategory.Row cat, Dictionary< string, ThingStack > stacks, Thing t)
Definition: Props.cs:344
Thing Find< T >()
Definition: Props.cs:359
int GetNum(string id, bool onlyShared=false)
Definition: Props.cs:433
virtual bool IsStocked
Definition: Props.cs:29
Thing FindEmptyContainer< T >()
Definition: Props.cs:371
Thing Find(string id, int idMat=-1, int refVal=-1, bool shared=false)
Definition: Props.cs:417
Dictionary< string, PropSetCategory > categoryMap
Definition: Props.cs:12
PropSet all
Definition: Props.cs:8
Thing FindShared(string id)
Definition: Props.cs:407
bool ShouldListAsResource(Thing t)
Definition: Props.cs:174
ThingStack ListThingStack(Recipe.Ingredient ing, StockSearchMode searchMode)
Definition: Props.cs:204
Definition: Recipe.cs:7
IngType
Definition: Recipe.cs:15
Dictionary< string, CardRow > map
Definition: SourceCard.cs:9
SourceMaterial materials
SourceCard cards
SourceCategory categories
void Foreach(Action< Thing > action, bool onlyAccessible=true)
bool IsFull(int y=0)
void Add(Thing t)
Definition: ThingStack.cs:13
List< Thing > list
Definition: ThingStack.cs:5
Definition: Thing.cs:8
SourceThing.Row source
Definition: Thing.cs:11
bool isEquipped
Definition: Thing.cs:17
void OnRemoveCard(Card c)
Definition: TraitManager.cs:38
void OnAddCard(Card c)
Definition: TraitManager.cs:16
Definition: Trait.cs:7
bool IsPCFaction
Definition: Zone.cs:480