From 4534825e23c2dac117e8de04d3bb1eae64dffd33 Mon Sep 17 00:00:00 2001
From: client_Hale <339726288@qq.com>
Date: 星期一, 25 三月 2019 21:08:01 +0800
Subject: [PATCH] 382 寻路逻辑增加又可跳跃又可走到的目标点的距离检测判断

---
 Fight/MapTransferUtility.cs                      |   28 ++++++
 Fight/Stage/MapEditor/Game/ClientSceneManager.cs |  171 ++++++++++++++++++++++++++++++++++++++++++
 Core/AI/NavmeshPathFind/PathFinder.cs            |   17 ++++
 3 files changed, 215 insertions(+), 1 deletions(-)

diff --git a/Core/AI/NavmeshPathFind/PathFinder.cs b/Core/AI/NavmeshPathFind/PathFinder.cs
index 960e868..5e443a1 100644
--- a/Core/AI/NavmeshPathFind/PathFinder.cs
+++ b/Core/AI/NavmeshPathFind/PathFinder.cs
@@ -27,6 +27,23 @@
         return false;
     }
 
+    public static float CalculateDistance(Vector3 start, Vector3 dest)
+    {
+        float _dis = float.MaxValue;
+        start.y = 0;
+        dest.y = 0;
+        NavMesh.CalculatePath(start, dest, -1, _path);
+        if (_path.corners != null && _path.corners.Length > 1)
+        {
+            _dis = 0;
+            for (int i = 0; i < _path.corners.Length - 1; ++i)
+            {
+                _dis += Vector3.Distance(_path.corners[i], _path.corners[i + 1]);
+            }
+        }
+        return _dis;
+    }
+
     public static bool TryGetValidDest(Vector3 start, Vector3 dest, ref Vector3 validDest)
     {
         dest = AdjustPosition(dest);
diff --git a/Fight/MapTransferUtility.cs b/Fight/MapTransferUtility.cs
index afa0f4a..2c2471e 100644
--- a/Fight/MapTransferUtility.cs
+++ b/Fight/MapTransferUtility.cs
@@ -266,6 +266,8 @@
 
         Vector3 _destPostion = Vector3.zero;
 
+        var _curStage = StageLoad.Instance.currentStage as DungeonStage;
+
         // 鍒ゆ柇鏄惁鑳藉寰楀埌鍒拌揪鎸囧畾鐐�
         // 鑾峰彇NPC浣嶇疆鏁版嵁
         GAStaticDefine.NPCLocation _npcLocation;
@@ -327,7 +329,6 @@
                                                           _nextMapID);
                     if (_transportID != -1)
                     {
-                        var _curStage = StageLoad.Instance.currentStage as DungeonStage;
                         if (_curStage)
                         {
                             Vector3 _moveToPos;
@@ -380,14 +381,39 @@
             Debug.LogErrorFormat("绉诲姩鑷砃PC: {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)
         {
+            while (true)
+            {
+                Vector3 _nextPos = ClientSceneManager.Instance.GetNext1(_hero.Pos, _destPostion);
+                if (_nextPos == Vector3.zero)
+                {
+                    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);
         }
         else
diff --git a/Fight/Stage/MapEditor/Game/ClientSceneManager.cs b/Fight/Stage/MapEditor/Game/ClientSceneManager.cs
index 4e7a52f..3712f2b 100644
--- a/Fight/Stage/MapEditor/Game/ClientSceneManager.cs
+++ b/Fight/Stage/MapEditor/Game/ClientSceneManager.cs
@@ -251,6 +251,7 @@
     }
 
     private List<MapTrasfer> m_ChkedList = new List<MapTrasfer>();
+    private List<MapTrasfer> m_ChkedList1 = new List<MapTrasfer>();
 
     public Vector3 GetTransPoint(Vector3 start, Vector3 next)
     {
@@ -259,6 +260,176 @@
         return GetNext(start, next);
     }
 
+    public Vector3 GetNext1(Vector3 start, Vector3 dest)
+    {
+        m_ChkedList1.Clear();
+
+        if (PathFinder.WalkAble(start, dest))
+        {
+            float _dis = PathFinder.CalculateDistance(start, dest);
+            Debug.Log("寰楀嚭鐨勮窛绂诲钩鏂逛负: " + _dis);
+
+            int _chkTransID = -1;
+            int _chkIndex = -1;
+            float _compareDis = float.MaxValue;
+            float _chkDis1;
+            float _chkDis2;
+            float _totalDis = 0;
+            foreach (var _t in m_MapData.transfers)
+            {
+                if (_t.transferPoints.Length >= 2)
+                {
+                    if (!PathFinder.WalkAble(_t.transferPoints[0].position, dest)
+                     && !PathFinder.WalkAble(_t.transferPoints[_t.transferPoints.Length - 1].position, dest))
+                    {
+                        continue;
+                    }
+
+                    _chkDis1 = Vector3.Distance(_t.transferPoints[0].position, dest);
+                    _chkDis2 = Vector3.Distance(_t.transferPoints[_t.transferPoints.Length - 1].position, dest);
+
+                    if (_chkDis1 > _compareDis && _chkDis2 > _compareDis)
+                    {
+                        continue;
+                    }
+
+                    if (_chkDis1 < _chkDis2)
+                    {
+                        _compareDis = _chkDis1;
+                        _chkIndex = 0;
+                    }
+                    else
+                    {
+                        _compareDis = _chkDis2;
+                        _chkIndex = _t.transferPoints.Length - 1;
+                    }
+                    m_ChkedList1.Add(_t);
+                }
+            }
+            Debug.LogFormat("绂荤粓鐐规渶杩戠殑鐐逛负椋炶穬缁�: {0} 鐨勭 {1} 涓偣", _chkTransID, _chkIndex);
+            if (m_ChkedList1.Count == 0)
+            {
+                return Vector3.zero;
+            }
+            var _t1 = m_ChkedList1[m_ChkedList1.Count - 1];
+            for (int i = 0; i < _t1.transferPoints.Length - 1; ++i)
+            {
+                var _p1 = _t1.transferPoints[i].position;
+                _p1.y = 0;
+                var _p2 = _t1.transferPoints[i + 1].position;
+                _p2.y = 0;
+                _totalDis += Vector3.Distance(_p1, _p2);
+                // Debug.LogFormat(" ### 2涓偣鐨勮窛绂�: {0}, {1}", Vector3.Distance(_p1, _p2), _totalDis);
+            }
+            var _p = _t1.transferPoints[_chkIndex].position;
+            _p.y = 0;
+            _totalDis += Vector3.Distance(_p, dest);
+            //Debug.LogFormat(" ### 缁堢偣鍜岃烦璺冪偣鐨勮窛绂�: {0}, {1}", Vector3.Distance(_p, dest), _totalDis);
+            var _nextIdx = _chkIndex == 0 ? _t1.transferPoints.Length - 1 : 0;
+            _p = _t1.transferPoints[_nextIdx].position;
+            var _startDis = PathFinder.CalculateDistance(start, _p);
+            _totalDis += _startDis;
+            //Debug.LogFormat(" ### 璧风偣鍜岃烦璺冪偣鐨勮窛绂�: {0}, {1}", _startDis, _totalDis);
+            if (_totalDis < _dis)
+            {
+                return _p;
+            }
+            var _next = GetNext11(start, _p, ref _totalDis, _dis);
+            if (_totalDis < _dis)
+            {
+                return _next;
+            }
+            else
+            {
+                return Vector3.zero;
+            }
+        }
+        else
+        {
+            return GetNext(start, dest);
+        }
+    }
+
+    private Vector3 GetNext11(Vector3 start, Vector3 dest, ref float dis, float totalDis)
+    {
+        float _chkDis1;
+        float _chkDis2;
+        float _compareDis = float.MaxValue;
+        int _chkTransID = -1;
+        int _chkIndex = -1;
+
+        foreach (var _t in m_MapData.transfers)
+        {
+            if (m_ChkedList1.Contains(_t))
+            {
+                continue;
+            }
+
+            if (_t.transferPoints.Length >= 2)
+            {
+                if (!PathFinder.WalkAble(_t.transferPoints[0].position, dest)
+                 && !PathFinder.WalkAble(_t.transferPoints[_t.transferPoints.Length - 1].position, dest))
+                {
+                    continue;
+                }
+                _chkDis1 = Vector3.Distance(_t.transferPoints[0].position, dest);
+                _chkDis2 = Vector3.Distance(_t.transferPoints[_t.transferPoints.Length - 1].position, dest);
+
+                if (_chkDis1 > _compareDis && _chkDis2 > _compareDis)
+                {
+                    continue;
+                }
+
+                if (_chkDis1 < _chkDis2)
+                {
+                    _compareDis = _chkDis1;
+                    _chkIndex = 0;
+                }
+                else
+                {
+                    _compareDis = _chkDis2;
+                    _chkIndex = _t.transferPoints.Length - 1;
+                }
+
+                m_ChkedList1.Add(_t);
+                _chkTransID = _t.id;
+            }
+        }
+
+        if (m_ChkedList1.Count == 0)
+        {
+            return Vector3.zero;
+        }
+
+        var _t1 = m_ChkedList1[m_ChkedList1.Count - 1];
+
+        if (_chkTransID != -1)
+        {
+            for (int i = 0; i < _t1.transferPoints.Length - 1; ++i)
+            {
+                var _p1 = _t1.transferPoints[i].position;
+                _p1.y = 0;
+                var _p2 = _t1.transferPoints[i + 1].position;
+                _p2.y = 0;
+                dis += Vector3.Distance(_p1, _p2);
+                // Debug.LogFormat(" ### 2涓偣鐨勮窛绂�: {0}", Vector3.Distance(_p1, _p2));
+            }
+            var _p = _t1.transferPoints[_chkIndex].position;
+            _p.y = 0;
+            dis += Vector3.Distance(_p, dest);
+            _p = _t1.transferPoints[_chkIndex].position;
+            _p.y = 0;
+            //Debug.LogFormat(" ### 缁堢偣鍜岃烦璺冪偣鐨勮窛绂�: {0}", Vector3.Distance(_p, dest));
+            int _nextIdx = _chkIndex == 0 ? _t1.transferPoints.Length - 1 : 0;
+            return GetNext11(start, _t1.transferPoints[_nextIdx].position, ref dis, totalDis);
+        }
+        else
+        {
+            int _nextIdx = _chkIndex == 0 ? _t1.transferPoints.Length - 1 : 0;
+            return _t1.transferPoints[_nextIdx].position;
+        }
+    }
+
     private Vector3 GetNext(Vector3 start, Vector3 next)
     {
         Vector3 _targetPos = Vector3.zero;

--
Gitblit v1.8.0