using System.Collections.Generic; using Snxxz.UI; using UnityEngine; using UnityEngine.Events; public class GA_Player : GActorPlayerBase, IOtherSelectable { // 为守护特殊定义的当前是否装备守护id public int serverGuardId; public static UnityAction s_OnSelected; public static UnityAction s_OnRefreshLife; private static Dictionary>> m_StaticOffLineSkllList = new Dictionary>>(); private int[] m_OffLineSkillList; protected H0434_tagAreaPlayerAppearEx m_H0434; private CmdManager m_CmdManager; private int m_ComAtkIndex;// 普攻索引 protected 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); ActorInfo.serverBornPos = new Vector2(m_H0434.PosX, m_H0434.PosY); // 计算移动速度 CalculateMoveSpeed(m_H0434.Speed); CalculateAtkSpeed((ushort)m_H0434.AtkInterval); // 处理职业配置 JobSetup = JobSetupConfig.Get(m_H0434.Job); // 处理装备 H0434_tagAreaPlayerAppearEx.tagEquipInfo _equipInfo; Dictionary> _userDataDict; EquipInfo _info; // 因为衣服是所有装备的父节点, 需要预先处理衣服 for (int i = 0; i < m_H0434.EquipCount; ++i) { _equipInfo = m_H0434.EquipInfo[i]; _info = new EquipInfo { itemID = _equipInfo.ItemID }; if (_equipInfo.UserDataLen > 2) { _userDataDict = ConfigParse.Analysis(_equipInfo.UserData); if (_userDataDict != null && _userDataDict.ContainsKey(25)) { _info.suitLV_1 = (byte)_userDataDict[25][0]; _info.suitLV_2 = (byte)_userDataDict[25][1]; } } m_EquipDict[_equipInfo.Place] = _info; if (_equipInfo.Place == (byte)RoleEquipType.retFashionClothes) { SwitchClothes(_equipInfo.ItemID, _equipInfo.Place); } else if (_equipInfo.Place == (byte)RoleEquipType.retClothes) { SwitchClothes(_equipInfo.ItemID); } } // 如果没有任何衣服, 则穿上默认装备 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.retFashionWeapon) { SwitchWeapon(_equipInfo.ItemID, _equipInfo.Place); continue; } else if (_equipInfo.Place == (int)RoleEquipType.retWeapon) { SwitchWeapon(_equipInfo.ItemID); continue; } if (_equipInfo.Place == (int)RoleEquipType.retFashionWeapon2) { SwitchSecondary(_equipInfo.ItemID, _equipInfo.Place); continue; } else if (_equipInfo.Place == (int)RoleEquipType.retWeapon2) { SwitchSecondary(_equipInfo.ItemID); continue; } if (_equipInfo.Place == (int)RoleEquipType.retWing) { SwitchWing(_equipInfo.ItemID); } else if (_equipInfo.Place == (int)RoleEquipType.retSpiritAnimal) { var _index = BattleEffectPlayRule.Instance.GetIndex(ServerInstID); if (_index != -1 && _index < BattleEffectPlayRule.Instance.petLimit) { SwitchGuard(_equipInfo.ItemID); } serverGuardId = (int)_equipInfo.ItemID; } else if (_equipInfo.Place == (int)RoleEquipType.mount) { ActorInfo.horseItemID = _equipInfo.ItemID; } } SyncSuitEffect(); if (ActorInfo.horseItemID != 0 && m_H0434.PlayerState == 2) { OnHorse(1); } if (WeaponItemID == 0 || WeaponItemID == uint.MaxValue) { SwitchWeapon(0); } if (SecondaryID == 0 || SecondaryID == uint.MaxValue) { SwitchSecondary(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; if (s_OnRefreshLife != null) { s_OnRefreshLife(ServerInstID, ActorInfo.RealHp, ActorInfo.RealMaxHp); } RequestName(); m_CmdManager = new CmdManager(); if (m_H0434.State == 1) { if (!m_StaticOffLineSkllList.ContainsKey(m_H0434.Job)) { m_StaticOffLineSkllList.Add(m_H0434.Job, new Dictionary>()); var _json = LitJson.JsonMapper.ToObject(JobSetup.OffLineSkillList); foreach (var _level in _json.Keys) { var _list = new List(); for (int i = 0; i < _json[_level].Count; ++i) { _list.Add((int)_json[_level][i]); } m_StaticOffLineSkllList[m_H0434.Job].Add(int.Parse(_level), _list); } } foreach (var _level in m_StaticOffLineSkllList[m_H0434.Job].Keys) { if (m_H0434.LV < _level) { m_OffLineSkillList = m_StaticOffLineSkllList[m_H0434.Job][_level].ToArray(); break; } } } } public override void SyncSuitEffect() { var _suitCount = 0; int _start = (int)RoleEquipType.retHat; int _end = (int)RoleEquipType.retShoes; int _rank = 0; EquipInfo _equipInfo; // 先取得衣服的阶数 if (!m_EquipDict.TryGetValue((int)RoleEquipType.retClothes, out _equipInfo)) { return; } var _itemConfig = ItemConfig.Get((int)_equipInfo.itemID); _rank = _itemConfig.LV; for (int i = _start; i <= _end; ++i) { if (!m_EquipDict.TryGetValue(i, out _equipInfo)) { continue; } if (_equipInfo.suitLV_1 > 0 || _equipInfo.suitLV_2 > 0) { _itemConfig = ItemConfig.Get((int)_equipInfo.itemID); if (_itemConfig.LV >= _rank) { _suitCount += 1; } } } if (m_SuitCount == _suitCount) { return; } if (m_SuitCount < 5 && _suitCount < 5) { m_SuitCount = _suitCount; return; } // Debug.Log("_suitCount: " + _suitCount); if (_suitCount == 5) { _itemConfig = ItemConfig.Get((int)ClothesItemID); if (_itemConfig != null) { var _newMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, true); if (_newMat) { MaterialLoader.Release(m_SMRenderer.material); m_SMRenderer.material = m_Material = _newMat; MaterialUtility.SwitchXrayShader(m_SMRenderer.material, false); } } } else { _itemConfig = ItemConfig.Get((int)ClothesItemID); if (_itemConfig != null) { var _newMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, false); if (_newMat) { MaterialLoader.Release(m_SMRenderer.material); m_SMRenderer.material = m_Material = _newMat; MaterialUtility.SwitchXrayShader(m_SMRenderer.material, false); } } } m_SuitCount = _suitCount; } protected sealed override void OnUnit() { ShowOrHideModel(true); StatusMgr.Instance.ReleaseActor(ServerInstID); StopMoveToPosition(); m_CmdManager = null; m_H0434 = null; m_OffLineSkillList = null; base.OnUnit(); } public override void Destroy() { } protected override void OnUpdate() { base.OnUpdate(); if (m_CmdManager != null) { m_CmdManager.Update(); } } 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, GeneralDefine.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(); } public void UpdateData(H0418_tagObjInfoRefresh data) { int _level = 0; switch ((PlayerDataRefresh)data.RefreshType) { case PlayerDataRefresh.EquipShowSwitch: m_H0434.EquipShowSwitch = data.Value; _level = (int)m_H0434.ExAttr18; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 4, out _level)) { SwitchGodWeapon(4, _level); } else { SwitchGodWeapon(4, 0); } _level = (int)m_H0434.ExAttr15; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 1, out _level)) { SwitchGodWeapon(1, _level); } else { SwitchGodWeapon(1, 0); } _level = (int)m_H0434.ExAttr16; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 2, out _level)) { SwitchGodWeapon(2, _level); } else { SwitchGodWeapon(2, 0); } break; case PlayerDataRefresh.CDBPlayerRefresh_GodWeaponLV_1: _level = (int)data.Value; m_H0434.ExAttr15 = data.Value; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 1, out _level)) { SwitchGodWeapon(1, _level); } else { SwitchGodWeapon(1, 0); } break; case PlayerDataRefresh.CDBPlayerRefresh_GodWeaponLV_2: _level = (int)data.Value; m_H0434.ExAttr16 = data.Value; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 2, out _level)) { SwitchGodWeapon(2, _level); } else { SwitchGodWeapon(2, 0); } break; case PlayerDataRefresh.CDBPlayerRefresh_GodWeaponLV_3: _level = (int)data.Value; m_H0434.ExAttr17 = data.Value; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 3, out _level)) { SwitchGodWeapon(3, _level); } else { SwitchGodWeapon(3, 0); } break; case PlayerDataRefresh.CDBPlayerRefresh_GodWeaponLV_4: _level = (int)data.Value; m_H0434.ExAttr18 = data.Value; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 4, out _level)) { SwitchGodWeapon(4, _level); } else { SwitchGodWeapon(4, 0); } break; } } 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); int _level = (int)m_H0434.ExAttr18; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 4, out _level)) { SwitchGodWeapon(4, _level); } else { SwitchGodWeapon(4, 0); } _level = (int)m_H0434.ExAttr15; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 1, out _level)) { SwitchGodWeapon(1, (int)m_H0434.ExAttr15); } else { SwitchGodWeapon(1, 0); } _level = (int)m_H0434.ExAttr16; if (EquipShowSwitch.IsGodWeaponEffectOn(m_H0434.EquipShowSwitch, 2, out _level)) { SwitchGodWeapon(2, (int)m_H0434.ExAttr16); } else { SwitchGodWeapon(2, 0); } } protected sealed override void OnPutonSecondary(uint secondaryItemID, GameObject secondary) { if(!secondary) { return; } 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 override void ShowGodWeaponEffect() { SwitchGodWeapon(1, (int)m_H0434.ExAttr15); SwitchGodWeapon(2, (int)m_H0434.ExAttr16); SwitchGodWeapon(4, (int)m_H0434.ExAttr18); } 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); } var titleId = PlayerDatas.Instance.baseData.MapID == 31160 ? 0 : ActorInfo.titleID; m_HeadUpName.SetPlayerInfo((int)ActorInfo.realm, 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); CheckAncientHeadUp(); } 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(ulong value) { // Debug.LogFormat("{0} 血量改变: {1}", ServerInstID, value); GA_Hero _hero = PlayerDatas.Instance.hero; if (_hero != null && (_hero.SelectTarget == this || CrossServerUtility.IsCrossServer())) { 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(); } public void UpdateOffLineAction() { if (!IsIdle()) { return; } if (SelectTarget == null) { SelectTarget = GAMgr.Instance.GetCloserFightNpc(Pos); } if (SelectTarget != null) { destForward = Forward = MathUtility.ForwardXZ(SelectTarget.Pos, Pos); } Skill _castSkill = null; int _skillIndex = UnityEngine.Random.Range(0, m_OffLineSkillList.Length); if (SkillMgr.Get(m_OffLineSkillList[_skillIndex]).IsValid()) { _castSkill = SkillMgr.Get(m_OffLineSkillList[_skillIndex]); } if (_castSkill == null) { if (m_ComAtkIndex > JobSetup.ComAtkIdList.Length - 1) { m_ComAtkIndex = 0; } int _comSkillId = JobSetup.ComAtkIdList[m_ComAtkIndex]; _castSkill = SkillMgr.Get(_comSkillId); m_ComAtkIndex += 1; } if (_castSkill != null) { SkillMgr.CastSkill(ServerInstID, _castSkill.id, true); Vector3 _targetPosition = Pos + Forward * (_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; _castSkill.targetPosition = _targetPosition; if (_castSkill.skillInfo.config.Skillactmark > 0 && _castSkill.skillInfo.config.Skillactmark < 20) { switch (_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 (_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; } } } } }