Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ShopTransaction.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3
4public class ShopTransaction : EClass
5{
6 public class Item
7 {
8 public Thing thing;
9
10 public int num;
11
12 public int price;
13 }
14
15 public static ShopTransaction current;
16
18
19 public List<Item> bought = new List<Item>();
20
21 public List<Item> sold = new List<Item>();
22
23 public void Log()
24 {
25 foreach (Item item3 in bought)
26 {
27 Debug.Log("Bought:" + item3.thing.Name + "/" + item3.num + " x " + item3.price + " = " + item3.num * item3.price);
28 }
29 foreach (Item item4 in sold)
30 {
31 Debug.Log("Sold:" + item4.thing.Name + "/" + item4.num + " x " + item4.price + " = " + item4.num * item4.price);
32 }
33 }
34
35 public bool HasBought(Thing t)
36 {
37 foreach (Item item in bought)
38 {
39 if (item.thing == t)
40 {
41 return true;
42 }
43 }
44 return false;
45 }
46
47 public bool CanSellBack(Thing t, int num = -1)
48 {
49 if (num == -1)
50 {
51 num = t.Num;
52 }
53 foreach (Item item in bought)
54 {
55 if (item.thing == t && item.num >= num)
56 {
57 return true;
58 }
59 }
60 return false;
61 }
62
63 public void Process(Thing t, int n, bool sell)
64 {
65 int price = t.GetPrice(trader.currency, sell: false, trader.priceType);
66 int price2 = t.GetPrice(trader.currency, sell: true, trader.priceType);
67 int num = n;
68 Debug.Log((sell ? "■Selling:" : "■Buying:") + t.Name + "/" + n + " x " + (sell ? price2 : price) + " = " + n * (sell ? price2 : price));
69 int num2 = (sell ? price : price2);
70 List<Item> list = (sell ? bought : sold);
71 foreach (Item item in list)
72 {
73 if (item.thing.id == t.id && item.price == num2)
74 {
75 int num3 = ((item.num >= num) ? num : item.num);
76 num -= num3;
77 item.num -= num3;
78 }
79 if (num == 0)
80 {
81 break;
82 }
83 }
84 list.ForeachReverse(delegate(Item i)
85 {
86 if (i.num == 0)
87 {
88 list.Remove(i);
89 }
90 });
91 if (num > 0)
92 {
93 if (sell)
94 {
95 sold.Add(new Item
96 {
97 thing = t,
98 num = num,
99 price = price2
100 });
101 }
102 else
103 {
104 bought.Add(new Item
105 {
106 thing = t,
107 num = num,
108 price = price
109 });
110 }
111 }
112 Log();
113 }
114
115 public int GetPrice(Thing t, int n, bool sell)
116 {
117 long num = t.GetPrice(trader.currency, sell: false, trader.priceType);
118 long num2 = t.GetPrice(trader.currency, sell: true, trader.priceType);
119 int num3 = n;
120 long num4 = 0L;
121 long num5 = (sell ? num : num2);
122 foreach (Item item in sell ? bought : sold)
123 {
124 if (item.thing.id == t.id && item.price == num5)
125 {
126 int num6 = ((item.num >= num3) ? num3 : item.num);
127 num3 -= num6;
128 num4 += num6 * num5;
129 }
130 if (num3 == 0)
131 {
132 break;
133 }
134 }
135 num4 += (sell ? num2 : num) * num3;
136 if (num4 >= int.MaxValue || num4 <= -2147483647)
137 {
138 return -1;
139 }
140 return (int)num4;
141 }
142
143 public void OnEndTransaction()
144 {
145 Thing thing = trader.owner.things.Find("chest_merchant");
146 if (thing != null)
147 {
148 thing.c_lockLv = 1;
149 }
150 foreach (Item item4 in bought)
151 {
152 Debug.Log(item4.thing);
153 item4.thing.SetInt(101);
154 item4.thing.isStolen = false;
155 }
156 if (trader.currency != CurrencyType.Money)
157 {
158 current = null;
159 return;
160 }
161 int num = 0;
162 foreach (Item item5 in bought)
163 {
164 for (int i = 0; i < item5.num; i++)
165 {
166 num += (int)Mathf.Sqrt(Mathf.Abs(item5.price * 5));
167 }
168 if (item5.thing.trait is TraitDeed)
169 {
170 EClass.player.flags.landDeedBought += item5.num;
171 }
172 }
173 if (num >= 10)
174 {
175 EClass.pc.ModExp(291, num);
176 }
177 Debug.Log("negotiation total:" + num);
178 num = 0;
179 foreach (Item item6 in sold)
180 {
181 if (item6.thing.isStolen)
182 {
183 item6.thing.isStolen = false;
184 for (int j = 0; j < item6.num; j++)
185 {
186 num += (int)Mathf.Sqrt(item6.price) / 2;
187 }
188 }
189 }
190 Debug.Log("stolen total:" + num);
191 if (num > 0)
192 {
194 }
195 current = null;
196 }
197}
CurrencyType
Definition: CurrencyType.cs:2
void SetInt(int id, int value=0)
Definition: BaseCard.cs:39
virtual int GetPrice(CurrencyType currency=CurrencyType.Money, bool sell=false, PriceType priceType=PriceType.Default, Chara c=null)
Definition: Card.cs:6449
string Name
Definition: Card.cs:2013
Trait trait
Definition: Card.cs:49
ThingContainer things
Definition: Card.cs:34
bool isStolen
Definition: Card.cs:826
void ModExp(string alias, int a)
Definition: Card.cs:2508
int Num
Definition: Card.cs:154
Definition: EClass.cs:5
static Chara pc
Definition: EClass.cs:14
void AddContribution(int a)
Definition: FACTION.cs:316
Definition: Guild.cs:2
static GuildThief Thief
Definition: Guild.cs:27
Card owner
Definition: InvOwner.cs:538
CurrencyType currency
Definition: InvOwner.cs:532
PriceType priceType
Definition: InvOwner.cs:534
bool HasBought(Thing t)
List< Item > sold
static ShopTransaction current
bool CanSellBack(Thing t, int num=-1)
List< Item > bought
int GetPrice(Thing t, int n, bool sell)
void Process(Thing t, int n, bool sell)
Thing Find(int uid)
Definition: Thing.cs:8