少年修仙传客户端代码仓库
client_Hale
2019-03-18 bdac52e01035a49bf3d5feefa6b2a28a3db06e86
6362 【前端】【2.0】飞跃的功能和跨地图NPC寻路功能
5个文件已修改
258 ■■■■ 已修改文件
Fight/GameActor/GA_Hero.cs 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/GameActor/GA_Player.cs 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/MapTransferUtility.cs 193 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/Stage/Dungeon/DungeonStage.cs 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/Stage/Dungeon/MapTransfer.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/GameActor/GA_Hero.cs
@@ -183,30 +183,23 @@
            return;
        }
        if (onOrOff)
        {
            var _itemConfig = ItemConfig.Get((int)ClothesItemID);
            if (_itemConfig != null)
            {
                var _newMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, true);
                if (_newMat)
            Material _replaceMat = null;
            if (onOrOff)
                {
                    m_SMRenderer.material = m_Material = _newMat;
                    MaterialUtility.SwitchXrayShader(m_SMRenderer.material, this is GA_Hero);
                }
            }
                _replaceMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, true);
        }
        else
        {
            var _itemConfig = ItemConfig.Get((int)ClothesItemID);
            if (_itemConfig != null)
            {
                var _newMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, false);
                if (_newMat)
                {
                    m_SMRenderer.material = m_Material = _newMat;
                    MaterialUtility.SwitchXrayShader(m_SMRenderer.material, this is GA_Hero);
                _replaceMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, false);
                }
            if (_replaceMat)
            {
                MaterialLoader.Release(m_SMRenderer.material);
                m_SMRenderer.material = m_Material = _replaceMat;
                MaterialUtility.SwitchXrayShader(m_SMRenderer.material, true);
            }
        }
Fight/GameActor/GA_Player.cs
@@ -214,30 +214,22 @@
        // Debug.Log("_suitCount: " + _suitCount);
        var _itemConfig = ItemConfig.Get((int)ClothesItemID);
        if (onOrOff)
        {
            if (_itemConfig != null)
            {
                var _newMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, true);
                if (_newMat)
            Material _replaceMat = null;
            if (onOrOff)
                {
                    MaterialLoader.Release(m_SMRenderer.material);
                    m_SMRenderer.material = m_Material = _newMat;
                    MaterialUtility.SwitchXrayShader(m_SMRenderer.material, false);
                }
            }
                _replaceMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, true);
        }
        else
        {
            if (_itemConfig != null)
            {
                var _newMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, false);
                if (_newMat)
                _replaceMat = MaterialLoader.LoadClothesMaterial(_itemConfig.ChangeOrd, false, false);
            }
            if (_replaceMat)
                {
                    MaterialLoader.Release(m_SMRenderer.material);
                    m_SMRenderer.material = m_Material = _newMat;
                m_SMRenderer.material = m_Material = _replaceMat;
                    MaterialUtility.SwitchXrayShader(m_SMRenderer.material, false);
                }
            }
        }
Fight/MapTransferUtility.cs
@@ -37,6 +37,9 @@
    private float m_ClosedFuncNpcDistSqrt;
    public float conversationDistSqrt;
    private List<maptransportConfig> m_MapTransportCfgs;
    private List<int> m_TransMapLine = new List<int>();
    public void Initialize()
    {
        FuncConfigConfig _funcModel = FuncConfigConfig.Get("ConversationDistanc");
@@ -47,10 +50,56 @@
            m_ClosedFuncNpcDistSqrt = float.Parse(_funcModel.Numerical2);
            m_ClosedFuncNpcDistSqrt *= m_ClosedFuncNpcDistSqrt;
        }
        m_MapTransportCfgs = maptransportConfig.GetValues();
        m_TransMapLine.Clear();
        var _id = 122549;
        var _configs = maptransportConfig.Get(_id);
        m_TransMapLine.Add(_configs.OriginalMapID);
        while (true)
        {
            if (!m_TransMapLine.Contains(_configs.TargetMapID))
            {
                m_TransMapLine.Add(_configs.TargetMapID);
            }
            else
            {
                break;
            }
            var _nextID = GetMapID(_configs.TargetMapID, _configs.OriginalMapID);
            if (_nextID == -1)
            {
                break;
            }
            _configs = maptransportConfig.Get(_nextID);
        }
        conversationDistSqrt = conversationDistSqrt == 0 ? 6 : conversationDistSqrt;
        m_ClosedFuncNpcDistSqrt = m_ClosedFuncNpcDistSqrt == 0 ? 1 : m_ClosedFuncNpcDistSqrt;
    }
    private int GetMapID(int start, int target)
    {
        var _configs = maptransportConfig.GetValues();
        foreach (var _cfg in _configs)
        {
            if (_cfg.OriginalMapID == start && _cfg.TargetMapID != target)
            {
                return _cfg.TransportID;
            }
        }
        return -1;
    }
    private int GetNextTransportID(int start, int end)
    {
        foreach (var _cfg in m_MapTransportCfgs)
        {
            if (_cfg.OriginalMapID == start && _cfg.TargetMapID == end)
            {
                return _cfg.TransportID;
            }
        }
        return -1;
    }
    #region 打坐
@@ -191,6 +240,9 @@
    public void MoveToNPC(int _npcID, int _sid = 0)
    {
#if UNITY_EDITOR
        Debug.LogFormat("想要切换至目标npc: {0}", _npcID);
#endif
        StopCoroutine("CoMoveToNPC");
        var _data = new MoveToData
        {
@@ -208,29 +260,30 @@
            yield break;
        }
        var npcID = data.npcID;
        var sid = data.sid;
        NpcID = data.npcID;
        MapTransferDoType = E_MapTransferDoType.Npc;
        Vector3 _destPostion = Vector3.zero;
        // 判断是否能够得到到达指定点
        // 获取NPC位置数据
        GAStaticDefine.NPCLocation _npcLocation;
        var _findLocation = GAStaticDefine.TryGetMapNPCLocation(npcID, out _npcLocation);
        var _findLocation = GAStaticDefine.TryGetMapNPCLocation(NpcID, out _npcLocation);
        if (!_findLocation)
        {
#if UNITY_EDITOR
            Debug.LogWarningFormat("需要传送至的npcid有错,无法在mapnpc表中查询到, id: {0}", npcID);
            Debug.LogWarningFormat("需要传送至的npcid有错,无法在mapnpc表中查询到, id: {0}", NpcID);
#endif
            // 如果找不到配置, 可能为客户端战斗配置的刷怪逻辑
            // 由于可能有回包慢问题, 这里等待
            yield return WaitingForSecondConst.WaitMS200;
            GActor _npc = GAMgr.Instance.GetCloserNPC(_hero.Pos, npcID);
            GActor _npc = GAMgr.Instance.GetCloserNPC(_hero.Pos, NpcID);
            if (_npc != null)
            {
                _destPostion = _npc.Pos;
                NpcID = npcID;
                NpcID = NpcID;
                MapTransferDoType = E_MapTransferDoType.Npc;
                _hero.MoveToPosition(_destPostion);
@@ -239,43 +292,59 @@
        }
        else
        {
            _destPostion = new Vector3(_npcLocation.position.x, 0, _npcLocation.position.y);
            // 判断是否在同一张地图中
            if (_npcLocation.mapId != PlayerDatas.Instance.baseData.MapID)
            {
                _MoveToNPC(npcID, sid);
                yield break;
                int _idx1 = m_TransMapLine.IndexOf(PlayerDatas.Instance.baseData.MapID);
                int _idx2 = m_TransMapLine.IndexOf(_npcLocation.mapId);
                bool _valid = true;
                if (_idx1 == -1)
                {
                    _valid = false;
                    Debug.LogErrorFormat("寻找的地图ID不在线路中: {0}", PlayerDatas.Instance.baseData.MapID);
            }
                if (_idx2 == -1)
                {
                    _valid = false;
                    Debug.LogErrorFormat("寻找的地图ID不在线路中: {0}", _npcLocation.mapId);
                }
                if (_valid)
                {
                    int _nextMapID = -1;
                    // 顺序
                    if (_idx2 > _idx1)
                    {
                        _nextMapID = m_TransMapLine[_idx1 + 1];
                    }
                    // 逆序
                    else
                    {
                        _nextMapID = m_TransMapLine[_idx1 - 1];
        }
        if (_destPostion == Vector3.zero)
                    // 先寻找传送点
                    int _transportID = GetNextTransportID(PlayerDatas.Instance.baseData.MapID,
                                                          _nextMapID);
                    if (_transportID != -1)
        {
            Debug.LogErrorFormat("移动至NPC: {0} 时找不到一个可以到达的点.", npcID);
            yield break;
        }
        float _dist = 0.01f;
        var _config = NPCConfig.Get(npcID);
        if (_config != null)
                        var _curStage = StageLoad.Instance.currentStage as DungeonStage;
                        if (_curStage)
        {
            _dist = Mathf.Max(GeneralDefine.CloseNpcDist + _config.ModelRadius - 0.3f, 0);
        }
        if (PathFinder.WalkAble(_hero.Pos, _destPostion, _dist) || npcID == 32504001)
        {
            _MoveToNPC(npcID, sid);
        }
        else
                            Vector3 _moveToPos;
                            if (_curStage.TryGetTransportPosition(_transportID, out _moveToPos))
        {
            while (true)
            {
                if (PathFinder.WalkAble(_hero.Pos, _destPostion, _dist))
                                    if (PathFinder.WalkAble(_hero.Pos, _moveToPos))
                {
                    break;
                }
                var _nextPos = ClientSceneManager.Instance.GetTransPoint(_hero.Pos, _destPostion);
                                    var _nextPos = ClientSceneManager.Instance.GetTransPoint(_hero.Pos, _moveToPos);
                // 如果找到的下一个点
                if (!PathFinder.WalkAble(_hero.Pos, _nextPos)
                 || _nextPos == Vector3.zero)
                {
                    Debug.LogErrorFormat("移动至NPC: {0} 时找不到任何跳跃点", npcID);
                                        Debug.LogErrorFormat("移动至NPC: {0} 时找不到任何跳跃点", NpcID);
                    break;
                }
                float _dis = MathUtility.DistanceSqrtXZ(_hero.Pos, _nextPos);
@@ -294,7 +363,66 @@
                    yield return null;
                }
            }
            _MoveToNPC(npcID, sid);
                                _hero.MoveToPosition(_moveToPos);
                                yield break;
                            }
                        }
                    }
                }
                _MoveToNPC(NpcID, sid);
                yield break;
            }
            _destPostion = new Vector3(_npcLocation.position.x, 0, _npcLocation.position.y);
        }
        if (_destPostion == Vector3.zero)
        {
            Debug.LogErrorFormat("移动至NPC: {0} 时找不到一个可以到达的点.", NpcID);
            yield break;
        }
        float _dist = 0.01f;
        var _config = NPCConfig.Get(NpcID);
        if (_config != null)
        {
            _dist = Mathf.Max(GeneralDefine.CloseNpcDist + _config.ModelRadius - 0.3f, 0);
        }
        if (PathFinder.WalkAble(_hero.Pos, _destPostion, _dist) || NpcID == 32504001)
        {
            _MoveToNPC(NpcID, sid);
        }
        else
        {
            while (true)
            {
                if (PathFinder.WalkAble(_hero.Pos, _destPostion, _dist))
                {
                    break;
                }
                var _nextPos = ClientSceneManager.Instance.GetTransPoint(_hero.Pos, _destPostion);
                // 如果找到的下一个点
                if (!PathFinder.WalkAble(_hero.Pos, _nextPos)
                 || _nextPos == Vector3.zero)
                {
                    Debug.LogErrorFormat("移动至NPC: {0} 时找不到任何跳跃点", NpcID);
                    break;
                }
                float _dis = MathUtility.DistanceSqrtXZ(_hero.Pos, _nextPos);
                while (_dis > 0.01f)
                {
                    _dis = MathUtility.DistanceSqrtXZ(_hero.Pos, _nextPos);
                    _hero.MoveToPosition(_nextPos);
                    yield return null;
                }
                while (!GA_Hero.s_Flying)
                {
                    yield return null;
                }
                while (GA_Hero.s_Flying)
                {
                    yield return null;
                }
            }
            _MoveToNPC(NpcID, sid);
        }
    }
@@ -325,10 +453,6 @@
        {
            return;
        }
#if UNITY_EDITOR
        Debug.LogFormat("想要切换至目标npc: {0}", npcID);
#endif
        m_DelayMoveToNPC = false;
        m_TempNpcID = 0;
@@ -1034,6 +1158,10 @@
                _hero.Behaviour.StartHandupAI();
                Clear();
            }
            else
            {
                Debug.LogFormat("_npc == null : {0}, _chkDistSqrt < Mathf.Pow(_fightConfigDist, 2): {1}", _npc == null, _chkDistSqrt < Mathf.Pow(_fightConfigDist, 2));
            }
        }
        else if (_npcConfig.NPCType == (int)E_NpcType.Collect
              || _npcConfig.NPCType == (int)E_NpcType.Flag)
@@ -1103,12 +1231,13 @@
    public void Clear()
    {
        StopCoroutine("CoMoveToNPC");
        if (m_SwitchMapFinished)
        {
            StopCoroutine("CoMoveToNPC");
            NpcID = 0;
            MapTransferDoType = E_MapTransferDoType.None;
            m_DelayMoveToNPC = false;
        }
    }
}
Fight/Stage/Dungeon/DungeonStage.cs
@@ -9,6 +9,7 @@
{
    public static Dictionary<MapArea.E_Type, List<MapArea>> s_MapAreaDict;
    public static MapType CurrentMapType;
    private static Dictionary<int, MapTransfer> s_MapTransferDict = new Dictionary<int, MapTransfer>();
    public override void Initialize()
    {
@@ -117,7 +118,7 @@
        base.UnInitialize();
        StopAllCoroutines();
        s_MapTransferDict.Clear();
        if (s_MapAreaDict != null)
        {
            foreach (var _list in s_MapAreaDict.Values)
@@ -279,6 +280,7 @@
    private void CreateMapTransfer()
    {
        s_MapTransferDict.Clear();
        // 创建传送点
        var _dict = maptransportConfig.GetValues();
        foreach (var _item in _dict)
@@ -326,9 +328,21 @@
            MapTransfer _maptransfer = _transport.AddMissingComponent<MapTransfer>();
            _maptransfer.transportModel = _item;
            _maptransfer.TransportID = _item.TransportID;
            s_MapTransferDict[_item.TransportID] = _maptransfer;
        }
    }
    public bool TryGetTransportPosition(int id, out Vector3 pos)
    {
        if (s_MapTransferDict.ContainsKey(id))
        {
            pos = s_MapTransferDict[id].transform.position;
            return true;
        }
        pos = Vector3.zero;
        return false;
    }
    private IEnumerator CreateMapArea()
    {
        yield return WaitingForSecondConst.WaitMS200;
Fight/Stage/Dungeon/MapTransfer.cs
@@ -64,7 +64,7 @@
            return;
        }
        MapTransferUtility.Instance.Clear();
        // MapTransferUtility.Instance.Clear();
        _hero.IdleImmediate();
        _hero.Behaviour.StopHandupAI();
        _hero.Behaviour.StopKillUntilDieAI();