From bdac52e01035a49bf3d5feefa6b2a28a3db06e86 Mon Sep 17 00:00:00 2001
From: client_Hale <339726288@qq.com>
Date: 星期一, 18 三月 2019 16:40:53 +0800
Subject: [PATCH] 6362 【前端】【2.0】飞跃的功能和跨地图NPC寻路功能

---
 Fight/MapTransferUtility.cs |  167 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 148 insertions(+), 19 deletions(-)

diff --git a/Fight/MapTransferUtility.cs b/Fight/MapTransferUtility.cs
index 531f756..afa0f4a 100644
--- a/Fight/MapTransferUtility.cs
+++ b/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("鎯宠鍒囨崲鑷崇洰鏍噉pc: {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("闇�瑕佷紶閫佽嚦鐨刵pcid鏈夐敊,鏃犳硶鍦╩apnpc琛ㄤ腑鏌ヨ鍒�, id: {0}", npcID);
+            Debug.LogWarningFormat("闇�瑕佷紶閫佽嚦鐨刵pcid鏈夐敊,鏃犳硶鍦╩apnpc琛ㄤ腑鏌ヨ鍒�, 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("瀵绘壘鐨勫湴鍥綢D涓嶅湪绾胯矾涓�: {0}", PlayerDatas.Instance.baseData.MapID);
+                }
+                if (_idx2 == -1)
+                {
+                    _valid = false;
+                    Debug.LogErrorFormat("瀵绘壘鐨勫湴鍥綢D涓嶅湪绾胯矾涓�: {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("绉诲姩鑷砃PC: {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("绉诲姩鑷砃PC: {0} 鏃舵壘涓嶅埌涓�涓彲浠ュ埌杈剧殑鐐�.", npcID);
+            Debug.LogErrorFormat("绉诲姩鑷砃PC: {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("绉诲姩鑷砃PC: {0} 鏃舵壘涓嶅埌浠讳綍璺宠穬鐐�", npcID);
+                    Debug.LogErrorFormat("绉诲姩鑷砃PC: {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("鎯宠鍒囨崲鑷崇洰鏍噉pc: {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;
         }
     }
+
 }

--
Gitblit v1.8.0