少年修仙传客户端代码仓库
client_Hale
2019-03-18 bdac52e01035a49bf3d5feefa6b2a28a3db06e86
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,28 +292,103 @@
        }
        else
        {
            _destPostion = new Vector3(_npcLocation.position.x, 0, _npcLocation.position.y);
            // 判断是否在同一张地图中
            if (_npcLocation.mapId != PlayerDatas.Instance.baseData.MapID)
            {
                _MoveToNPC(npcID, sid);
                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];
                    }
                    // 先寻找传送点
                    int _transportID = GetNextTransportID(PlayerDatas.Instance.baseData.MapID,
                                                          _nextMapID);
                    if (_transportID != -1)
                    {
                        var _curStage = StageLoad.Instance.currentStage as DungeonStage;
                        if (_curStage)
                        {
                            Vector3 _moveToPos;
                            if (_curStage.TryGetTransportPosition(_transportID, out _moveToPos))
                            {
                                while (true)
                                {
                                    if (PathFinder.WalkAble(_hero.Pos, _moveToPos))
                                    {
                                        break;
                                    }
                                    var _nextPos = ClientSceneManager.Instance.GetTransPoint(_hero.Pos, _moveToPos);
                                    // 如果找到的下一个点
                                    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;
                                    }
                                }
                                _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);
            Debug.LogErrorFormat("移动至NPC: {0} 时找不到一个可以到达的点.", NpcID);
            yield break;
        }
        float _dist = 0.01f;
        var _config = NPCConfig.Get(npcID);
        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)
        if (PathFinder.WalkAble(_hero.Pos, _destPostion, _dist) || NpcID == 32504001)
        {
            _MoveToNPC(npcID, sid);
            _MoveToNPC(NpcID, sid);
        }
        else
        {
@@ -275,7 +403,7 @@
                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 +422,7 @@
                    yield return null;
                }
            }
            _MoveToNPC(npcID, sid);
            _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;
        }
    }
}