summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XPlayer.cs
blob: c9707f54ffd542996a6f4100bbb4d7ee8e2bea01 (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
using System;
using System.Collections.Generic;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient
{
	internal sealed class XPlayer : XRole
	{
		public XRole WatchTo
		{
			get
			{
				return (this._watch_to != null && !this._watch_to.Deprecated) ? this._watch_to : null;
			}
		}

		public XLocateTargetComponent TargetLocated
		{
			get
			{
				return this._located_target;
			}
		}

		public bool IsCorrectingMe
		{
			get
			{
				return this._correct_me;
			}
		}

		public uint[] SkillSlot
		{
			get
			{
				bool flag = base.Skill != null && base.Skill.IsSkillReplaced;
				uint[] result;
				if (flag)
				{
					result = base.Skill.ReplacedSlot;
				}
				else
				{
					result = this.Attributes.skillSlot;
				}
				return result;
			}
		}

		public XPlayerAttributes PlayerAttributes
		{
			get
			{
				return this.Attributes as XPlayerAttributes;
			}
		}

		private XLocateTargetComponent _located_target = null;

		private XRole _watch_to = null;

		private IXPlayerAction _action = null;

		private bool _correct_me = false;

		public static int PlayerLayer = LayerMask.NameToLayer("Player");

		public override bool Initilize(int flag)
		{
			base.Initilize(flag);
			this._xobject.Tag = "Player";
			this._eEntity_Type |= XEntity.EnitityType.Entity_Player;
			this._layer = XPlayer.PlayerLayer;
			this._using_cc_move = true;
			this._client_predicted = true;
			this._action = XSingleton<XInterfaceMgr>.singleton.AttachInterface<IXPlayerAction>(1u, new XPlayerAction());
			XSingleton<XInterfaceMgr>.singleton.AttachInterface<IAssociatedCamera>(XSingleton<XCommon>.singleton.XHash("IAssociatedCamera"), new XAssociatedCamera());
			bool flag2 = !XSingleton<XScene>.singleton.bSpectator;
			if (flag2)
			{
				XSingleton<XComponentMgr>.singleton.CreateComponent(this, XActionGeneratorComponent.uuID);
				bool flag3 = XSingleton<XSceneMgr>.singleton.SceneCanNavi(XSingleton<XScene>.singleton.SceneID);
				if (flag3)
				{
					this._nav = (XSingleton<XComponentMgr>.singleton.CreateComponent(this, XNavigationComponent.uuID) as XNavigationComponent);
				}
				bool flag4 = XSingleton<XSceneMgr>.singleton.CanAutoPlay(XSingleton<XScene>.singleton.SceneID) && this._xobject.IsNotEmptyObject;
				if (flag4)
				{
					bool flag5 = this._ai == null;
					if (flag5)
					{
						this._ai = (XSingleton<XComponentMgr>.singleton.CreateComponent(this, XAIComponent.uuID) as XAIComponent);
					}
					bool flag6 = this._nav == null;
					if (flag6)
					{
						this._nav = (XSingleton<XComponentMgr>.singleton.CreateComponent(this, XNavigationComponent.uuID) as XNavigationComponent);
					}
				}
			}
			bool flag7 = XSingleton<XGame>.singleton.CurrentStage.Stage != EXStage.Hall && XSingleton<XSceneMgr>.singleton.SpecifiedTargetLocatedRange(XSingleton<XScene>.singleton.SceneID) != 0f;
			if (flag7)
			{
				this._located_target = (XSingleton<XComponentMgr>.singleton.CreateComponent(this, XLocateTargetComponent.uuID) as XLocateTargetComponent);
			}
			return true;
		}

		public void UpdatePlayerAttr(XPlayerAttributes attr)
		{
			this._attr = attr;
		}

		public override void OnCreated()
		{
			XSingleton<XEntityMgr>.singleton.Player = this;
			bool flag = this.Attributes.SkillLevelInfo != null;
			if (flag)
			{
				this.Attributes.SkillLevelInfo.RefreshSelfLinkedLevels(this);
			}
			base.OnCreated();
		}

		public override void OnDestroy()
		{
			XSingleton<XEntityMgr>.singleton.Player = null;
			XSingleton<XInterfaceMgr>.singleton.DetachInterface(1u);
			XSingleton<XInterfaceMgr>.singleton.DetachInterface(XSingleton<XCommon>.singleton.XHash("IAssociatedCamera"));
			this._action = null;
			this._watch_to = null;
			base.OnDestroy();
		}

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

		public override void Revive()
		{
			base.Revive();
			XSingleton<XLevelStatistics>.singleton.OnPlayerRevive();
		}

		public void PreUpdate()
		{
			this._action.RefreshPosition();
		}

		public void WatchIt(XRole role)
		{
			this._watch_to = role;
			this._net.Pause = true;
			XSpectateSceneDocument specificDocument = XDocuments.GetSpecificDocument<XSpectateSceneDocument>(XSpectateSceneDocument.uuID);
			specificDocument.ChangeSpectator(role);
			XGuildArenaBattleDocument specificDocument2 = XDocuments.GetSpecificDocument<XGuildArenaBattleDocument>(XGuildArenaBattleDocument.uuID);
			specificDocument2.ChangeSpectator(role);
			this.UpdateWatcher();
			XCameraSoloComponent solo = XSingleton<XScene>.singleton.GameCamera.Solo;
			bool flag = solo == null;
			if (!flag)
			{
				solo.Stop();
				XSingleton<XScene>.singleton.GameCamera.TrySolo();
			}
		}

		public override void OnTransform(uint to)
		{
			base.OnTransform(to);
			XBattleSkillDocument specificDocument = XDocuments.GetSpecificDocument<XBattleSkillDocument>(XBattleSkillDocument.uuID);
			bool flag = specificDocument != null;
			if (flag)
			{
				specificDocument.ResetAll(XSingleton<XScene>.singleton.SceneReady && base.IsTransform, true);
			}
		}

		public override void UpdateWatcher()
		{
			bool bSpectator = XSingleton<XScene>.singleton.bSpectator;
			if (bSpectator)
			{
				bool flag = this._watch_to != null;
				if (flag)
				{
					bool deprecated = this._watch_to.Deprecated;
					if (deprecated)
					{
						this._watch_to = null;
					}
					else
					{
						base.MoveObj.Position = this._watch_to.MoveObj.Position;
						base.MoveObj.Rotation = this._watch_to.MoveObj.Rotation;
					}
				}
			}
		}

		protected override void PositionTo(Vector3 pos)
		{
			base.PositionTo(pos);
			this._correct_me = false;
			this._action.RefreshPosition();
		}

		public override void CorrectMe(Vector3 pos, Vector3 face, bool reconnected = false, bool fade = false)
		{
			XSingleton<XActionSender>.singleton.Empty();
			bool flag = XSingleton<XScene>.singleton.bSpectator && XSingleton<XScene>.singleton.bSceneServerReady;
			if (!flag)
			{
				this._correct_me = true;
				base.CorrectMe(pos, face, reconnected, fade);
			}
		}

		public void OnGamePause(bool pause)
		{
			if (pause)
			{
				XSingleton<XVirtualTab>.singleton.Cancel();
				base.Net.ReportMoveAction(Vector3.zero, 0.0);
				XSingleton<XActionSender>.singleton.Flush(true);
				XSingleton<XDebug>.singleton.AddLog("Player to BackGround.", null, null, null, null, null, XDebugColor.XDebug_None);
			}
		}

		protected override void Move()
		{
			bool bSpectator = XSingleton<XScene>.singleton.bSpectator;
			if (bSpectator)
			{
				this.UpdateWatcher();
			}
			else
			{
				Vector3 hitNormal = XSingleton<XScene>.singleton.GameCamera.Collision.HitNormal;
				hitNormal.y = 0f;
				Vector3 movement = this._movement;
				movement.y = 0f;
				bool flag = hitNormal.sqrMagnitude > 0f && movement.sqrMagnitude > 0f && Vector3.Angle(movement, hitNormal) > 90f;
				if (flag)
				{
					this.EdgeDetection(this.EngineObject.Forward, ref movement);
					float num = Vector3.SqrMagnitude(XSingleton<XScene>.singleton.GameCamera.CameraTrans.position - this.EngineObject.Position);
					bool flag2 = num < 1f;
					if (flag2)
					{
						this.ProjectNormal(hitNormal, ref movement);
					}
					this._movement.x = movement.x;
					this._movement.z = movement.z;
				}
				base.Move();
				this.MoveLateUpdate();
			}
		}

		private void MoveLateUpdate()
		{
			bool flag = XSingleton<XGame>.singleton.SyncMode && !XStateMgr.IsUnBattleState(base.Machine.Current);
			if (!flag)
			{
				List<XEntity> opponent = XSingleton<XEntityMgr>.singleton.GetOpponent(this);
				for (int i = 0; i < opponent.Count; i++)
				{
					Vector3 position = base.MoveObj.Position;
					bool isRole = opponent[i].IsRole;
					if (!isRole)
					{
						bool flag2 = (opponent[i].IsPuppet || opponent[i].IsSubstance) && !XEntity.ValideEntity(opponent[i]);
						if (!flag2)
						{
							bool flag3 = opponent[i].Skill != null && opponent[i].Skill.IsCasting() && opponent[i].Skill.CurrentSkill.MainCore.Soul.IgnoreCollision;
							if (!flag3)
							{
								XOthersAttributes xothersAttributes = opponent[i].Attributes as XOthersAttributes;
								bool flag4 = xothersAttributes == null || !xothersAttributes.Blocked;
								if (!flag4)
								{
									bool flag5 = opponent[i].MoveObj.Position.y > position.y + base.Height;
									if (!flag5)
									{
										bool flag6 = opponent[i].Present != null && opponent[i].Present.PresentLib.Huge;
										if (flag6)
										{
											SeqListRef<float> hugeMonsterColliders = opponent[i].Present.PresentLib.HugeMonsterColliders;
											for (int j = 0; j < hugeMonsterColliders.Count; j++)
											{
												float num = hugeMonsterColliders[j, 2] * opponent[i].Scale;
												this.A(position, opponent[i].HugeMonsterColliderCenter(j), base.Radius + num);
											}
										}
										else
										{
											this.A(position, opponent[i].RadiusCenter, base.Radius + opponent[i].Radius);
										}
									}
								}
							}
						}
					}
				}
			}
		}

		private void A(Vector3 me, Vector3 it, float r)
		{
			Vector3 v = me - it;
			v.y = 0f;
			float sqrMagnitude = v.sqrMagnitude;
			bool flag = sqrMagnitude - r * r < -0.001f;
			if (flag)
			{
				Vector3 vector = XSingleton<XCommon>.singleton.Horizontal(v);
				Vector3 vector2 = it + vector * r;
				float y = vector2.y;
				bool flag2 = XSingleton<XScene>.singleton.TryGetTerrainY(vector2, out y) && y >= 0f;
				if (flag2)
				{
					bool flag3 = XSingleton<XScene>.singleton.CheckDynamicBlock(base.MoveObj.Position, vector2);
					if (flag3)
					{
						bool standOn = base.StandOn;
						if (standOn)
						{
							vector2.y = y + 0.25f;
							base.MoveObj.Position = vector2;
							base.MoveObj.Move(Vector3.down);
						}
						else
						{
							vector2.y = me.y;
							base.MoveObj.Position = vector2;
						}
					}
				}
			}
		}

		private bool EdgeDetection(Vector3 forward, ref Vector3 move)
		{
			RaycastHit raycastHit;
			bool flag = this.RayDetection(forward, out raycastHit);
			bool result;
			if (flag)
			{
				this.ProjectNormal(raycastHit.normal, ref move);
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}

		private void ProjectNormal(Vector3 normal, ref Vector3 move)
		{
			Vector3 forward = Vector3.forward;
			Vector3 vector = normal;
			Vector3.OrthoNormalize(ref vector, ref forward);
			move = Vector3.Project(move, forward);
		}

		private bool RayDetection(Vector3 ray, out RaycastHit hit)
		{
			int num = 513;
			Vector3 position = this.EngineObject.Position;
			position.y += base.Height;
			return Physics.Raycast(position, ray, out hit, 1f, num);
		}

		public override bool CastFakeShadow()
		{
			return true;
		}
	}
}