Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryPurchasing()

virtual bool Terraria.GameContent.UI.CustomCurrencySystem.TryPurchasing ( long price,
List< Item[]> inv,
List< Point > slotCoins,
List< Point > slotsEmpty,
List< Point > slotEmptyBank,
List< Point > slotEmptyBank2,
List< Point > slotEmptyBank3,
List< Point > slotEmptyBank4 )
inlinevirtual

Reimplemented in Terraria.GameContent.UI.CustomCurrencySingleCoin.

Definition at line 65 of file CustomCurrencySystem.cs.

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 {
104 slotsEmpty.Sort(DelegateMethods.CompareYReverse);
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 }
201 slotsEmpty.Sort(DelegateMethods.CompareYReverse);
202 slotEmptyBank.Sort(DelegateMethods.CompareYReverse);
203 slotEmptyBank2.Sort(DelegateMethods.CompareYReverse);
204 slotEmptyBank3.Sort(DelegateMethods.CompareYReverse);
205 slotEmptyBank4.Sort(DelegateMethods.CompareYReverse);
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 }
void Add(TKey key, TValue value)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), Terraria.DelegateMethods.CompareYReverse(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.dictionary, System.item, System.L, System.list, and Microsoft.Xna.Framework.Graphics.Point.