using System.Collections.Generic; using Snxxz.UI; using TableConfig; using UnityEngine; using UnityEngine.Events; public class GA_Player : GActorPlayerBase, IOtherSelectable { // 为守护特殊定义的当前是否装备守护id public int serverGuardId; // 简易的脱机挂AI草稿 // 步骤 1. 寻点 2. 移动至 3. 放个普攻 private byte m_Step; private Vector3 m_DestPos; private Vector3 m_RecordBornPos; private float m_WaitTime; public static UnityAction s_OnSelected; public static UnityAction s_OnRefreshLife; private H0434_tagAreaPlayerAppearEx m_H0434; private CmdManager m_CmdManager; private int m_ComAtkIndex;// 普攻索引 private Skill m_CastSkill;// 要释放的技能 protected sealed override void OnInit(GameNetPackBasic package) { m_H0434 = package as H0434_tagAreaPlayerAppearEx; if (m_H0434 == null) { return; } base.OnInit(package); if (CanBeSelected()) { CapsuleCollider _capCollider = Root.AddMissingComponent(); _capCollider.height = 1.2f; _capCollider.center = new Vector3(0, .6f, 0); _capCollider.radius = .4f; Evt_PlayerClick _evtClick = Root.AddMissingComponent(); _evtClick.ownerSID = ServerInstID; } Root.gameObject.layer = LayerUtility.Player; // 初始化坐标 AdjustPos(m_H0434.PosX, m_H0434.PosY); // 计算移动速度 CalculateMoveSpeed(m_H0434.Speed); CalculateAtkSpeed((ushort)m_H0434.AtkInterval); // 处理职业配置 JobSetup = ConfigManager.Instance.GetTemplate(m_H0434.Job); // 处理装备 H0434_tagAreaPlayerAppearEx.tagEquipInfo _equipInfo; // 因为衣服是所有装备的父节点, 需要预先处理衣服 for (int i = 0; i < m_H0434.EquipCount; ++i) { _equipInfo = m_H0434.EquipInfo[i]; if (_equipInfo.Place == (byte)RoleEquipType.retClothes) { m_SuitLevel = 0; if (_equipInfo.IsSuite == 1) { Dictionary> _userData = ConfigParse.Analysis(_equipInfo.UserData); if (_userData.ContainsKey(30)) { m_SuitLevel = (byte)_userData[30][0]; } } SwitchClothes(_equipInfo.ItemID); ChangeEquip(_equipInfo.Place, _equipInfo.ItemID, m_SuitLevel); break; } } // 如果没有任何衣服, 则穿上默认装备 if (ClothesItemID == 0 || ClothesItemID == uint.MaxValue) { SwitchClothes(0); } // 处理其他装备 for (int i = 0; i < m_H0434.EquipCount; ++i) { _equipInfo = m_H0434.EquipInfo[i]; if (_equipInfo.Place == (int)RoleEquipType.retWeapon) { SwitchWeapon(_equipInfo.ItemID); } else if (_equipInfo.Place == (int)RoleEquipType.retWeapon2) { SwitchSecondary(_equipInfo.ItemID); } else if (_equipInfo.Place == (int)RoleEquipType.retWing) { SwitchWing(_equipInfo.ItemID); } else if (_equipInfo.Place == (int)RoleEquipType.retSpiritAnimal) { SwitchGuard(_equipInfo.ItemID); serverGuardId = (int)_equipInfo.ItemID; } else if (_equipInfo.Place == (int)RoleEquipType.mount) { ActorInfo.horseItemID = _equipInfo.ItemID; } m_SuitLevel = 0; if (_equipInfo.IsSuite == 1) { Dictionary> _userData = ConfigParse.Analysis(_equipInfo.UserData); if (_userData.ContainsKey(30)) { m_SuitLevel = (byte)_userData[30][0]; } } ChangeEquip(_equipInfo.Place, _equipInfo.ItemID, m_SuitLevel); } if (ActorInfo.horseItemID != 0 && m_H0434.PlayerState == 2) { OnHorse(1); } if (WeaponItemID == 0 || WeaponItemID == uint.MaxValue) { SwitchWeapon(0); } ActorInfo.LV = m_H0434.LV; ActorInfo.familyName = m_H0434.FamilyName; ActorInfo.ReincarnationLv = m_H0434.ReincarnationLv; ActorInfo.Job = m_H0434.Job; ActorInfo.realm = m_H0434.OfficialRank; ActorInfo.titleID = m_H0434.CurDienstgradID; ActorInfo.PlayerName = m_H0434.PlayerName; ActorInfo.teamID = m_H0434.TeamID; ActorInfo.familyID = m_H0434.FamilyID; ActorInfo.faction = m_H0434.Faction; ActorInfo.Hp = m_H0434.HP; ActorInfo.MaxHp = m_H0434.MaxHP; RequestName(); m_CmdManager = new CmdManager(); if (m_H0434.State == 1) { m_RecordBornPos = Pos; m_Step = 0; } } protected sealed override void OnUnit() { ShowOrHideModel(true); StatusMgr.Instance.ReleaseActor(ServerInstID); StopMoveToPosition(); m_CmdManager = null; m_H0434 = null; base.OnUnit(); } public override void Destroy() { } protected sealed override void OnUpdate() { base.OnUpdate(); if (m_CmdManager != null) { m_CmdManager.Update(); } // 脱机挂 if (m_H0434.State == 1) { switch (m_Step) { case 0: //m_DestPos = m_RecordBornPos + Quaternion.Euler(0, Random.Range(0, 359), 0) * Vector3.forward * Random.Range(1f, 2f); //TryGetValidPos(m_DestPos, ref m_DestPos); if (SelectTarget == null) { SelectTarget = GAMgr.Instance.GetCloserFightNpc(Pos); } if (SelectTarget != null) { destForward = Forward = MathUtility.ForwardXZ(SelectTarget.Pos, Pos); } m_Step = 1; break; case 1: m_CastSkill = null; for (int i = 0; i < JobSetup.HangupSkillList.Length; ++i) { if (SkillMgr.Get(JobSetup.HangupSkillList[i]).IsValid()) { m_CastSkill = SkillMgr.Get(JobSetup.HangupSkillList[i]); break; } } if (m_CastSkill == null) { if (m_ComAtkIndex > JobSetup.ComAtkIdList.Length - 1) { m_ComAtkIndex = 0; } int _comSkillId = JobSetup.ComAtkIdList[m_ComAtkIndex]; m_CastSkill = SkillMgr.Get(_comSkillId); m_ComAtkIndex += 1; } m_Step = 2; break; case 2: if (m_CastSkill != null) { SkillMgr.CastSkill(ServerInstID, m_CastSkill.id, true); Vector3 _targetPosition = Pos + Forward * (m_CastSkill.skillInfo.config.AtkDist * .5f); _targetPosition.y = 0; UnityEngine.AI.NavMeshHit _navMeshHit; if (UnityEngine.AI.NavMesh.Raycast(Pos, _targetPosition, out _navMeshHit, -1)) { _targetPosition = _navMeshHit.position; } _targetPosition.y = Pos.y; m_CastSkill.targetPosition = _targetPosition; if (m_CastSkill.skillInfo.config.Skillactmark > 0 && m_CastSkill.skillInfo.config.Skillactmark < 20) { switch (m_CastSkill.skillInfo.config.Skillactmark) { case 10: Play(GAStaticDefine.State_Attack1Hash, 0); break; case 11: Play(GAStaticDefine.State_Attack2Hash, 0); break; case 12: Play(GAStaticDefine.State_Attack3Hash, 0); break; case 13: Play(GAStaticDefine.State_Attack4Hash, 0); break; } } else { switch (m_CastSkill.skillInfo.config.Skillactmark) { case 21: Play(GAStaticDefine.State_Skill21, 0); break; case 22: Play(GAStaticDefine.State_Skill22, 0); break; case 23: Play(GAStaticDefine.State_Skill23, 0); break; case 24: Play(GAStaticDefine.State_Skill24, 0); break; case 25: Play(GAStaticDefine.State_Skill25, 0); break; case 26: Play(GAStaticDefine.State_Skill26, 0); break; case 27: Play(GAStaticDefine.State_Skill27, 0); break; case 28: Play(GAStaticDefine.State_Skill28, 0); break; case 29: Play(GAStaticDefine.State_Skill29, 0); break; case 99: Play(GAStaticDefine.State_RollHash, 0); break; } } } m_Step = 3; break; case 3: if (IsIdle()) { m_Step = 0; } break; } } } protected sealed override void OnLateUpdate() { base.OnLateUpdate(); UpdateMove(); } private bool m_StartMove; private Vector3 m_TargetPos; private bool m_MoveToFinalPos; private Vector3 _dir; public void MoveToPosition(Vector3 pos, float angle, float speed, bool startOrStop) { ActorInfo.moveSpeed = 500f / speed; m_StartMove = startOrStop; TryGetValidPos(pos, ref m_TargetPos); _dir = MathUtility.ForwardXZ(m_TargetPos, Pos); if (m_StartMove) { State = E_ActorState.AutoRun; Run(); } else { m_MoveToFinalPos = true; } } public void StopMoveToPosition() { m_StartMove = false; m_MoveToFinalPos = false; } private void UpdateMove() { if (SkillMgr.CurCastSkill != null) { if (!SkillMgr.CurCastSkill.SkillCompelete) { return; } if (SkillMgr.DoingPrepareSkill) { return; } if (IsRushing) { return; } } if (m_StartMove) { //if (_dir != Vector3.zero) //{ // Quaternion _quaternion = Quaternion.LookRotation(_dir, Vector3.up); // Rotation = Quaternion.RotateTowards(Rotation, _quaternion, GeneralConfig.Instance.RotateSpeed); // destForward = _dir; //} //Vector3 _pos = Pos + ActorInfo.moveSpeed * _dir * Time.deltaTime; //if (TryGetValidPos(_pos, ref _pos)) //{ // _pos.y = Pos.y; // Pos = _pos; //} if (MathUtility.DistanceSqrtXZ(Pos, m_TargetPos) > 0.1f) { MoveToPosition(m_TargetPos); } } else if (m_MoveToFinalPos) { MoveToPosition(m_TargetPos); if (MathUtility.DistanceSqrtXZ(Pos, m_TargetPos) < 0.01f) { Pos = new Vector3(m_TargetPos.x, Pos.y, m_TargetPos.z); m_MoveToFinalPos = false; Idle(); if (State == E_ActorState.AutoRun) { State = E_ActorState.Idle; } } } } protected sealed override void OnFixedUpdate() { base.OnFixedUpdate(); } protected sealed override void OnPutonClothes(uint clothesItemID, GameObject clothed) { clothed.layer = LayerUtility.Player; SkinnedMeshRenderer _renderer = clothed.GetComponentInChildren(); _renderer.gameObject.SetLayer(LayerUtility.Player, false); MaterialUtility.SwitchXrayShader(m_Material, false); } protected sealed override void OnPutonSecondary(uint secondaryItemID, GameObject secondary) { Renderer _renderer = secondary.GetComponent(); if (_renderer) { _renderer.gameObject.SetLayer(LayerUtility.Player, false); MaterialUtility.SwitchXrayShader(m_SecondaryMaterial, false); } } protected sealed override void OnPutonWeapon(uint weaponItemID, GameObject weapon) { Renderer _renderer = weapon.GetComponent(); if (_renderer) { _renderer.gameObject.SetLayer(LayerUtility.Player, false); MaterialUtility.SwitchXrayShader(m_WeaponMaterial, false); } } protected sealed override void OnPutonWing(uint wingItemID, GameObject wing) { SkinnedMeshRenderer _renderer = wing.GetComponentInChildren(); _renderer.gameObject.SetLayer(LayerUtility.Player, true); MaterialUtility.SwitchXrayShader(m_WingMaterial, false); } protected sealed override void OnSwitchHorse(uint horseID, GameObject horse) { horse.layer = LayerUtility.Player; SkinnedMeshRenderer _renderer = horse.GetComponentInChildren(); _renderer.gameObject.SetLayer(LayerUtility.Player, false); MaterialUtility.SwitchXrayShader(m_HorseMaterial, false); } public sealed override void OnHorse(byte upOrDown) { if (upOrDown == 1) { SwitchHorse(ActorInfo.horseItemID); } else { SwitchHorse(0); } } public sealed override void RequestName() { ReleaseName(); if (MovingState == E_MovingState.Ride) { m_HeadUpName = HeadUpName.RequireHeadUpName(HeadUpName.Pattern.Player, MP_Name1, 0, CameraController.Instance.CameraObject); } else { m_HeadUpName = HeadUpName.RequireHeadUpName(HeadUpName.Pattern.Player, MP_Name, 0, CameraController.Instance.CameraObject); } m_HeadUpName.SetPlayerInfo((int)ActorInfo.realm, ActorInfo.titleID, ActorInfo.PlayerName, ActorInfo.familyName, m_H0434.State == 1); if (StatusMgr.Instance.IsExist(ServerInstID, StatusMgr.Instance.bossBelongBuffID)) { m_HeadUpName.SetBossDropout(true); } base.SetFairyLeagueHeadUp(PlayerDatas.Instance.baseData.MapID == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON); } public sealed override void SwitchRedName(bool on) { if (PlayerDatas.Instance.baseData.MapID == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON) { return; } base.SwitchRedName(on); } public sealed override void SwitchYellowName(bool on) { if (PlayerDatas.Instance.baseData.MapID == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON) { return; } base.SwitchYellowName(on); } public sealed override void RefreshLifeBar(uint value) { GA_Hero _hero = PlayerDatas.Instance.hero; if (_hero != null && _hero.SelectTarget == this) { if (s_OnRefreshLife != null) { s_OnRefreshLife(ServerInstID, ActorInfo.RealHp, ActorInfo.RealMaxHp); } } } public sealed override bool CanAtked() { if (ActorInfo.serverDie) { return false; } if (PlayerDatas.Instance.maliciousAtkPlayer.Contains(ServerInstID)) { return true; } if (StatusMgr.Instance.IsInvisible(ServerInstID)) { return false; } GA_Hero _hero = PlayerDatas.Instance.hero; if ((E_AttackMode)PlayerDatas.Instance.baseData.AttackMode == E_AttackMode.Peace) { return false; } else if ((E_AttackMode)PlayerDatas.Instance.baseData.AttackMode == E_AttackMode.All) { return true; } else if ((E_AttackMode)PlayerDatas.Instance.baseData.AttackMode == E_AttackMode.Family) { // 判断队伍 if (ActorInfo.teamID != 0 && _hero.ActorInfo.teamID != 0 && ActorInfo.teamID == _hero.ActorInfo.teamID) { return false; } // 判断阵营 if (ActorInfo.faction != 0 && _hero.ActorInfo.faction != 0 && ActorInfo.faction == _hero.ActorInfo.faction) { return false; } // 判断仙盟 if (ActorInfo.familyID != 0 && _hero.ActorInfo.familyID != 0 && ActorInfo.familyID == _hero.ActorInfo.familyID) { return false; } if (StatusMgr.Instance.IsExist(ServerInstID, StatusMgr.Instance.redNameBuffID)) { return true; } } else if ((E_AttackMode)PlayerDatas.Instance.baseData.AttackMode == E_AttackMode.Country) { return false; } return true; } public override void Die() { base.Die(); StopMoveToPosition(); } public bool CanBeSelected() { if (ActorInfo.serverDie) { return false; } if (StatusMgr.Instance.IsInvisible(ServerInstID)) { return false; } return true; } public void OnClick() { if (ActorInfo.serverDie) { return; } GA_Hero _hero = PlayerDatas.Instance.hero; if (_hero == null) { return; } _hero.LockTarget = this; _hero.SelectTarget = this; } public void OnSelect() { if (CanAtked()) { SelectionManager.Request(SelectionManager.E_Type.Red, this); } else { SelectionManager.Request(SelectionManager.E_Type.Green, this); } if (s_OnSelected != null) { s_OnSelected(ServerInstID, true); } } public void OnUnSelect() { SelectionManager.Release(SelectionManager.E_Type.Green); SelectionManager.Release(SelectionManager.E_Type.Red); if (s_OnSelected != null) { s_OnSelected(ServerInstID, false); } } public void Cmd_0614(H0614_tagUseSkillPos h0614) { Cmd0614 _cmd = new Cmd0614(); _cmd.Init(h0614); m_CmdManager.Enqueue(_cmd); } public void Cmd_B402(HB402_tagMCRush hb402) { CmdB402 _cmd = new CmdB402(); _cmd.Init(hb402); m_CmdManager.Enqueue(_cmd); } public void Cmd_0501(H0501_tagObjMove h0501) { Cmd0501 _cmd = new Cmd0501(); _cmd.Init(h0501); m_CmdManager.Enqueue(_cmd); } public void ClearAllCMD() { m_CmdManager.Clear(); } }