Elin Decompiled Documentation EA 23.193 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 != 0)
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.Remove(t.Thing);
139 cardMap[t.id].Remove(t);
140 if (t.sourceCard.origin != null)
141 {
142 cardMap[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.Remove(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 id2 = 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(id2);
217 foreach (string item in ing.idOther)
218 {
219 FindCat(item);
220 }
221 }
222 else
223 {
224 Find(id2);
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 stack.list.Sort(UIList.SortMode.ByCategory);
235 return stack;
236 void Find(string id)
237 {
238 bool isOrigin = EClass.sources.cards.map[id].isOrigin;
239 EClass.pc.things.Foreach(delegate(Thing t)
240 {
241 if (!t.isEquipped && (!(t.id != id) || (isOrigin && t.source._origin == id)))
242 {
243 TryAdd(t);
244 }
245 });
247 {
248 foreach (Card item3 in cardMap.GetOrCreate(id))
249 {
250 if (!(item3.parent is Thing thing2) || (thing2.c_lockLv == 0 && thing2.trait.CanUseContent))
251 {
252 TryAdd(item3.Thing);
253 }
254 }
255 }
256 }
257 void FindAnyFood()
258 {
259 EClass.pc.things.Foreach(delegate(Thing t)
260 {
261 if (!t.isEquipped)
262 {
263 TryAdd(t);
264 }
265 });
267 {
268 foreach (Card item4 in all)
269 {
270 if (!(item4.parent is Thing thing) || (thing.c_lockLv == 0 && thing.trait.CanUseContent))
271 {
272 TryAdd(item4.Thing);
273 }
274 }
275 }
276 }
277 void FindCat(string id)
278 {
280 EClass.pc.things.Foreach(delegate(Thing t)
281 {
282 if (!t.isEquipped && t.category.IsChildOf(cat.id) && !t.IsExcludeFromCraft(ing))
283 {
284 stack.Add(t);
285 }
286 });
288 {
289 foreach (Thing thing3 in things)
290 {
291 Card obj = thing3.parent as Card;
292 if (obj != null && obj.c_lockLv == 0 && thing3.category.IsChildOf(cat.id) && !thing3.IsExcludeFromCraft(ing))
293 {
294 stack.Add(thing3);
295 }
296 }
297 }
298 }
299 void TryAdd(Thing t)
300 {
301 if ((tag == null || t.Thing.material.tag.Contains(tag)) && (idMat == -1 || t.material.id == idMat) && !t.IsExcludeFromCraft(ing))
302 {
303 stack.Add(t.Thing);
304 }
305 }
306 void TryAdd(Thing t)
307 {
308 if (t.HasElement(10) && !(t.trait is TraitFoodFishSlice) && !t.category.IsChildOf("seasoning") && !t.category.IsChildOf("meal") && !t.IsExcludeFromCraft(ing) && !stack.list.Contains(t))
309 {
310 stack.Add(t.Thing);
311 }
312 }
313 }
314
316 {
317 List<Thing> list = new List<Thing>();
318 foreach (Thing thing in Things)
319 {
320 if (thing.category.IsChildOf(cat))
321 {
322 list.Add(thing);
323 }
324 }
325 return list;
326 }
327
328 public Dictionary<string, ThingStack> ListThingStacksInCategory(SourceCategory.Row cat)
329 {
330 Dictionary<string, ThingStack> dictionary = new Dictionary<string, ThingStack>();
331 foreach (Thing thing in Things)
332 {
333 ListThingStacksInCategory(cat, dictionary, thing);
334 }
335 return dictionary;
336 }
337
338 private void ListThingStacksInCategory(SourceCategory.Row cat, Dictionary<string, ThingStack> stacks, Thing t)
339 {
340 if (EClass.sources.categories.map[t.source.category].IsChildOf(cat))
341 {
342 ThingStack thingStack = stacks.TryGetValue(t.id);
343 if (thingStack == null)
344 {
345 thingStack = new ThingStack();
346 stacks.Add(t.id, thingStack);
347 }
348 thingStack.count += t.Num;
349 thingStack.list.Add(t);
350 }
351 }
352
353 public Thing Find<T>() where T : Trait
354 {
355 foreach (Thing thing in Things)
356 {
357 if (thing.trait is T)
358 {
359 return thing;
360 }
361 }
362 return null;
363 }
364
366 {
367 foreach (Thing thing in Things)
368 {
369 if (thing.trait is T && !thing.things.IsFull())
370 {
371 return thing;
372 }
373 }
374 return null;
375 }
376
377 public Thing FindEmptyContainer<T>(Thing target) where T : Trait
378 {
379 foreach (Thing thing in Things)
380 {
381 if (thing.trait is T && !thing.things.IsFull(target))
382 {
383 return thing;
384 }
385 }
386 return null;
387 }
388
389 public Thing Find(int uid)
390 {
391 foreach (Thing thing in Things)
392 {
393 if (thing.uid == uid)
394 {
395 return thing;
396 }
397 }
398 return null;
399 }
400
401 public Thing FindShared(string id)
402 {
403 return Find(id, -1, -1, shared: true);
404 }
405
406 public Thing Find(string id, string idMat)
407 {
408 return Find(id, idMat.IsEmpty() ? (-1) : EClass.sources.materials.alias[idMat].id);
409 }
410
411 public Thing Find(string id, int idMat = -1, int refVal = -1, bool shared = false)
412 {
413 PropSet propSet = cardMap.TryGetValue(id);
414 if (propSet != null)
415 {
416 foreach (Card item in propSet)
417 {
418 if ((!shared || item.parent is Thing { IsSharedContainer: not false }) && (idMat == -1 || item.material.id == idMat) && (refVal == -1 || item.refVal == refVal))
419 {
420 return item as Thing;
421 }
422 }
423 }
424 return null;
425 }
426
427 public int GetNum(string id, bool onlyShared = false)
428 {
429 int num = 0;
430 foreach (Card item in cardMap.GetOrCreate(id))
431 {
432 if (!onlyShared || (item.parentThing != null && item.parentThing.IsSharedContainer))
433 {
434 num += item.Num;
435 }
436 }
437 return num;
438 }
439
440 public static int GetNumStockedAndRoaming(string id)
441 {
442 return EClass._map.Stocked.cardMap.GetOrCreate(id).num + EClass._map.Roaming.GetNum(id);
443 }
444
445 public void Validate()
446 {
447 foreach (KeyValuePair<string, PropSet> item in cardMap)
448 {
449 int num = 0;
450 foreach (Card item2 in item.Value)
451 {
452 num += item2.Num;
453 }
454 if (num != item.Value.num)
455 {
456 Debug.LogError("prop num:" + item.Key + " " + item.Value.num + "/" + num);
457 }
458 }
459 }
460}
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:49
virtual Chara Chara
Definition: Card.cs:2032
string id
Definition: Card.cs:33
bool IsExcludeFromCraft(Recipe.Ingredient ing)
Definition: Card.cs:2491
bool HasElement(int ele, int req=1)
Definition: Card.cs:5683
SourceMaterial.Row material
Definition: Card.cs:2013
int c_lockLv
Definition: Card.cs:938
ICardParent parent
Definition: Card.cs:53
Point pos
Definition: Card.cs:57
int uid
Definition: Card.cs:120
Trait trait
Definition: Card.cs:51
bool c_isImportant
Definition: Card.cs:998
ThingContainer things
Definition: Card.cs:36
virtual bool isChara
Definition: Card.cs:2045
virtual Thing Thing
Definition: Card.cs:2020
int Num
Definition: Card.cs:156
SourceCategory.Row category
Definition: Card.cs:2011
Room room
Definition: Cell.cs:102
SourceRace.Row race
Definition: Chara.cs:462
bool enable
Definition: CoreDebug.cs:286
Definition: EClass.cs:5
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static SourceManager sources
Definition: EClass.cs:42
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
PropsRoaming Roaming
Definition: Map.cs:125
PropsManager props
Definition: Map.cs:91
PropsStocked Stocked
Definition: Map.cs:121
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:315
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:328
Thing Find(int uid)
Definition: Props.cs:389
Dictionary< string, PropSet > cardMap
Definition: Props.cs:10
void Validate()
Definition: Props.cs:445
Thing Find(string id, string idMat)
Definition: Props.cs:406
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:440
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:338
Thing Find< T >()
Definition: Props.cs:353
int GetNum(string id, bool onlyShared=false)
Definition: Props.cs:427
virtual bool IsStocked
Definition: Props.cs:29
Thing FindEmptyContainer< T >()
Definition: Props.cs:365
Thing Find(string id, int idMat=-1, int refVal=-1, bool shared=false)
Definition: Props.cs:411
Dictionary< string, PropSetCategory > categoryMap
Definition: Props.cs:12
PropSet all
Definition: Props.cs:8
Thing FindShared(string id)
Definition: Props.cs:401
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:8
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
Definition: UIList.cs:9
SortMode
Definition: UIList.cs:27
bool IsPCFaction
Definition: Zone.cs:468