summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XShopPurchaseView.cs
blob: 92ad4dcd8400e3f942b9e9682bbf827c2db47a87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
using System;
using UILib;
using XMainClient.UI;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XShopPurchaseView : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "Common/PurchaseFrame";
			}
		}

		public IXUISprite mItemIcon;

		public IXUILabel mItemName;

		public IXUILabel mItemOwnNum;

		public IXUILabel mItemCanBuyNum;

		public IXUIButton mMinusTen;

		public IXUIButton mMinusOne;

		public IXUIButton mAddOne;

		public IXUIButton mAddTen;

		public IXUIButton mClose;

		public IXUIButton mBlock;

		public IXUILabel mCurBuyNum;

		public IXUISprite mMoneyIcon;

		public IXUILabel mMoneyNum;

		public IXUIButton mDoBuy;

		private XNormalShopDocument _doc = null;

		private int mItemId = 0;

		private int mMoneyType = 0;

		private int mWantBuyNum = 0;

		private int mMaxCanBuyNum = 0;

		private int mMaxConstrainNum = 0;

		private int mPrice = 0;

		private XNormalShopGoods mBuyGoods;

		private static readonly int MAX_BUYNUM_ONE_TIME = 9999;

		protected override void Init()
		{
			base.Init();
			this._doc = XDocuments.GetSpecificDocument<XNormalShopDocument>(XNormalShopDocument.uuID);
			this.mItemIcon = (base.PanelObject.transform.Find("Item/Icon").GetComponent("XUISprite") as IXUISprite);
			this.mItemName = (base.PanelObject.transform.Find("Item/Name").GetComponent("XUILabel") as IXUILabel);
			this.mItemOwnNum = (base.PanelObject.transform.Find("OP/own").GetComponent("XUILabel") as IXUILabel);
			this.mItemCanBuyNum = (base.PanelObject.transform.Find("OP/canbuy").GetComponent("XUILabel") as IXUILabel);
			this.mMinusTen = (base.PanelObject.transform.Find("OP/minus10").GetComponent("XUIButton") as IXUIButton);
			this.mMinusTen.ID = 10UL;
			this.mMinusOne = (base.PanelObject.transform.Find("OP/minus1").GetComponent("XUIButton") as IXUIButton);
			this.mMinusOne.ID = 1UL;
			this.mAddOne = (base.PanelObject.transform.Find("OP/add1").GetComponent("XUIButton") as IXUIButton);
			this.mAddOne.ID = 1UL;
			this.mAddTen = (base.PanelObject.transform.Find("OP/add10").GetComponent("XUIButton") as IXUIButton);
			this.mAddTen.ID = 10UL;
			this.mClose = (base.PanelObject.transform.Find("OP/close").GetComponent("XUIButton") as IXUIButton);
			this.mBlock = (base.PanelObject.transform.Find("block").GetComponent("XUIButton") as IXUIButton);
			this.mCurBuyNum = (base.PanelObject.transform.Find("buynum").GetComponent("XUILabel") as IXUILabel);
			this.mMoneyIcon = (base.PanelObject.transform.Find("moneysign").GetComponent("XUISprite") as IXUISprite);
			this.mMoneyNum = (base.PanelObject.transform.Find("moneynum").GetComponent("XUILabel") as IXUILabel);
			this.mDoBuy = (base.PanelObject.transform.Find("OP/OK").GetComponent("XUIButton") as IXUIButton);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.mMinusTen.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnMinusItem));
			this.mMinusOne.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnMinusItem));
			this.mAddTen.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnAddItem));
			this.mAddOne.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnAddItem));
			this.mDoBuy.RegisterClickEventHandler(new ButtonClickEventHandler(this.DoPurchase));
			this.mClose.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClosePurchaseView));
			this.mBlock.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClosePurchaseView));
		}

		protected override void OnShow()
		{
			base.OnShow();
			this._doc.PurchaseView = this;
		}

		public override void OnUnload()
		{
			base.OnUnload();
		}

		public int GetMaxConstrainNum(int itemid, ulong moneynum, int price)
		{
			int num = (int)moneynum / price;
			int num2 = XShopPurchaseView.MAX_BUYNUM_ONE_TIME;
			ShopTable.RowData dataById = XNormalShopDocument.GetDataById((uint)this.mBuyGoods.item.uid);
			bool flag = dataById.DailyCountCondition > 0 || dataById.CountCondition > 0u || dataById.WeekCountCondition > 0;
			if (flag)
			{
				bool flag2 = dataById.CountCondition > 0u;
				if (flag2)
				{
					num2 = (int)(dataById.CountCondition - (uint)this.mBuyGoods.soldNum);
				}
				else
				{
					bool flag3 = dataById.DailyCountCondition > 0;
					if (flag3)
					{
						num2 = (int)dataById.DailyCountCondition - this.mBuyGoods.soldNum;
					}
					else
					{
						num2 = (int)((uint)dataById.WeekCountCondition - this.mBuyGoods.weeklyBuyCount);
					}
				}
				num2 = ((num2 >= 0) ? num2 : 0);
			}
			return num2;
		}

		public int CalMaxCanBuyNum(int itemid, ulong moneynum, int price)
		{
			ShopTable.RowData dataById = XNormalShopDocument.GetDataById((uint)this.mBuyGoods.item.uid);
			bool flag = dataById.Benefit[0] == 2u;
			if (flag)
			{
				price = price * (int)dataById.Benefit[1] / 100;
			}
			int num = (int)moneynum / price;
			this.mMaxConstrainNum = this.GetMaxConstrainNum(itemid, moneynum, price);
			return (num < this.mMaxConstrainNum) ? num : this.mMaxConstrainNum;
		}

		public void OnBuyItem(XNormalShopGoods goods)
		{
			base.SetVisible(true);
			this.mBuyGoods = goods;
			this.OnBuyItem(goods.item.itemID, goods.priceType, goods.priceValue);
		}

		public int GetNeedMoney()
		{
			ShopTable.RowData dataById = XNormalShopDocument.GetDataById((uint)this.mBuyGoods.item.uid);
			bool flag = dataById.Benefit[0] == 2u;
			int result;
			if (flag)
			{
				result = this.mWantBuyNum * this.mPrice * (int)dataById.Benefit[1] / 100;
			}
			else
			{
				result = this.mWantBuyNum * this.mPrice;
			}
			return result;
		}

		public void OnBuyItem(int itemid, int moneyid, int price)
		{
			this.mItemId = itemid;
			this.mWantBuyNum = 1;
			this.mMoneyType = moneyid;
			XSingleton<XItemDrawerMgr>.singleton.DrawItem(base.PanelObject.transform.Find("Item").gameObject, this.mBuyGoods.item);
			ulong itemCount = XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemCount(moneyid);
			ulong num = XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemCount(itemid);
			bool flag = num == 0UL;
			if (flag)
			{
				XFashionDocument specificDocument = XDocuments.GetSpecificDocument<XFashionDocument>(XFashionDocument.uuID);
				num = (ulong)((long)specificDocument.GetFashionCount(itemid));
			}
			this.mMaxCanBuyNum = this.CalMaxCanBuyNum(itemid, itemCount, price);
			this.mPrice = price;
			int maxConstrainNum = this.GetMaxConstrainNum(itemid, itemCount, price);
			this.mItemOwnNum.SetText(num.ToString());
			this.mCurBuyNum.SetText(this.mWantBuyNum.ToString());
			bool flag2 = maxConstrainNum == XShopPurchaseView.MAX_BUYNUM_ONE_TIME;
			if (flag2)
			{
				this.mItemCanBuyNum.SetVisible(false);
			}
			else
			{
				this.mItemCanBuyNum.SetVisible(true);
				this.mItemCanBuyNum.SetText(maxConstrainNum.ToString());
			}
			bool flag3 = !this._doc.IsMoneyOrItemEnough(this.mMoneyType, this.GetNeedMoney());
			if (flag3)
			{
				this.mMoneyNum.SetText("[fe0000]" + this.GetNeedMoney().ToString() + "[-]");
			}
			else
			{
				this.mMoneyNum.SetText(this.GetNeedMoney().ToString());
			}
			string itemSmallIcon = XBagDocument.GetItemSmallIcon(moneyid, 0u);
			this.mMoneyIcon.SetSprite(itemSmallIcon);
		}

		public bool OnAddItem(IXUIButton sp)
		{
			int num = this.mWantBuyNum;
			int num2 = (int)sp.ID;
			bool flag = this.mWantBuyNum + num2 >= this.mMaxCanBuyNum;
			if (flag)
			{
				this.mWantBuyNum = ((this.mMaxCanBuyNum == 0) ? 1 : this.mMaxCanBuyNum);
			}
			else
			{
				this.mWantBuyNum += num2;
			}
			bool flag2 = this.mWantBuyNum >= XShopPurchaseView.MAX_BUYNUM_ONE_TIME;
			if (flag2)
			{
				this.mWantBuyNum = ((XShopPurchaseView.MAX_BUYNUM_ONE_TIME == 0) ? 1 : XShopPurchaseView.MAX_BUYNUM_ONE_TIME);
			}
			this.mCurBuyNum.SetText(this.mWantBuyNum.ToString());
			bool flag3 = !this._doc.IsMoneyOrItemEnough(this.mMoneyType, this.GetNeedMoney());
			if (flag3)
			{
				this.mMoneyNum.SetText("[fe0000]" + this.GetNeedMoney().ToString() + "[-]");
			}
			else
			{
				this.mMoneyNum.SetText(this.GetNeedMoney().ToString());
			}
			bool flag4 = num == this.mWantBuyNum;
			if (flag4)
			{
				bool flag5 = this.mWantBuyNum == this.mMaxConstrainNum;
				if (flag5)
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("ERR_BUY_LIMIT"), "fece00");
				}
				else
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("ERR_REINFORCE_LACKMONEY"), "fece00");
				}
			}
			return true;
		}

		public bool OnMinusItem(IXUIButton sp)
		{
			int num = (int)sp.ID;
			bool flag = this.mWantBuyNum - num <= 1;
			if (flag)
			{
				this.mWantBuyNum = 1;
			}
			else
			{
				this.mWantBuyNum -= num;
			}
			this.mCurBuyNum.SetText(this.mWantBuyNum.ToString());
			bool flag2 = !this._doc.IsMoneyOrItemEnough(this.mMoneyType, this.GetNeedMoney());
			if (flag2)
			{
				this.mMoneyNum.SetText("[fe0000]" + this.GetNeedMoney().ToString() + "[-]");
			}
			else
			{
				this.mMoneyNum.SetText(this.GetNeedMoney().ToString());
			}
			return true;
		}

		public bool DoPurchase(IXUIButton sp)
		{
			bool flag = this._doc.IsExchangeMoney(this.mMoneyType) && !this._doc.IsMoneyOrItemEnough(this.mMoneyType, this.GetNeedMoney());
			bool result;
			if (flag)
			{
				this._doc.ProcessItemOrMoneyNotEnough(this.mMoneyType);
				base.SetVisible(false);
				result = false;
			}
			else
			{
				bool flag2 = this.mWantBuyNum == 0;
				if (flag2)
				{
					base.SetVisible(false);
					result = false;
				}
				else
				{
					this._doc.DoBuyItem(this.mBuyGoods, (uint)this.mWantBuyNum);
					base.SetVisible(false);
					result = true;
				}
			}
			return result;
		}

		public bool OnClosePurchaseView(IXUIButton sp)
		{
			base.SetVisible(false);
			return true;
		}
	}
}