Elin Decompiled Documentation EA 23.102 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 stack.list.Sort(UIList.SortMode.ByCategory);
222 return stack;
223 }
224 Find(id2);
225 foreach (string item2 in ing.idOther)
226 {
227 Find(item2);
228 }
229 stack.list.Sort(UIList.SortMode.ByCategory);
230 return stack;
231 void Find(string id)
232 {
233 bool isOrigin = EClass.sources.cards.map[id].isOrigin;
234 EClass.pc.things.Foreach(delegate(Thing t)
235 {
236 if (!t.isEquipped && (!(t.id != id) || (isOrigin && t.source._origin == id)))
237 {
238 TryAdd(t);
239 }
240 });
242 {
243 foreach (Card item3 in cardMap.GetOrCreate(id))
244 {
245 if (!(item3.parent is Thing thing) || (thing.c_lockLv == 0 && thing.trait.CanUseContent))
246 {
247 TryAdd(item3.Thing);
248 }
249 }
250 }
251 }
252 void FindCat(string id)
253 {
255 EClass.pc.things.Foreach(delegate(Thing t)
256 {
257 if (!t.isEquipped && t.category.IsChildOf(cat.id) && !t.IsExcludeFromCraft())
258 {
259 stack.Add(t);
260 }
261 });
263 {
264 foreach (Thing thing2 in things)
265 {
266 Card obj = thing2.parent as Card;
267 if (obj != null && obj.c_lockLv == 0 && thing2.category.IsChildOf(cat.id) && !thing2.IsExcludeFromCraft())
268 {
269 stack.Add(thing2);
270 }
271 }
272 }
273 }
274 void TryAdd(Thing t)
275 {
276 if ((tag == null || t.Thing.material.tag.Contains(tag)) && (idMat == -1 || t.material.id == idMat) && !t.IsExcludeFromCraft())
277 {
278 stack.Add(t.Thing);
279 }
280 }
281 }
282
284 {
285 List<Thing> list = new List<Thing>();
286 foreach (Thing thing in Things)
287 {
288 if (thing.category.IsChildOf(cat))
289 {
290 list.Add(thing);
291 }
292 }
293 return list;
294 }
295
296 public Dictionary<string, ThingStack> ListThingStacksInCategory(SourceCategory.Row cat)
297 {
298 Dictionary<string, ThingStack> dictionary = new Dictionary<string, ThingStack>();
299 foreach (Thing thing in Things)
300 {
301 ListThingStacksInCategory(cat, dictionary, thing);
302 }
303 return dictionary;
304 }
305
306 private void ListThingStacksInCategory(SourceCategory.Row cat, Dictionary<string, ThingStack> stacks, Thing t)
307 {
308 if (EClass.sources.categories.map[t.source.category].IsChildOf(cat))
309 {
310 ThingStack thingStack = stacks.TryGetValue(t.id);
311 if (thingStack == null)
312 {
313 thingStack = new ThingStack();
314 stacks.Add(t.id, thingStack);
315 }
316 thingStack.count += t.Num;
317 thingStack.list.Add(t);
318 }
319 }
320
321 public Thing Find<T>() where T : Trait
322 {
323 foreach (Thing thing in Things)
324 {
325 if (thing.trait is T)
326 {
327 return thing;
328 }
329 }
330 return null;
331 }
332
334 {
335 foreach (Thing thing in Things)
336 {
337 if (thing.trait is T && !thing.things.IsFull())
338 {
339 return thing;
340 }
341 }
342 return null;
343 }
344
345 public Thing FindEmptyContainer<T>(Thing target) where T : Trait
346 {
347 foreach (Thing thing in Things)
348 {
349 if (thing.trait is T && !thing.things.IsFull(target))
350 {
351 return thing;
352 }
353 }
354 return null;
355 }
356
357 public Thing Find(int uid)
358 {
359 foreach (Thing thing in Things)
360 {
361 if (thing.uid == uid)
362 {
363 return thing;
364 }
365 }
366 return null;
367 }
368
369 public Thing FindShared(string id)
370 {
371 return Find(id, -1, -1, shared: true);
372 }
373
374 public Thing Find(string id, string idMat)
375 {
376 return Find(id, idMat.IsEmpty() ? (-1) : EClass.sources.materials.alias[idMat].id);
377 }
378
379 public Thing Find(string id, int idMat = -1, int refVal = -1, bool shared = false)
380 {
381 PropSet propSet = cardMap.TryGetValue(id);
382 if (propSet != null)
383 {
384 foreach (Card item in propSet)
385 {
386 if ((!shared || item.parent is Thing { IsSharedContainer: not false }) && (idMat == -1 || item.material.id == idMat) && (refVal == -1 || item.refVal == refVal))
387 {
388 return item as Thing;
389 }
390 }
391 }
392 return null;
393 }
394
395 public int GetNum(string id, bool onlyShared = false)
396 {
397 int num = 0;
398 foreach (Card item in cardMap.GetOrCreate(id))
399 {
400 if (!onlyShared || (item.parentThing != null && item.parentThing.IsSharedContainer))
401 {
402 num += item.Num;
403 }
404 }
405 return num;
406 }
407
408 public static int GetNumStockedAndRoaming(string id)
409 {
410 return EClass._map.Stocked.cardMap.GetOrCreate(id).num + EClass._map.Roaming.GetNum(id);
411 }
412
413 public void Validate()
414 {
415 foreach (KeyValuePair<string, PropSet> item in cardMap)
416 {
417 int num = 0;
418 foreach (Card item2 in item.Value)
419 {
420 num += item2.Num;
421 }
422 if (num != item.Value.num)
423 {
424 Debug.LogError("prop num:" + item.Key + " " + item.Value.num + "/" + num);
425 }
426 }
427 }
428}
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:47
virtual Chara Chara
Definition: Card.cs:1946
string id
Definition: Card.cs:31
SourceMaterial.Row material
Definition: Card.cs:1927
bool IsExcludeFromCraft()
Definition: Card.cs:2389
int c_lockLv
Definition: Card.cs:924
ICardParent parent
Definition: Card.cs:51
Point pos
Definition: Card.cs:55
int uid
Definition: Card.cs:118
Trait trait
Definition: Card.cs:49
bool c_isImportant
Definition: Card.cs:984
ThingContainer things
Definition: Card.cs:34
virtual bool isChara
Definition: Card.cs:1959
virtual Thing Thing
Definition: Card.cs:1934
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:2878
int Num
Definition: Card.cs:154
SourceCategory.Row category
Definition: Card.cs:1925
Room room
Definition: Cell.cs:102
SourceRace.Row race
Definition: Chara.cs:449
bool enable
Definition: CoreDebug.cs:285
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:283
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:296
Thing Find(int uid)
Definition: Props.cs:357
Dictionary< string, PropSet > cardMap
Definition: Props.cs:10
void Validate()
Definition: Props.cs:413
Thing Find(string id, string idMat)
Definition: Props.cs:374
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:408
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:306
Thing Find< T >()
Definition: Props.cs:321
int GetNum(string id, bool onlyShared=false)
Definition: Props.cs:395
virtual bool IsStocked
Definition: Props.cs:29
Thing FindEmptyContainer< T >()
Definition: Props.cs:333
Thing Find(string id, int idMat=-1, int refVal=-1, bool shared=false)
Definition: Props.cs:379
Dictionary< string, PropSetCategory > categoryMap
Definition: Props.cs:12
PropSet all
Definition: Props.cs:8
Thing FindShared(string id)
Definition: Props.cs:369
bool ShouldListAsResource(Thing t)
Definition: Props.cs:174
ThingStack ListThingStack(Recipe.Ingredient ing, StockSearchMode searchMode)
Definition: Props.cs:204
Definition: Recipe.cs:7
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)
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:464