Elin Modding Docs Doc
Loading...
Searching...
No Matches
ShopTransaction.cs
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5// Token: 0x0200055F RID: 1375
6public class ShopTransaction : EClass
7{
8 // Token: 0x0600255A RID: 9562 RVA: 0x000D48B8 File Offset: 0x000D2AB8
9 public void Log()
10 {
11 foreach (ShopTransaction.Item item in this.bought)
12 {
13 Debug.Log(string.Concat(new string[]
14 {
15 "Bought:",
16 item.thing.Name,
17 "/",
18 item.num.ToString(),
19 " x ",
20 item.price.ToString(),
21 " = ",
22 (item.num * item.price).ToString()
23 }));
24 }
25 foreach (ShopTransaction.Item item2 in this.sold)
26 {
27 Debug.Log(string.Concat(new string[]
28 {
29 "Sold:",
30 item2.thing.Name,
31 "/",
32 item2.num.ToString(),
33 " x ",
34 item2.price.ToString(),
35 " = ",
36 (item2.num * item2.price).ToString()
37 }));
38 }
39 }
40
41 // Token: 0x0600255B RID: 9563 RVA: 0x000D4A2C File Offset: 0x000D2C2C
42 public bool HasBought(Thing t)
43 {
44 using (List<ShopTransaction.Item>.Enumerator enumerator = this.bought.GetEnumerator())
45 {
46 while (enumerator.MoveNext())
47 {
48 if (enumerator.Current.thing == t)
49 {
50 return true;
51 }
52 }
53 }
54 return false;
55 }
56
57 // Token: 0x0600255C RID: 9564 RVA: 0x000D4A88 File Offset: 0x000D2C88
58 public bool CanSellBack(Thing t, int num = -1)
59 {
60 if (num == -1)
61 {
62 num = t.Num;
63 }
64 foreach (ShopTransaction.Item item in this.bought)
65 {
66 if (item.thing == t && item.num >= num)
67 {
68 return true;
69 }
70 }
71 return false;
72 }
73
74 // Token: 0x0600255D RID: 9565 RVA: 0x000D4AFC File Offset: 0x000D2CFC
75 public void Process(Thing t, int n, bool sell)
76 {
77 int price = t.GetPrice(this.trader.currency, false, this.trader.priceType, null);
78 int price2 = t.GetPrice(this.trader.currency, true, this.trader.priceType, null);
79 int num = n;
80 Debug.Log(string.Concat(new string[]
81 {
82 sell ? "■Selling:" : "■Buying:",
83 t.Name,
84 "/",
85 n.ToString(),
86 " x ",
87 (sell ? price2 : price).ToString(),
88 " = ",
89 (n * (sell ? price2 : price)).ToString()
90 }));
91 int num2 = sell ? price : price2;
92 List<ShopTransaction.Item> list = sell ? this.bought : this.sold;
93 foreach (ShopTransaction.Item item in list)
94 {
95 if (item.thing.id == t.id && item.price == num2)
96 {
97 int num3 = (item.num >= num) ? num : item.num;
98 num -= num3;
99 item.num -= num3;
100 }
101 if (num == 0)
102 {
103 break;
104 }
105 }
106 list.ForeachReverse(delegate(ShopTransaction.Item i)
107 {
108 if (i.num == 0)
109 {
110 list.Remove(i);
111 }
112 });
113 if (num > 0)
114 {
115 if (sell)
116 {
117 this.sold.Add(new ShopTransaction.Item
118 {
119 thing = t,
120 num = num,
121 price = price2
122 });
123 }
124 else
125 {
126 this.bought.Add(new ShopTransaction.Item
127 {
128 thing = t,
129 num = num,
130 price = price
131 });
132 }
133 }
134 this.Log();
135 }
136
137 // Token: 0x0600255E RID: 9566 RVA: 0x000D4CEC File Offset: 0x000D2EEC
138 public int GetPrice(Thing t, int n, bool sell)
139 {
140 int price = t.GetPrice(this.trader.currency, false, this.trader.priceType, null);
141 int price2 = t.GetPrice(this.trader.currency, true, this.trader.priceType, null);
142 int num = n;
143 int num2 = 0;
144 int num3 = sell ? price : price2;
145 foreach (ShopTransaction.Item item in (sell ? this.bought : this.sold))
146 {
147 if (item.thing.id == t.id && item.price == num3)
148 {
149 int num4 = (item.num >= num) ? num : item.num;
150 num -= num4;
151 num2 += num4 * num3;
152 }
153 if (num == 0)
154 {
155 break;
156 }
157 }
158 return num2 + num * (sell ? price2 : price);
159 }
160
161 // Token: 0x0600255F RID: 9567 RVA: 0x000D4DE8 File Offset: 0x000D2FE8
162 public void OnEndTransaction()
163 {
164 foreach (ShopTransaction.Item item in this.bought)
165 {
166 Debug.Log(item.thing);
167 item.thing.SetInt(101, 0);
168 item.thing.isStolen = false;
169 }
170 if (this.trader.currency != CurrencyType.Money)
171 {
172 ShopTransaction.current = null;
173 return;
174 }
175 int num = 0;
176 foreach (ShopTransaction.Item item2 in this.bought)
177 {
178 for (int i = 0; i < item2.num; i++)
179 {
180 num += (int)Mathf.Sqrt((float)Mathf.Abs(item2.price * 2));
181 }
182 if (item2.thing.trait is TraitDeed)
183 {
184 EClass.player.flags.landDeedBought += item2.num;
185 }
186 }
187 if (num >= 100)
188 {
189 EClass.pc.ModExp(291, num);
190 }
191 Debug.Log("negotiation total:" + num.ToString());
192 num = 0;
193 foreach (ShopTransaction.Item item3 in this.sold)
194 {
195 if (item3.thing.isStolen)
196 {
197 item3.thing.isStolen = false;
198 for (int j = 0; j < item3.num; j++)
199 {
200 num += (int)Mathf.Sqrt((float)item3.price) / 2;
201 }
202 }
203 }
204 Debug.Log("stolen total:" + num.ToString());
205 if (num > 0)
206 {
207 Guild.Thief.AddContribution(num);
208 }
209 ShopTransaction.current = null;
210 }
211
212 // Token: 0x040014E6 RID: 5350
213 public static ShopTransaction current;
214
215 // Token: 0x040014E7 RID: 5351
216 public InvOwner trader;
217
218 // Token: 0x040014E8 RID: 5352
219 public List<ShopTransaction.Item> bought = new List<ShopTransaction.Item>();
220
221 // Token: 0x040014E9 RID: 5353
222 public List<ShopTransaction.Item> sold = new List<ShopTransaction.Item>();
223
224 // Token: 0x02000A93 RID: 2707
225 public class Item
226 {
227 // Token: 0x04002B2E RID: 11054
228 public Thing thing;
229
230 // Token: 0x04002B2F RID: 11055
231 public int num;
232
233 // Token: 0x04002B30 RID: 11056
234 public int price;
235 }
236}
Definition Guild.cs:5
Definition Thing.cs:10