summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/Guild/XGuildWeeklyBountyDocument.cs
blob: 28994f9f877aebe150c01d709e0e67ac608c1020 (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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
using System;
using System.Collections.Generic;
using KKSG;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XGuildWeeklyBountyDocument : XDocComponent
	{
		public override uint ID
		{
			get
			{
				return XGuildWeeklyBountyDocument.uuID;
			}
		}

		public static XGuildWeeklyBountyDocument Doc
		{
			get
			{
				return XSingleton<XGame>.singleton.Doc.GetXComponent(XGuildWeeklyBountyDocument.uuID) as XGuildWeeklyBountyDocument;
			}
		}

		public List<GuildWeeklyTaskInfo> CurGuildWeeklyTaskList
		{
			get
			{
				return this._curGuildWeeklyTaskList;
			}
		}

		public List<uint> RewardedBoxList
		{
			get
			{
				return this._rewardedBoxList;
			}
		}

		public uint WeeklyScore
		{
			get
			{
				return this._weeklyScore;
			}
		}

		public uint WeeklyAskedHelpNum
		{
			get
			{
				return this._weeklyAskedHelpNum;
			}
		}

		public List<uint> ChestValueList
		{
			get
			{
				return this._chestValueList;
			}
		}

		public List<TaskHelpInfo> TaskHelpInfoList
		{
			get
			{
				return this._taskHelpInfoList;
			}
		}

		public double ActivityLeftTime
		{
			get
			{
				return this._activityLeftTime;
			}
			set
			{
				this._activityLeftTime = value;
			}
		}

		public uint RemainedFreshTimes
		{
			get
			{
				return this._remainedFreshTimes;
			}
		}

		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("XGuildWeeklyBountyDocument");

		public static XTableAsyncLoader AsyncLoader = new XTableAsyncLoader();

		private uint _weeklyScore;

		private uint _weeklyAskedHelpNum;

		private uint _taskRoleLevel = 0u;

		private List<uint> _rewardedBoxList = new List<uint>();

		private List<GuildWeeklyTaskInfo> _curGuildWeeklyTaskList = new List<GuildWeeklyTaskInfo>();

		private Dictionary<uint, List<GuildTaskReward>> _guildTaskRewardWithMap = new Dictionary<uint, List<GuildTaskReward>>();

		private List<uint> _chestValueList = new List<uint>();

		private List<TaskHelpInfo> _taskHelpInfoList = new List<TaskHelpInfo>();

		private double _activityLeftTime = 0.0;

		private uint _remainedFreshTimes = 0u;

		public static void Execute(OnLoadedCallback callback = null)
		{
			XGuildWeeklyBountyDocument.AsyncLoader.Execute(callback);
		}

		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
		}

		protected override void EventSubscribe()
		{
			base.EventSubscribe();
		}

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

		protected override void OnReconnected(XReconnectedEventArgs arg)
		{
		}

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

		public void SendGetWeeklyTaskInfo()
		{
			RpcC2G_GetWeeklyTaskInfo rpc = new RpcC2G_GetWeeklyTaskInfo();
			XSingleton<XClientNetwork>.singleton.Send(rpc);
		}

		public void OnGetWeeklyTaskInfo(GetWeeklyTaskInfoRes oRes)
		{
			this._weeklyScore = oRes.score;
			this._weeklyAskedHelpNum = oRes.askhelp_num;
			this._rewardedBoxList = oRes.rewarded_box;
			this._taskHelpInfoList = oRes.helpinfo;
			this._taskRoleLevel = oRes.accept_level;
			this._activityLeftTime = oRes.lefttime;
			this._remainedFreshTimes = oRes.remain_free_refresh_count;
			this.UpdateTaskContent(oRes.task);
			this.ResetRewardsMap();
			bool flag = DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.IsVisible();
			if (flag)
			{
				DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.RefreshUI();
			}
		}

		public bool HasFinishWeeklyTasks()
		{
			return this.IsAllBoxsReward() && this.IsAllTaskFinished();
		}

		public void SendToGetWeeklyTaskReward(uint type, uint value)
		{
			RpcC2G_GetWeeklyTaskReward rpcC2G_GetWeeklyTaskReward = new RpcC2G_GetWeeklyTaskReward();
			rpcC2G_GetWeeklyTaskReward.oArg.type = type;
			rpcC2G_GetWeeklyTaskReward.oArg.value = value;
			XSingleton<XClientNetwork>.singleton.Send(rpcC2G_GetWeeklyTaskReward);
		}

		public void OnGetWeeklyTaskReward(GetWeeklyTaskRewardArg oArg, GetWeeklyTaskRewardRes oRes)
		{
			bool flag = oArg.type == 1u && (ulong)oArg.value < (ulong)((long)this._curGuildWeeklyTaskList.Count);
			if (flag)
			{
				this._weeklyScore = oRes.score;
				for (int i = 0; i < this._curGuildWeeklyTaskList.Count; i++)
				{
					GuildWeeklyTaskInfo guildWeeklyTaskInfo = this._curGuildWeeklyTaskList[i];
					bool flag2 = guildWeeklyTaskInfo.originIndex == oArg.value;
					if (flag2)
					{
						guildWeeklyTaskInfo.isRewarded = true;
						break;
					}
				}
				bool flag3 = DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.IsVisible();
				if (flag3)
				{
					DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.RefreshTaskList(false);
					DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.RefreshChestList();
					DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.PlayCompleteEffect();
				}
			}
			else
			{
				bool flag4 = oArg.type == 2u;
				if (flag4)
				{
					bool flag5 = !this._rewardedBoxList.Contains(oArg.value);
					if (flag5)
					{
						this._rewardedBoxList.Add(oArg.value);
					}
					bool flag6 = DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.IsVisible();
					if (flag6)
					{
						DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.RefreshChestList();
					}
				}
			}
		}

		private bool IsAllBoxsReward()
		{
			List<uint> chestValueList = XGuildWeeklyBountyDocument.Doc.ChestValueList;
			for (int i = 0; i < chestValueList.Count; i++)
			{
				bool flag = !this.RewardedBoxList.Contains(chestValueList[i]);
				if (flag)
				{
					return false;
				}
			}
			return true;
		}

		private bool IsAllTaskFinished()
		{
			for (int i = 0; i < this._curGuildWeeklyTaskList.Count; i++)
			{
				bool flag = !this._curGuildWeeklyTaskList[i].isRewarded;
				if (flag)
				{
					return false;
				}
			}
			return true;
		}

		private void UpdateTaskContent(List<WeeklyTaskInfo> task)
		{
			this.CurGuildWeeklyTaskList.Clear();
			for (int i = 0; i < task.Count; i++)
			{
				WeeklyTaskInfo weeklyTaskInfo = task[i];
				this.CurGuildWeeklyTaskList.Add(new GuildWeeklyTaskInfo
				{
					taskID = weeklyTaskInfo.id,
					step = weeklyTaskInfo.step,
					isRewarded = weeklyTaskInfo.is_rewarded,
					hasAsked = weeklyTaskInfo.ask_help,
					refreshedCount = weeklyTaskInfo.refresh_count,
					originIndex = weeklyTaskInfo.index,
					category = WeeklyTaskCategory.None
				});
			}
			this._curGuildWeeklyTaskList.Sort(new Comparison<GuildWeeklyTaskInfo>(this.SortWeeklyTaskList));
		}

		private int SortWeeklyTaskList(GuildWeeklyTaskInfo x, GuildWeeklyTaskInfo y)
		{
			DailyTask.RowData dailyTaskTableInfoByID = XGuildDailyTaskDocument.Doc.GetDailyTaskTableInfoByID(x.taskID);
			DailyTask.RowData dailyTaskTableInfoByID2 = XGuildDailyTaskDocument.Doc.GetDailyTaskTableInfoByID(y.taskID);
			bool flag = dailyTaskTableInfoByID != null && dailyTaskTableInfoByID2 != null;
			if (flag)
			{
				bool flag2 = x.isRewarded ^ y.isRewarded;
				if (flag2)
				{
					bool isRewarded = x.isRewarded;
					if (isRewarded)
					{
						return 1;
					}
					bool isRewarded2 = y.isRewarded;
					if (isRewarded2)
					{
						return -1;
					}
				}
				else
				{
					bool flag3 = !x.isRewarded && x.step >= dailyTaskTableInfoByID.conditionNum;
					bool flag4 = !y.isRewarded && y.step >= dailyTaskTableInfoByID2.conditionNum;
					bool flag5 = flag3 ^ flag4;
					if (flag5)
					{
						bool flag6 = flag3;
						if (flag6)
						{
							return -1;
						}
						bool flag7 = flag4;
						if (flag7)
						{
							return 1;
						}
					}
					else
					{
						bool flag8 = dailyTaskTableInfoByID.taskquality != dailyTaskTableInfoByID2.taskquality;
						if (flag8)
						{
							return (int)(dailyTaskTableInfoByID2.taskquality - dailyTaskTableInfoByID.taskquality);
						}
					}
				}
			}
			return (int)(x.taskID - y.taskID);
		}

		private void ResetRewardsMap()
		{
			this._guildTaskRewardWithMap.Clear();
			this._chestValueList.Clear();
			for (int i = 0; i < XGuildDailyTaskDocument.DailyTaskRewardTable.Table.Length; i++)
			{
				DailyTaskReward.RowData rowData = XGuildDailyTaskDocument.DailyTaskRewardTable.Table[i];
				uint num = rowData.level[0];
				uint num2 = rowData.level[1];
				bool flag = this._taskRoleLevel >= num && this._taskRoleLevel <= num2;
				if (flag)
				{
					uint mappingValueWithQualityAndType = XGuildDailyTaskDocument.GetMappingValueWithQualityAndType((GuildTaskType)rowData.category, rowData.tasktype, rowData.taskquality);
					bool flag2 = rowData.category == 2u && !this._guildTaskRewardWithMap.ContainsKey(mappingValueWithQualityAndType);
					if (flag2)
					{
						this._guildTaskRewardWithMap.Add(mappingValueWithQualityAndType, new List<GuildTaskReward>());
						for (int j = 0; j < rowData.taskreward.Count; j++)
						{
							this._guildTaskRewardWithMap[mappingValueWithQualityAndType].Add(new GuildTaskReward
							{
								itemID = rowData.taskreward[j, 0],
								count = rowData.taskreward[j, 1]
							});
						}
					}
					bool flag3 = rowData.category == 2u && rowData.tasktype == 2u;
					if (flag3)
					{
						bool flag4 = !this._chestValueList.Contains(rowData.taskquality);
						if (flag4)
						{
							this._chestValueList.Add(rowData.taskquality);
						}
					}
				}
			}
			this._chestValueList.Sort();
		}

		public List<GuildTaskReward> GetSingleTaskRewardInfoByID(GuildTaskType type, uint taskID)
		{
			DailyTask.RowData dailyTaskTableInfoByID = XGuildDailyTaskDocument.Doc.GetDailyTaskTableInfoByID(taskID);
			bool flag = dailyTaskTableInfoByID != null;
			if (flag)
			{
				uint mappingValueWithQualityAndType = XGuildDailyTaskDocument.GetMappingValueWithQualityAndType(type, 1u, dailyTaskTableInfoByID.taskquality);
				List<GuildTaskReward> result = new List<GuildTaskReward>();
				bool flag2 = this._guildTaskRewardWithMap.TryGetValue(mappingValueWithQualityAndType, out result);
				if (flag2)
				{
					return result;
				}
			}
			return new List<GuildTaskReward>();
		}

		public List<GuildTaskReward> GetTotalTaskRewardInfo(GuildTaskType type, uint count)
		{
			uint mappingValueWithQualityAndType = XGuildDailyTaskDocument.GetMappingValueWithQualityAndType(type, 2u, count);
			List<GuildTaskReward> list = new List<GuildTaskReward>();
			bool flag = this._guildTaskRewardWithMap.TryGetValue(mappingValueWithQualityAndType, out list);
			List<GuildTaskReward> result;
			if (flag)
			{
				result = list;
			}
			else
			{
				result = new List<GuildTaskReward>();
			}
			return result;
		}

		public void SendCommitWeeklyItem(uint index, List<ulong> items)
		{
			RpcC2G_TurnOverWeeklyTaskItem rpcC2G_TurnOverWeeklyTaskItem = new RpcC2G_TurnOverWeeklyTaskItem();
			rpcC2G_TurnOverWeeklyTaskItem.oArg.index = index;
			rpcC2G_TurnOverWeeklyTaskItem.oArg.itemuid.Clear();
			rpcC2G_TurnOverWeeklyTaskItem.oArg.itemuid.AddRange(items);
			XSingleton<XClientNetwork>.singleton.Send(rpcC2G_TurnOverWeeklyTaskItem);
		}

		public void OnTurnOverWeeklyTaskReply(TurnOverWeeklyTaskItemArg oArg, TurnOverWeeklyTaskItemRes oRes)
		{
			XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("weeklyCommitSuccess"), "fece00");
			bool flag = (ulong)oArg.index < (ulong)((long)this._curGuildWeeklyTaskList.Count);
			if (flag)
			{
				for (int i = 0; i < this._curGuildWeeklyTaskList.Count; i++)
				{
					bool flag2 = oArg.index == this._curGuildWeeklyTaskList[i].originIndex;
					if (flag2)
					{
						GuildWeeklyTaskInfo guildWeeklyTaskInfo = this._curGuildWeeklyTaskList[i];
						guildWeeklyTaskInfo.step += (uint)oArg.itemuid.Count;
						bool flag3 = DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.IsVisible();
						if (flag3)
						{
							DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.RefreshTaskList(false);
						}
						break;
					}
				}
			}
		}

		public void SendToRefreshTaskList(uint taskIndex)
		{
			RpcC2G_RefreshWeeklyTask rpcC2G_RefreshWeeklyTask = new RpcC2G_RefreshWeeklyTask();
			rpcC2G_RefreshWeeklyTask.oArg.index = taskIndex;
			XSingleton<XClientNetwork>.singleton.Send(rpcC2G_RefreshWeeklyTask);
		}

		internal void OnRefreshTaskList(RefreshWeeklyTaskArg oArg, RefreshWeeklyTaskRes oRes)
		{
			bool flag = this._remainedFreshTimes > 0u;
			if (flag)
			{
				this._remainedFreshTimes -= 1u;
			}
			for (int i = 0; i < this._curGuildWeeklyTaskList.Count; i++)
			{
				bool flag2 = this._curGuildWeeklyTaskList[i].originIndex == oArg.index;
				if (flag2)
				{
					WeeklyTaskInfo task = oRes.task;
					this.CurGuildWeeklyTaskList[i] = new GuildWeeklyTaskInfo
					{
						taskID = task.id,
						step = task.step,
						isRewarded = task.is_rewarded,
						hasAsked = task.ask_help,
						refreshedCount = task.refresh_count,
						originIndex = task.index
					};
					break;
				}
			}
			bool flag3 = DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.IsVisible();
			if (flag3)
			{
				DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.RefreshTaskList(false);
				DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.PlayRefreshEffect();
			}
		}

		public int GetTaskOriginalIndexByID(uint curSelectTaskID)
		{
			for (int i = 0; i < this._curGuildWeeklyTaskList.Count; i++)
			{
				bool flag = this._curGuildWeeklyTaskList[i].taskID == curSelectTaskID;
				if (flag)
				{
					return (int)this._curGuildWeeklyTaskList[i].originIndex;
				}
			}
			return -1;
		}

		public GuildWeeklyTaskInfo GetTaskInfoByTaskID(uint curSelectTaskID)
		{
			for (int i = 0; i < this._curGuildWeeklyTaskList.Count; i++)
			{
				bool flag = this._curGuildWeeklyTaskList[i].taskID == curSelectTaskID;
				if (flag)
				{
					return this._curGuildWeeklyTaskList[i];
				}
			}
			return null;
		}

		public GuildWeeklyTaskInfo GetTaskInfoByIndex(uint curSelectIndex)
		{
			for (int i = 0; i < this._curGuildWeeklyTaskList.Count; i++)
			{
				bool flag = this._curGuildWeeklyTaskList[i].originIndex == curSelectIndex;
				if (flag)
				{
					return this._curGuildWeeklyTaskList[i];
				}
			}
			return null;
		}

		public int GetRewardedTaskCount()
		{
			int num = 0;
			for (int i = 0; i < this._curGuildWeeklyTaskList.Count; i++)
			{
				bool isRewarded = this._curGuildWeeklyTaskList[i].isRewarded;
				if (isRewarded)
				{
					num++;
				}
			}
			return num;
		}

		public void OnGetWeeklyHelpReply(DailyTaskAskHelpArg oArg, DailyTaskAskHelpRes oRes)
		{
			bool flag = oRes.code == ErrorCode.ERR_SUCCESS;
			if (flag)
			{
				DailyTask.RowData dailyTaskTableInfoByID = XGuildDailyTaskDocument.Doc.GetDailyTaskTableInfoByID(oArg.task_id);
				GuildWeeklyTaskInfo taskInfoByTaskID = this.GetTaskInfoByTaskID(oArg.task_id);
				bool flag2 = taskInfoByTaskID != null && dailyTaskTableInfoByID != null;
				if (flag2)
				{
					bool flag3 = dailyTaskTableInfoByID.tasktype == 4u;
					if (flag3)
					{
						XGuildDailyTaskDocument.Doc.SendGuildDonateReq(dailyTaskTableInfoByID.conditionNum - taskInfoByTaskID.step, dailyTaskTableInfoByID.BQ[0, 0], oRes.ask_uid, NoticeType.NT_GUILD_Weekly_DONATE_REQ);
					}
					else
					{
						XGuildDailyTaskDocument.Doc.SendGuildDonateReq(dailyTaskTableInfoByID.conditionNum - taskInfoByTaskID.step, dailyTaskTableInfoByID.conditionId[0], oRes.ask_uid, NoticeType.NT_GUILD_Weekly_DONATE_REQ);
					}
					taskInfoByTaskID.hasAsked = true;
					this._weeklyAskedHelpNum += 1u;
					bool flag4 = DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.IsVisible();
					if (flag4)
					{
						DlgBase<XGuildWeeklyBountyView, XGuildWeeklyBountyBehavior>.singleton.RefreshTaskItem();
					}
				}
			}
			else
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(oRes.code, "fece00");
			}
		}

		public bool GoToTakeTask()
		{
			XTaskDocument specificDocument = XDocuments.GetSpecificDocument<XTaskDocument>(XTaskDocument.uuID);
			XTaskRecord taskRecord = specificDocument.TaskRecord;
			for (int i = 0; i < taskRecord.Tasks.Count; i++)
			{
				bool flag = taskRecord.Tasks[i].Status == TaskStatus.TaskStatus_CanTake && taskRecord.Tasks[i].TableData.TaskType == 7u;
				if (flag)
				{
					return true;
				}
			}
			return false;
		}
	}
}