Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CustomCurrencySystem.cs
Go to the documentation of this file.
1using System;
5
7
9{
11
12 private long _currencyCap = 999999999L;
13
14 public long CurrencyCap => _currencyCap;
15
16 public void Include(int coin, int howMuchIsItWorth)
17 {
19 }
20
21 public void SetCurrencyCap(long cap)
22 {
24 }
25
26 public virtual long CountCurrency(out bool overFlowing, Item[] inv, params int[] ignoreSlots)
27 {
29 long num = 0L;
30 for (int i = 0; i < inv.Length; i++)
31 {
32 if (!list.Contains(i))
33 {
35 {
36 num += value * inv[i].stack;
37 }
38 if (num >= CurrencyCap)
39 {
40 overFlowing = true;
41 return CurrencyCap;
42 }
43 }
44 }
45 overFlowing = false;
46 return num;
47 }
48
49 public virtual long CombineStacks(out bool overFlowing, params long[] coinCounts)
50 {
51 long num = 0L;
52 foreach (long num2 in coinCounts)
53 {
54 num += num2;
55 if (num >= CurrencyCap)
56 {
57 overFlowing = true;
58 return CurrencyCap;
59 }
60 }
61 overFlowing = false;
62 return num;
63 }
64
66 {
67 long num = price;
69 bool result = true;
70 while (num > 0)
71 {
72 long num2 = 1000000L;
73 for (int i = 0; i < 4; i++)
74 {
75 if (num >= num2)
76 {
77 foreach (Point slotCoin in slotCoins)
78 {
79 if (inv[slotCoin.X][slotCoin.Y].type == 74 - i)
80 {
81 long num3 = num / num2;
82 dictionary[slotCoin] = inv[slotCoin.X][slotCoin.Y].Clone();
83 if (num3 < inv[slotCoin.X][slotCoin.Y].stack)
84 {
85 inv[slotCoin.X][slotCoin.Y].stack -= (int)num3;
86 }
87 else
88 {
89 inv[slotCoin.X][slotCoin.Y].SetDefaults();
91 }
92 num -= num2 * (dictionary[slotCoin].stack - inv[slotCoin.X][slotCoin.Y].stack);
93 }
94 }
95 }
96 num2 /= 100;
97 }
98 if (num <= 0)
99 {
100 continue;
101 }
102 if (slotsEmpty.Count > 0)
103 {
105 Point item = new Point(-1, -1);
106 for (int j = 0; j < inv.Count; j++)
107 {
108 num2 = 10000L;
109 for (int k = 0; k < 3; k++)
110 {
111 if (num >= num2)
112 {
113 foreach (Point slotCoin2 in slotCoins)
114 {
115 if (slotCoin2.X == j && inv[slotCoin2.X][slotCoin2.Y].type == 74 - k && inv[slotCoin2.X][slotCoin2.Y].stack >= 1)
116 {
118 if (j == 1 && slotEmptyBank.Count > 0)
119 {
121 }
122 if (j == 2 && slotEmptyBank2.Count > 0)
123 {
125 }
126 if (j == 3 && slotEmptyBank3.Count > 0)
127 {
129 }
130 if (j == 4 && slotEmptyBank4.Count > 0)
131 {
133 }
134 if (--inv[slotCoin2.X][slotCoin2.Y].stack <= 0)
135 {
136 inv[slotCoin2.X][slotCoin2.Y].SetDefaults();
138 }
139 dictionary[list[0]] = inv[list[0].X][list[0].Y].Clone();
140 inv[list[0].X][list[0].Y].SetDefaults(73 - k);
141 inv[list[0].X][list[0].Y].stack = 100;
142 item = list[0];
143 list.RemoveAt(0);
144 break;
145 }
146 }
147 }
148 if (item.X != -1 || item.Y != -1)
149 {
150 break;
151 }
152 num2 /= 100;
153 }
154 for (int l = 0; l < 2; l++)
155 {
156 if (item.X != -1 || item.Y != -1)
157 {
158 continue;
159 }
160 foreach (Point slotCoin3 in slotCoins)
161 {
162 if (slotCoin3.X == j && inv[slotCoin3.X][slotCoin3.Y].type == 73 + l && inv[slotCoin3.X][slotCoin3.Y].stack >= 1)
163 {
165 if (j == 1 && slotEmptyBank.Count > 0)
166 {
168 }
169 if (j == 2 && slotEmptyBank2.Count > 0)
170 {
172 }
173 if (j == 3 && slotEmptyBank3.Count > 0)
174 {
176 }
177 if (j == 4 && slotEmptyBank4.Count > 0)
178 {
180 }
181 if (--inv[slotCoin3.X][slotCoin3.Y].stack <= 0)
182 {
183 inv[slotCoin3.X][slotCoin3.Y].SetDefaults();
185 }
186 dictionary[list2[0]] = inv[list2[0].X][list2[0].Y].Clone();
187 inv[list2[0].X][list2[0].Y].SetDefaults(72 + l);
188 inv[list2[0].X][list2[0].Y].stack = 100;
189 item = list2[0];
190 list2.RemoveAt(0);
191 break;
192 }
193 }
194 }
195 if (item.X != -1 && item.Y != -1)
196 {
198 break;
199 }
200 }
206 continue;
207 }
209 {
210 inv[item2.Key.X][item2.Key.Y] = item2.Value.Clone();
211 }
212 result = false;
213 break;
214 }
215 return result;
216 }
217
218 public virtual bool Accepts(Item item)
219 {
220 return _valuePerUnit.ContainsKey(item.type);
221 }
222
223 public virtual void DrawSavingsMoney(SpriteBatch sb, string text, float shopx, float shopy, long totalCoins, bool horizontal = false)
224 {
225 }
226
227 public virtual void GetPriceText(string[] lines, ref int currentLine, long price)
228 {
229 }
230
232 {
233 if (valueA.Item2 > valueB.Item2)
234 {
235 return -1;
236 }
237 if (valueA.Item2 == valueB.Item2)
238 {
239 return 0;
240 }
241 return -1;
242 }
243
245 {
247 for (int i = 0; i < inventories.Count; i++)
248 {
249 for (int j = 0; j < inventories[i].Length; j++)
250 {
251 Item item = inventories[i][j];
252 list.Add(new Tuple<Point, Item>(new Point(i, j), item.DeepClone()));
253 }
254 }
255 return list;
256 }
257
259 {
260 foreach (Tuple<Point, Item> item in cache)
261 {
262 inventories[item.Item1.X][item.Item1.Y] = item.Item2;
263 }
264 }
265
267 {
268 int storeValue = item.GetStoreValue();
271 }
272}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static int CompareYReverse(Point a, Point b)
virtual void DrawSavingsMoney(SpriteBatch sb, string text, float shopx, float shopy, long totalCoins, bool horizontal=false)
virtual long CombineStacks(out bool overFlowing, params long[] coinCounts)
void ItemCacheRestore(List< Tuple< Point, Item > > cache, List< Item[]> inventories)
virtual bool TryPurchasing(long price, List< Item[]> inv, List< Point > slotCoins, List< Point > slotsEmpty, List< Point > slotEmptyBank, List< Point > slotEmptyBank2, List< Point > slotEmptyBank3, List< Point > slotEmptyBank4)
int SortByHighest(Tuple< int, int > valueA, Tuple< int, int > valueB)
virtual long CountCurrency(out bool overFlowing, Item[] inv, params int[] ignoreSlots)
virtual void GetPriceText(string[] lines, ref int currentLine, long price)
virtual void GetItemExpectedPrice(Item item, out long calcForSelling, out long calcForBuying)
void Include(int coin, int howMuchIsItWorth)
List< Tuple< Point, Item > > ItemCacheCreate(List< Item[]> inventories)