summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XPlayer.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/XPlayer.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/XPlayer.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/XPlayer.cs385
1 files changed, 385 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/XPlayer.cs b/Client/Assets/Scripts/XMainClient/XPlayer.cs
new file mode 100644
index 00000000..c9707f54
--- /dev/null
+++ b/Client/Assets/Scripts/XMainClient/XPlayer.cs
@@ -0,0 +1,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;
+ }
+ }
+}