17 return this.width * this.height;
28 return this.grid !=
null;
35 public bool IsMagicChest
46 public int MaxCapacity
50 if (!this.IsMagicChest)
54 return 100 + this.owner.c_containerUpgrade.cap;
59 public void SetOwner(
Card owner)
62 this.width = owner.c_containerSize / 100;
63 this.height = owner.c_containerSize % 100;
72 public void ChangeSize(
int w,
int h)
76 this.owner.c_containerSize = w * 100 + h;
78 Debug.Log(
string.Concat(
new string[]
80 base.Count.ToString(),
82 this.width.ToString(),
84 this.height.ToString(),
86 this.GridSize.ToString()
91 public void RefreshGridRecursive()
93 foreach (
Thing thing
in this)
95 if (thing.IsContainer)
97 thing.things.RefreshGridRecursive();
104 public void RefreshGrid()
106 if (this.GridSize == 0)
110 this.grid =
new List<Thing>(
new Thing[this.GridSize]);
111 foreach (
Thing thing
in this)
113 if (this.ShouldShowOnGrid(thing))
115 if (thing.invX >=
this.GridSize || thing.invX < 0 ||
this.grid[thing.invX] !=
null)
121 this.grid[thing.invX] = thing;
127 int freeGridIndex = this.GetFreeGridIndex();
128 if (freeGridIndex == -1)
132 this.grid[freeGridIndex] = thing2;
133 thing2.invX = freeGridIndex;
139 public void RefreshGrid(
UIMagicChest magic, Window.SaveData data)
141 magic.filteredList.Clear();
143 magic.catCount.Clear();
144 this.grid =
new List<Thing>(
new Thing[this.GridSize]);
145 string lastSearch = magic.lastSearch;
146 bool flag = !lastSearch.IsEmpty();
147 bool flag2 = !magic.idCat.IsEmpty();
148 Window.SaveData.CategoryType category = data.category;
149 bool flag3 = category != Window.SaveData.CategoryType.None;
151 foreach (
Thing thing
in this)
157 case Window.SaveData.CategoryType.Main:
158 text = thing.category.GetRoot().id;
160 case Window.SaveData.CategoryType.Sub:
161 text = thing.category.GetSecondRoot().id;
163 case Window.SaveData.CategoryType.Exact:
164 text = thing.category.id;
167 magic.cats.Add(text);
168 if (magic.catCount.ContainsKey(text))
170 Dictionary<string, int> catCount = magic.catCount;
172 int num = catCount[key];
173 catCount[key] = num + 1;
177 magic.catCount.Add(text, 1);
182 if (thing.tempName ==
null)
184 thing.tempName = thing.GetName(NameStyle.Full, 1).ToLower();
186 if (!thing.tempName.Contains(lastSearch) && !thing.source.GetSearchName(
false).Contains(lastSearch) && !thing.source.GetSearchName(
true).Contains(lastSearch))
191 if (!flag2 || !(text != magic.idCat))
193 magic.filteredList.Add(thing);
196 if (flag2 && !magic.cats.Contains(magic.idCat))
199 this.RefreshGrid(magic, data);
202 magic.pageMax = (magic.filteredList.Count - 1) / this.GridSize;
203 if (magic.page > magic.pageMax)
205 magic.page = magic.pageMax;
207 for (
int i = 0; i < this.GridSize; i++)
209 int num2 = magic.page * this.GridSize + i;
210 if (num2 >= magic.filteredList.Count)
214 Thing thing2 = magic.filteredList[num2];
215 this.grid[i] = thing2;
222 public bool IsOccupied(
int x,
int y)
224 foreach (
Thing thing
in this)
226 if (thing.invY == y && thing.invX == x)
235 public bool ShouldShowOnGrid(
Thing t)
237 if (!this.owner.IsPC)
241 return !t.isEquipped && !t.IsHotItem;
245 public void OnAdd(
Thing t)
251 if (!this.ShouldShowOnGrid(t))
255 int freeGridIndex = this.GetFreeGridIndex();
256 if (freeGridIndex != -1)
258 this.grid[freeGridIndex] = t;
260 t.pos.x = freeGridIndex;
264 public bool IsFull(
int y = 0)
266 if (this.IsMagicChest)
268 return base.Count >= this.MaxCapacity || (this.owner.trait.IsFridge && !this.owner.isOn);
274 if (this.owner.trait.IsSpecialContainer &&
this.owner.parent !=
null)
280 return base.Count >= this.GridSize;
282 return this.GetFreeGridIndex() == -1;
286 public bool IsOverflowing()
288 if (!this.HasGrid || this.IsMagicChest)
293 foreach (
Thing thing
in this)
295 if (thing.invY != 1 && !thing.isEquipped)
300 return num > this.grid.Count;
304 public int GetFreeGridIndex()
306 for (
int i = 0; i < this.grid.Count; i++)
308 if (this.grid[i] ==
null)
317 public void OnRemove(
Thing t)
319 if (!this.HasGrid || t.invY != 0)
323 int num = this.grid.IndexOf(t);
326 this.grid[num] =
null;
331 public void SetSize(
int w,
int h)
333 this.owner.c_containerSize = w * 100 + h;
334 this.SetOwner(this.owner);
338 public Thing TryStack(
Thing target,
int destInvX = -1,
int destInvY = -1)
340 foreach (
Thing thing
in this)
342 if (destInvX == -1 && thing.CanSearchContents)
344 Thing thing2 = thing.things.TryStack(target, destInvX, destInvY);
345 if (thing2 != target)
350 if ((destInvX == -1 || (thing.invX == destInvX && thing.invY == destInvY)) && thing != target && target.TryStackTo(thing))
359 public Thing CanStack(
Thing target,
int destInvX = -1,
int destInvY = -1)
361 foreach (
Thing thing
in this)
363 if (thing != target && target.CanStackTo(thing))
375 CS$<>8__locals1.t = t;
376 CS$<>8__locals1.tryStack = tryStack;
377 CS$<>8__locals1.<>4__this =
this;
379 if (!this.owner.IsPC)
381 this.<GetDest>g__SearchDest|31_0(
this,
true,
true, ref CS$<>8__locals1);
382 return CS$<>8__locals1.d;
384 CS$<>8__locals1.flag = CS$<>8__locals1.t.category.GetRoot().id.ToEnum(
true);
385 if (CS$<>8__locals1.flag == ContainerFlag.none)
387 CS$<>8__locals1.flag = ContainerFlag.other;
391 this.<GetDest>g__TrySearchContainer|31_1(this.owner, ref CS$<>8__locals1);
394 Window.SaveData windowSaveData = b.owner.GetWindowSaveData();
395 int num = ((windowSaveData !=
null) ? windowSaveData.priority : 0) * 10 + (b.owner.IsPC ? 1 : 0);
396 Window.SaveData windowSaveData2 = a.owner.GetWindowSaveData();
397 return num - (((windowSaveData2 !=
null) ? windowSaveData2.priority : 0) * 10 + (a.owner.IsPC ? 1 : 0));
401 this.<GetDest>g__SearchDest|31_0(things,
false,
true, ref CS$<>8__locals1);
402 if (CS$<>8__locals1.d.IsValid)
404 return CS$<>8__locals1.d;
409 this.<GetDest>g__SearchDest|31_0(things2,
true,
false, ref CS$<>8__locals1);
410 if (CS$<>8__locals1.d.IsValid)
412 return CS$<>8__locals1.d;
415 return CS$<>8__locals1.d;
419 public bool IsFull(
Thing t,
bool recursive =
true,
bool tryStack =
true)
421 return this.IsFull(0) && (!tryStack || this.CanStack(t, -1, -1) == t) && (!recursive || !this.GetDest(t, tryStack).IsValid);
428 this.ListCurrency(
id);
431 if (!(thing.id !=
id) && (mat ==
null || thing.material == mat))
435 thing.ModNum(num,
true);
438 if (thing.Num + num >= 0)
440 thing.ModNum(num,
true);
444 thing.ModNum(-thing.Num,
true);
456 thing2.ChangeMaterial(mat);
458 owner.AddThing(thing2,
true, -1, -1).SetNum(num);
464 public void DestroyAll(Func<Thing, bool> funcExclude =
null)
466 this.ForeachReverse(delegate(
Thing t)
468 if (funcExclude !=
null && funcExclude(t))
475 if (this.grid !=
null)
477 for (
int i = 0; i < this.grid.Count; i++)
485 public Thing Find(
int uid)
487 foreach (
Thing thing
in this)
489 if (thing.CanSearchContents)
491 Thing thing2 = thing.things.Find(uid);
497 if (thing.uid == uid)
508 foreach (
Thing thing
in this)
510 if (thing.CanSearchContents)
512 Thing thing2 = thing.things.Find<T>();
518 if (thing.trait is T)
527 public Thing Find(Func<Thing, bool> func,
bool recursive =
true)
529 foreach (
Thing thing
in this)
531 if (recursive && thing.CanSearchContents)
533 Thing thing2 = thing.things.Find(func,
true);
548 public Thing Find(
string id,
string idMat)
550 return this.Find(
id, idMat.IsEmpty() ? -1 :
EClass.sources.materials.alias[idMat].id, -1);
554 public Thing Find(
string id,
int idMat = -1,
int refVal = -1)
556 foreach (
Thing thing
in this)
558 if (thing.CanSearchContents)
560 Thing thing2 = thing.things.Find(
id, idMat, refVal);
566 if (thing.id ==
id && (idMat == -1 || thing.material.id == idMat) && (refVal == -1 || thing.refVal == refVal))
575 public Thing FindStealable()
577 List<Thing> list =
new List<Thing>();
578 foreach (
Thing thing
in this)
580 if (!thing.IsContainer && thing.trait.CanBeStolen)
594 public ThingStack GetThingStack(
string id,
int refVal = -1)
597 bool isOrigin =
EClass.sources.cards.map[id].isOrigin;
598 return this.GetThingStack(
id, s, isOrigin, refVal);
604 foreach (
Thing thing
in this)
606 if (thing.CanSearchContents)
608 thing.things.GetThingStack(
id, s, isOrigin, refVal);
610 if ((refVal == -1 || thing.refVal == refVal) && thing.IsIdentified && (thing.id ==
id || (isOrigin && thing.source._origin ==
id)))
622 bool isOrigin =
EClass.sources.cards.map[id].isOrigin;
623 return this.GetThingStack(
id, s, isOrigin);
629 foreach (
Thing thing
in this)
631 if (thing.CanSearchContents)
633 thing.things.GetThingStack(
id, s, isOrigin);
635 if (thing.id ==
id || (isOrigin && thing.source._origin ==
id))
646 foreach (
Thing thing
in this)
648 if (thing.CanSearchContents)
650 thing.things.GetCurrency(
id, ref sum, mat);
652 if (thing.id ==
id && (mat ==
null || thing.material == mat))
661 public List<Thing> ListCurrency(
string id)
664 this._ListCurrency(
id);
669 private void _ListCurrency(
string id)
671 foreach (
Thing thing
in this)
673 if (thing.CanSearchContents)
675 thing.things._ListCurrency(
id);
685 public List<Thing> List(Func<Thing, bool> func,
bool onlyAccessible =
false)
688 this._List(func, onlyAccessible);
693 public void _List(Func<Thing, bool> func,
bool onlyAccessible =
false)
695 foreach (
Thing thing
in this)
697 if (!onlyAccessible || !(thing.parent is
Card) || (thing.parent as
Card).c_lockLv <= 0)
699 thing.things._List(func, onlyAccessible);
709 public void AddFactory(HashSet<string> hash)
711 foreach (
Thing thing
in this)
713 if (thing.CanSearchContents)
715 thing.things.AddFactory(hash);
717 if (thing.trait.IsFactory)
721 if (thing.trait.ToggleType == ToggleType.Fire && thing.isOn)
729 public void Foreach(Action<Thing> action,
bool onlyAccessible =
true)
731 foreach (
Thing thing
in this)
733 if (!onlyAccessible || thing.CanSearchContents)
735 thing.things.Foreach(action,
true);
742 public void Foreach(Func<Thing, bool> action,
bool onlyAccessible =
true)
744 foreach (
Thing thing
in this)
746 if (!onlyAccessible || thing.CanSearchContents)
748 thing.things.Foreach(action,
true);
759 private void <GetDest>g__SearchDest|31_0(
ThingContainer things,
bool searchEmpty,
bool searchStack, ref
ThingContainer.<>c__DisplayClass31_0 A_4)
761 if (A_4.t.IsContainer && A_4.t.things.Count > 0 && things.owner.IsContainer && !(things.owner.trait is
TraitToolBelt))
765 if (searchStack && A_4.tryStack)
767 Thing thing = things.CanStack(A_4.t, -1, -1);
774 if (searchEmpty && !things.IsFull(0))
780 if (!things.owner.isChara && !(things.owner.parent is
Chara))
783 if (!(((thing2 !=
null) ? thing2.trait :
null) is
TraitToolBelt))
788 A_4.d.container = things.owner;
794 private void <GetDest>g__TrySearchContainer|31_1(
Card c, ref
ThingContainer.<>c__DisplayClass31_0 A_2)
796 foreach (
Thing thing
in c.things)
798 if (thing.CanSearchContents)
800 this.<GetDest>g__TrySearchContainer|31_1(thing, ref A_2);
803 if (c.things ==
this)
807 Window.SaveData windowSaveData = c.GetWindowSaveData();
808 if (windowSaveData !=
null)
810 if (windowSaveData.noRotten && A_2.t.IsDecayed)
814 if (windowSaveData.onlyRottable && A_2.t.trait.Decay == 0)
818 if (windowSaveData.advDistribution)
820 using (HashSet<int>.Enumerator enumerator2 = windowSaveData.cats.GetEnumerator())
822 while (enumerator2.MoveNext())
824 int num = enumerator2.Current;
825 if (A_2.t.category.uid == num)
834 if (!windowSaveData.flag.HasFlag(A_2.flag))
843 internal static int <FindStealable>g__Compare|40_0(
Thing a)
845 return a.SelfWeight + (a.isEquipped ? 10000 : 0);
850 public static List<Thing> listUnassigned =
new List<Thing>();
854 public const int InvYHotbar = 1;
870 public List<Thing> grid;
873 private static List<ThingContainer> _listContainers =
new List<ThingContainer>();
876 private static List<Thing> tempList =
new List<Thing>();
887 return this.stack !=
null || this.container !=
null;
892 public Card container;