summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XPrerogativeDocument.cs
blob: e3afe35093833167f6338fe5a8679a3e552b1abf (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
using System;
using System.Collections.Generic;
using KKSG;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

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

		public bool RedPoint
		{
			get
			{
				return this._RedPoint;
			}
			set
			{
				bool flag = this._RedPoint != value;
				if (flag)
				{
					this._RedPoint = value;
					XSingleton<XGameSysMgr>.singleton.RecalculateRedPointState(XSysDefine.XSys_Prerogative, true);
				}
			}
		}

		public List<uint> PlayerSetid
		{
			get
			{
				return this._caches;
			}
		}

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

		private static PrerogativeContent _prerogativeContent = new PrerogativeContent();

		public static XTableAsyncLoader AsyncLoader = new XTableAsyncLoader();

		private static Dictionary<uint, uint> DefaultContent = new Dictionary<uint, uint>();

		public PrerogativeDlg View = null;

		private List<uint> _caches;

		private List<uint> _activeIds;

		private uint _cacheActiveId;

		private bool _RedPoint = false;

		protected override void OnReconnected(XReconnectedEventArgs arg)
		{
		}

		public static void Execute(OnLoadedCallback callback = null)
		{
			XPrerogativeDocument.AsyncLoader.AddTask("Table/PrerogativeContent", XPrerogativeDocument._prerogativeContent, false);
			XPrerogativeDocument.AsyncLoader.Execute(callback);
		}

		public static uint GetDefaultPreID(uint type)
		{
			return XPrerogativeDocument.DefaultContent.ContainsKey(type) ? XPrerogativeDocument.DefaultContent[type] : 0u;
		}

		public static void OnTableLoaded()
		{
			XPrerogativeDocument.DefaultContent.Clear();
			int i = 0;
			int num = XPrerogativeDocument._prerogativeContent.Table.Length;
			while (i < num)
			{
				PrerogativeContent.RowData rowData = XPrerogativeDocument._prerogativeContent.Table[i];
				bool flag = (ulong)rowData.Normal == (ulong)((long)XFastEnumIntEqualityComparer<PrerogativeNormalType>.ToInt(PrerogativeNormalType.PreDefault)) && !XPrerogativeDocument.DefaultContent.ContainsKey(rowData.Type);
				if (flag)
				{
					XPrerogativeDocument.DefaultContent.Add(rowData.Type, rowData.ID);
				}
				i++;
			}
		}

		public static uint ConvertTypeToPreId(uint type, List<uint> ids)
		{
			bool flag = ids != null;
			if (flag)
			{
				int i = 0;
				int count = ids.Count;
				while (i < count)
				{
					bool flag2 = XPrerogativeDocument.ConvertPreIdToType(ids[i]) == type;
					if (flag2)
					{
						return ids[i];
					}
					i++;
				}
			}
			return XPrerogativeDocument.DefaultContent[type];
		}

		public static uint ConvertTypeToPreId(uint type, uint id)
		{
			bool flag = id > 0u;
			if (flag)
			{
				bool flag2 = XPrerogativeDocument.ConvertPreIdToType(id) == type;
				if (flag2)
				{
					return id;
				}
			}
			return XPrerogativeDocument.DefaultContent[type];
		}

		public static string ConvertTypeToPreContent(PrerogativeType type, uint pid = 0u)
		{
			uint type2 = (uint)XFastEnumIntEqualityComparer<PrerogativeType>.ToInt(type);
			return XPrerogativeDocument.ConvertTypeToPreContent(type2, pid);
		}

		public static string ConvertTypeToPreContent(PrerogativeType type, List<uint> ids = null)
		{
			uint type2 = (uint)XFastEnumIntEqualityComparer<PrerogativeType>.ToInt(type);
			return XPrerogativeDocument.ConvertTypeToPreContent(type2, ids);
		}

		public static string ConvertTypeToPreContent(uint type, uint pid = 0u)
		{
			bool flag = type == 0u;
			string result;
			if (flag)
			{
				result = string.Empty;
			}
			else
			{
				uint key = XPrerogativeDocument.ConvertTypeToPreId(type, pid);
				PrerogativeContent.RowData byID = XPrerogativeDocument._prerogativeContent.GetByID(key);
				result = ((byID != null) ? byID.Content : string.Empty);
			}
			return result;
		}

		public static string ConvertTypeToPreContent(uint type, List<uint> ids = null)
		{
			bool flag = type == 0u;
			string result;
			if (flag)
			{
				result = string.Empty;
			}
			else
			{
				uint key = XPrerogativeDocument.ConvertTypeToPreId(type, ids);
				PrerogativeContent.RowData byID = XPrerogativeDocument._prerogativeContent.GetByID(key);
				result = ((byID != null) ? byID.Content : string.Empty);
			}
			return result;
		}

		public static PrerogativeContent.RowData ConvertTypeToPre(uint type, List<uint> ids = null)
		{
			uint key = XPrerogativeDocument.ConvertTypeToPreId(type, ids);
			return XPrerogativeDocument._prerogativeContent.GetByID(key);
		}

		public static PrerogativeContent.RowData GetPrerogativeByID(uint id)
		{
			return XPrerogativeDocument._prerogativeContent.GetByID(id);
		}

		private static uint ConvertPreIdToType(uint id)
		{
			PrerogativeContent.RowData byID = XPrerogativeDocument._prerogativeContent.GetByID(id);
			bool flag = byID != null;
			uint result;
			if (flag)
			{
				result = byID.Type;
			}
			else
			{
				result = 0u;
			}
			return result;
		}

		public void Initialize(List<uint> preIDs, List<uint> activeIDs)
		{
			this._caches = preIDs;
			this._activeIds = activeIDs;
		}

		public string GetPreContent(PrerogativeType type)
		{
			uint type2 = (uint)XFastEnumIntEqualityComparer<PrerogativeType>.ToInt(type);
			return this.GetPreContent(type2);
		}

		public string GetPreContent(uint type)
		{
			return XPrerogativeDocument.ConvertTypeToPreContent(type, this._caches);
		}

		public PrerogativeContent.RowData GetPreContentData(uint type)
		{
			return XPrerogativeDocument.ConvertTypeToPre(type, this._caches);
		}

		public uint GetPreContentID(uint type)
		{
			return XPrerogativeDocument.ConvertTypeToPreId(type, this._caches);
		}

		public bool TryGetContentByType(ref List<PrerogativeContent.RowData> list, uint type)
		{
			bool flag = list == null;
			if (flag)
			{
				list = new List<PrerogativeContent.RowData>();
			}
			list.Clear();
			int i = 0;
			int num = XPrerogativeDocument._prerogativeContent.Table.Length;
			while (i < num)
			{
				bool flag2 = XPrerogativeDocument._prerogativeContent.Table[i].Type == type && XPrerogativeDocument._prerogativeContent.Table[i].Normal != 2u;
				if (flag2)
				{
					list.Add(XPrerogativeDocument._prerogativeContent.Table[i]);
				}
				i++;
			}
			return true;
		}

		public bool IsActived(uint id)
		{
			bool flag = this._activeIds == null;
			return !flag && this._activeIds.Contains(id);
		}

		private bool CachePreValue(uint type, uint value)
		{
			bool flag = this._caches != null;
			if (flag)
			{
				int i = 0;
				int count = this._caches.Count;
				while (i < count)
				{
					bool flag2 = XPrerogativeDocument.ConvertPreIdToType(this._caches[i]) == type;
					if (flag2)
					{
						bool flag3 = this._caches[i] == value;
						if (flag3)
						{
							return false;
						}
						this._caches.RemoveAt(i);
						break;
					}
					else
					{
						i++;
					}
				}
			}
			else
			{
				this._caches = new List<uint>();
			}
			this._caches.Add(value);
			return true;
		}

		public bool TrySendPreCache(uint value)
		{
			PrerogativeContent.RowData byID = XPrerogativeDocument._prerogativeContent.GetByID(value);
			bool flag = byID != null && this.CachePreValue(byID.Type, value);
			bool result;
			if (flag)
			{
				RpcC2G_SetPreShow rpcC2G_SetPreShow = new RpcC2G_SetPreShow();
				rpcC2G_SetPreShow.oArg.showid.AddRange(this._caches);
				XSingleton<XClientNetwork>.singleton.Send(rpcC2G_SetPreShow);
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}

		public void HidePreCache(uint type)
		{
			uint num = XPrerogativeDocument.DefaultContent.ContainsKey(type) ? XPrerogativeDocument.DefaultContent[type] : 0u;
			bool flag = num > 0u;
			if (flag)
			{
				this.TrySendPreCache(num);
			}
		}

		public void ReceivePreCache(SetPreShowArg oArg, SetPreShowRes oRes)
		{
			bool flag = oRes.result > ErrorCode.ERR_SUCCESS;
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(oRes.result, "fece00");
			}
			else
			{
				this._caches = oArg.showid;
				this.Dispatch();
			}
		}

		public void TrySendActivePre(uint value)
		{
			PrerogativeContent.RowData byID = XPrerogativeDocument._prerogativeContent.GetByID(value);
			bool flag = byID != null;
			if (flag)
			{
				RpcC2G_ActivatePreShow rpcC2G_ActivatePreShow = new RpcC2G_ActivatePreShow();
				rpcC2G_ActivatePreShow.oArg.id = value;
				this._cacheActiveId = value;
				XSingleton<XClientNetwork>.singleton.Send(rpcC2G_ActivatePreShow);
			}
		}

		public void ReceiveActiveReply(ActivatePreShowArg oArg, ActivatePreShowRes oRes)
		{
			bool flag = oRes.result > ErrorCode.ERR_SUCCESS;
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(oRes.result, "fece00");
			}
			else
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("Prerogative_ActiveSuccess"), "fece00");
				bool flag2 = !this._activeIds.Contains(this._cacheActiveId);
				if (flag2)
				{
					this._activeIds.Add(this._cacheActiveId);
				}
				this.Dispatch();
			}
		}

		private void Dispatch()
		{
			XPrerogativeChangeArgs @event = XEventPool<XPrerogativeChangeArgs>.GetEvent();
			@event.Firer = XSingleton<XEntityMgr>.singleton.Player;
			XSingleton<XEventMgr>.singleton.FireEvent(@event);
			bool flag = DlgBase<PrerogativeDlg, PrerogativeDlgBehaviour>.singleton.IsVisible();
			if (flag)
			{
				DlgBase<PrerogativeDlg, PrerogativeDlgBehaviour>.singleton.Refresh();
			}
			bool flag2 = DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.IsVisible();
			if (flag2)
			{
				DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.SetHeadIcon();
			}
		}
	}
}