summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/Team/XTeamMemberMonitor.cs
blob: 52d17dfe5e5e87a93ad2130b8cc09e7aea1e5c3e (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
using System;
using System.Collections.Generic;
using KKSG;
using UILib;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XTeamMemberMonitor
	{
		public XTeamBloodUIData Data
		{
			get
			{
				return this.m_MemberData;
			}
		}

		public XEntity Entity
		{
			get
			{
				return this.m_Entity;
			}
		}

		public ulong ID
		{
			get
			{
				return this.m_MemberData.uid;
			}
		}

		public ulong EntityID
		{
			get
			{
				return this.m_MemberData.entityID;
			}
		}

		private GameObject m_Go;

		private bool m_bActive = true;

		private XTeamBloodUIData m_MemberData;

		private XTeamMonitorStateMgr m_StateMgr;

		private XEntity m_Entity;

		private IXUISprite m_uiAvatar;

		private IXUILabel m_uiName;

		private GameObject m_uiLeader;

		private IXUIProgress m_uiHpBar;

		private IXUIProgress m_uiMpBar;

		private GameObject m_uiDead;

		private IXUISprite m_HeroIcon;

		private IXUISprite m_HeroUnSelect;

		private IXUILabel m_uiLevel;

		public IXUISprite m_sprVoice;

		public IXUISprite m_sprSpeak;

		private GameObject m_uiLeave;

		private GameObject m_uiLoading;

		private IXUICheckBox m_uiCheckBox;

		private XBuffMonitorHandler m_BuffMonitor;

		public XTeamMemberMonitor(XTeamMonitorStateMgr stateMgr)
		{
			this.m_StateMgr = stateMgr;
		}

		public void SetGo(GameObject go)
		{
			this.m_Go = go;
			this.m_uiAvatar = (go.transform.Find("AvatarBG/Avatar").GetComponent("XUISprite") as IXUISprite);
			this.m_uiName = (go.transform.Find("PlayerName").GetComponent("XUILabel") as IXUILabel);
			this.m_uiLeader = go.transform.Find("TeamLeader").gameObject;
			this.m_HeroIcon = (go.transform.Find("Frame/HeroIcon").GetComponent("XUISprite") as IXUISprite);
			this.m_HeroUnSelect = (go.transform.Find("Frame/UnSelect").GetComponent("XUISprite") as IXUISprite);
			bool flag = DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded();
			if (flag)
			{
				this.m_sprVoice = (go.transform.Find("VoiceInfo/voice").GetComponent("XUISprite") as IXUISprite);
				this.m_sprSpeak = (go.transform.Find("VoiceInfo/speak").GetComponent("XUISprite") as IXUISprite);
			}
			Transform transform = go.transform.Find("HpBar");
			bool flag2 = transform != null;
			if (flag2)
			{
				this.m_uiHpBar = (transform.GetComponent("XUIProgress") as IXUIProgress);
			}
			else
			{
				this.m_uiHpBar = null;
			}
			transform = go.transform.Find("MpBar");
			bool flag3 = transform != null;
			if (flag3)
			{
				this.m_uiMpBar = (transform.GetComponent("XUIProgress") as IXUIProgress);
			}
			else
			{
				this.m_uiMpBar = null;
			}
			transform = go.transform.Find("BuffFrame");
			bool flag4 = transform != null;
			if (flag4)
			{
				bool flag5 = XSingleton<XScene>.singleton.SceneType != SceneType.SCENE_HEROBATTLE || !XSingleton<XScene>.singleton.bSpectator;
				if (flag5)
				{
					transform.gameObject.SetActive(true);
					DlgHandlerBase.EnsureCreate<XBuffMonitorHandler>(ref this.m_BuffMonitor, transform.gameObject, null, true);
				}
				else
				{
					transform.gameObject.SetActive(false);
				}
			}
			transform = go.transform.Find("Dead");
			bool flag6 = transform != null;
			if (flag6)
			{
				this.m_uiDead = transform.gameObject;
			}
			transform = go.transform.Find("Leave");
			bool flag7 = transform != null;
			if (flag7)
			{
				this.m_uiLeave = transform.gameObject;
			}
			transform = go.transform.Find("Loading");
			bool flag8 = transform != null;
			if (flag8)
			{
				this.m_uiLoading = transform.gameObject;
			}
			transform = go.transform.Find("Level");
			bool flag9 = transform != null;
			if (flag9)
			{
				this.m_uiLevel = (transform.GetComponent("XUILabel") as IXUILabel);
			}
			else
			{
				this.m_uiLevel = null;
			}
			bool flag10 = DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IsLoaded();
			if (flag10)
			{
				this.m_uiCheckBox = (go.GetComponent("XUICheckBox") as IXUICheckBox);
			}
		}

		public void SetActive(bool bActive)
		{
			this.m_bActive = bActive;
			this.m_Go.SetActive(bActive);
		}

		public void PlaySound(int state)
		{
			bool flag = DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded();
			if (flag)
			{
				this.m_sprVoice.SetVisible(state == 1);
				this.m_sprSpeak.SetVisible(state == 2);
			}
		}

		public void SetMemberData(XTeamBloodUIData data)
		{
			this.m_MemberData = data;
			this.m_Entity = null;
			this.PlaySound(0);
			this._SetBasicUI();
			this.Update();
		}

		private bool OnSpectateChangeClick(IXUICheckBox checkBox)
		{
			bool flag = !checkBox.bChecked;
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				XEntity entityConsiderDeath = XSingleton<XEntityMgr>.singleton.GetEntityConsiderDeath(checkBox.ID);
				bool flag2 = entityConsiderDeath != null && entityConsiderDeath.IsRole;
				if (flag2)
				{
					XSingleton<XEntityMgr>.singleton.Player.WatchIt(entityConsiderDeath as XRole);
				}
				result = true;
			}
			return result;
		}

		private void _SetBasicUI()
		{
			bool flag = this.m_MemberData != null;
			if (flag)
			{
				this.m_uiName.SetText(this.m_MemberData.name);
				bool flag2 = XSingleton<XScene>.singleton.SceneType != SceneType.SCENE_HEROBATTLE;
				if (flag2)
				{
					this.m_uiAvatar.SetVisible(true);
					this.m_uiLevel.gameObject.SetActive(true);
					this.m_HeroIcon.gameObject.transform.parent.gameObject.SetActive(false);
					int profID = XFastEnumIntEqualityComparer<RoleType>.ToInt(this.m_MemberData.profession);
					this.m_uiAvatar.spriteName = XSingleton<XProfessionSkillMgr>.singleton.GetProfIcon(profID);
					this.m_uiLeader.SetActive(this.m_MemberData.bIsLeader);
					bool flag3 = this.m_uiLevel != null;
					if (flag3)
					{
						this.m_uiLevel.SetText("Lv." + this.m_MemberData.level.ToString());
					}
				}
				else
				{
					this.m_uiAvatar.SetVisible(false);
					this.m_uiLeader.SetActive(false);
					this.m_uiLevel.gameObject.SetActive(false);
					this.m_HeroIcon.gameObject.transform.parent.gameObject.SetActive(true);
					uint num = 0u;
					XHeroBattleDocument specificDocument = XDocuments.GetSpecificDocument<XHeroBattleDocument>(XHeroBattleDocument.uuID);
					specificDocument.heroIDIndex.TryGetValue(this.m_MemberData.uid, out num);
					bool flag4 = num == 0u;
					if (flag4)
					{
						this.m_HeroIcon.SetAlpha(0f);
						this.m_HeroUnSelect.SetAlpha(1f);
					}
					else
					{
						this.m_HeroIcon.SetAlpha(1f);
						OverWatchTable.RowData byHeroID = specificDocument.OverWatchReader.GetByHeroID(num);
						bool flag5 = byHeroID != null;
						if (flag5)
						{
							this.m_HeroIcon.SetSprite(byHeroID.Icon, byHeroID.IconAtlas, false);
						}
						else
						{
							XSingleton<XDebug>.singleton.AddErrorLog("Error heroID on TeamMonitor. heroID = ", num.ToString(), null, null, null, null);
						}
						this.m_HeroUnSelect.SetAlpha(0f);
					}
				}
			}
			else
			{
				this.m_HeroIcon.gameObject.transform.parent.gameObject.SetActive(false);
				this.m_uiName.SetText("");
				this.m_uiLeader.SetActive(false);
				this.m_uiAvatar.spriteName = "zd_wh";
				bool flag6 = this.m_uiLevel != null;
				if (flag6)
				{
					this.m_uiLevel.SetText("");
				}
			}
			this.m_uiAvatar.SetEnabled(true);
			bool flag7 = this.m_uiDead != null;
			if (flag7)
			{
				this.m_uiDead.SetActive(false);
			}
			bool flag8 = this.m_uiHpBar != null;
			if (flag8)
			{
				this.m_uiHpBar.value = 0f;
			}
			bool flag9 = !XSingleton<XScene>.singleton.bSpectator && this.m_uiMpBar != null;
			if (flag9)
			{
				this.m_uiMpBar.value = 0f;
			}
			bool flag10 = this.m_BuffMonitor != null;
			if (flag10)
			{
				this.m_BuffMonitor.InitMonitor(XSingleton<XGlobalConfig>.singleton.BuffMaxDisplayCountTeam, this.m_MemberData != null && this.m_MemberData.isLeft, false);
			}
			bool bSpectator = XSingleton<XScene>.singleton.bSpectator;
			if (bSpectator)
			{
				bool flag11 = XSingleton<XEntityMgr>.singleton.Player != null && XSingleton<XEntityMgr>.singleton.Player.WatchTo != null && this.m_MemberData != null && this.m_MemberData.uid == XSingleton<XEntityMgr>.singleton.Player.WatchTo.ID;
				if (flag11)
				{
					this.m_uiCheckBox.ForceSetFlag(true);
				}
				else
				{
					this.m_uiCheckBox.ForceSetFlag(false);
				}
				this.m_uiCheckBox.ID = this.m_MemberData.uid;
				this.m_uiCheckBox.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnSpectateChangeClick));
			}
		}

		private void _SetState()
		{
			XTeamMonitorState state = this.m_StateMgr.GetState(this.m_MemberData.uid);
			bool flag = this.m_uiLeave != null;
			if (flag)
			{
				this.m_uiLeave.SetActive(this.m_Entity == null && state != XTeamMonitorState.TMS_Loading);
			}
			bool flag2 = this.m_uiLoading != null;
			if (flag2)
			{
				this.m_uiLoading.SetActive(this.m_Entity == null && state == XTeamMonitorState.TMS_Loading);
			}
		}

		public void Update()
		{
			bool flag = !this.m_bActive;
			if (!flag)
			{
				bool flag2 = this.m_Entity == null && this.m_MemberData != null;
				if (flag2)
				{
					this.m_Entity = XSingleton<XEntityMgr>.singleton.GetEntityConsiderDeath(this.m_MemberData.entityID);
					bool flag3 = this.m_Entity == null;
					if (flag3)
					{
						this._SetState();
						return;
					}
					bool flag4 = !this.m_Entity.Deprecated;
					if (flag4)
					{
						bool flag5 = this.m_BuffMonitor != null;
						if (flag5)
						{
							this.m_BuffMonitor.OnBuffChanged(this.m_Entity.Buffs.GetUIBuffList());
						}
						this.m_StateMgr.SetState(this.m_MemberData.uid, XTeamMonitorState.TMS_Normal);
					}
				}
				bool flag6 = this.m_Entity == null || this.m_Entity.Deprecated;
				if (flag6)
				{
					this.m_Entity = null;
					this._SetBasicUI();
					this._SetState();
				}
				else
				{
					bool flag7 = this.m_BuffMonitor != null;
					if (flag7)
					{
						this.m_BuffMonitor.OnUpdate();
					}
					this._SetState();
					bool flag8 = this.m_uiHpBar != null;
					if (flag8)
					{
						int num = (int)this.m_Entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxHP_Total);
						int num2 = (int)this.m_Entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentHP_Basic);
						bool flag9 = num2 < 0;
						if (flag9)
						{
							num2 = 0;
						}
						this.m_uiHpBar.value = (float)num2 / (float)num;
					}
					bool flag10 = !XSingleton<XScene>.singleton.bSpectator && this.m_uiMpBar != null;
					if (flag10)
					{
						int num3 = (int)this.m_Entity.Attributes.GetAttr(XAttributeDefine.XAttr_MaxMP_Total);
						int num4 = (int)this.m_Entity.Attributes.GetAttr(XAttributeDefine.XAttr_CurrentMP_Basic);
						bool flag11 = num4 < 0;
						if (flag11)
						{
							num4 = 0;
						}
						this.m_uiMpBar.value = (float)num4 / (float)num3;
					}
					bool flag12 = this.m_uiDead != null;
					if (flag12)
					{
						this.m_uiDead.SetActive(!XEntity.ValideEntity(this.m_Entity));
						this.m_uiAvatar.SetEnabled(XEntity.ValideEntity(this.m_Entity));
					}
				}
			}
		}

		public void OnBuffChange(List<UIBuffInfo> buffList)
		{
			bool flag = this.m_BuffMonitor != null;
			if (flag)
			{
				this.m_BuffMonitor.OnBuffChanged(buffList);
			}
		}

		public void CheckToggleState()
		{
			bool flag = XSingleton<XEntityMgr>.singleton.Player != null && XSingleton<XEntityMgr>.singleton.Player.WatchTo != null && this.m_MemberData.uid == XSingleton<XEntityMgr>.singleton.Player.WatchTo.ID;
			if (flag)
			{
				this.m_uiCheckBox.bChecked = true;
			}
			else
			{
				this.m_uiCheckBox.bChecked = false;
			}
		}

		public void Unload()
		{
			DlgHandlerBase.EnsureUnload<XBuffMonitorHandler>(ref this.m_BuffMonitor);
		}
	}
}