Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ItemShopSellbackHelper.cs
Go to the documentation of this file.
2
4
6{
7 private class ItemMemo
8 {
9 public readonly int itemNetID;
10
11 public readonly int itemPrefix;
12
13 public int stack;
14
15 public ItemMemo(Item item)
16 {
17 itemNetID = item.netID;
18 itemPrefix = item.prefix;
19 stack = item.stack;
20 }
21
22 public bool Matches(Item item)
23 {
24 if (item.netID == itemNetID)
25 {
26 return item.prefix == itemPrefix;
27 }
28 return false;
29 }
30 }
31
33
34 public void Add(Item item)
35 {
36 ItemMemo itemMemo = _memos.Find((ItemMemo x) => x.Matches(item));
37 if (itemMemo != null)
38 {
39 itemMemo.stack += item.stack;
40 }
41 else
42 {
43 _memos.Add(new ItemMemo(item));
44 }
45 }
46
47 public void Clear()
48 {
49 _memos.Clear();
50 }
51
52 public int GetAmount(Item item)
53 {
54 return _memos.Find((ItemMemo x) => x.Matches(item))?.stack ?? 0;
55 }
56
57 public int Remove(Item item)
58 {
59 ItemMemo itemMemo = _memos.Find((ItemMemo x) => x.Matches(item));
60 if (itemMemo == null)
61 {
62 return 0;
63 }
64 int stack = itemMemo.stack;
65 itemMemo.stack -= item.stack;
66 if (itemMemo.stack <= 0)
67 {
69 return stack;
70 }
71 return stack - itemMemo.stack;
72 }
73}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)