Bläddra i källkod

修改攻击目标即使在不可到达区域,也会努力走到区域边上尝试攻击

大爷 1 år sedan
förälder
incheckning
10c6d9dc27

+ 14 - 4
Common/CommonAI/Zone/Helper/Motions.cs

@@ -588,6 +588,16 @@ namespace CommonAI.Zone.Helper
                 {
                     holdTime.Reset(hold_time);
                     IsNoWay = true;
+
+                    var dis = MathVector.getDistance(unit.X, unit.Y, TargetX, TargetY);
+                    //如果不能到达目的地,则找个靠近点
+                    float fixx = -1, fixy = -1;
+                    if (zone.GetNearWay(unit.X, unit.Y, TargetX, TargetY, dis - 1, ref fixx, ref fixy))
+                    {
+                        Target = new TMoveTarget(fixx, fixy);
+                        next_path = zone.findPath(unit.X, unit.Y, TargetX, TargetY);
+                        IsNoWay = next_path == null;
+                    }
                 }
                 this.mPause = false;
             }
@@ -634,10 +644,10 @@ namespace CommonAI.Zone.Helper
                 if (IsNoWayAutoFindNear && holdTime.Update(zone.UpdateIntervalMS))
                 {
                     this.next_path = zone.findPath(
-                        unit.X + (float)(unit.Parent.GridCellW * unit.Parent.RandomN.NextDouble()),
-                        unit.Y + (float)(unit.Parent.GridCellH * unit.Parent.RandomN.NextDouble()),
-                        TargetX + (float)(unit.Parent.GridCellW * unit.Parent.RandomN.NextDouble()),
-                        TargetY + (float)(unit.Parent.GridCellH * unit.Parent.RandomN.NextDouble()));
+                        unit.X,
+                        unit.Y,
+                        TargetX + (float)(unit.Parent.GridCellW * ((unit.Parent.RandomN.NextDouble() * 2) - 1)),
+                        TargetY + (float)(unit.Parent.GridCellH * ((unit.Parent.RandomN.NextDouble() * 2) - 1)));
                     IsNoWay = next_path == null;
                 }
 				//else

+ 63 - 0
Common/CommonAI/Zone/Instance/InstanceZone.Terrain.cs

@@ -360,6 +360,69 @@ namespace CommonAI.Zone.Instance
             return mSpaceDiv.GetNearObjectsCapacity(x, y);
         }
 
+        /**
+         * 以目标点为中心,circle为半径,找可行走区域。找到了返回true;找不到返回false;
+         * sx, sy 起始位置
+         * dstx, dsty 目标位置
+         * circle 搜寻半径
+         * outx, outy修改后的目标点
+         */
+        public bool GetNearWay(float sx, float sy, float dstx, float dsty, float circle, ref float outx, ref float outy)
+        {
+            //以目标点为中心,一圈一圈向外查找可行走的块
+            //起始点与终点连线方向上的点优先
+            int W = Terrain.GridCellW;
+            int H = Terrain.GridCellH;
+            float squCircle = circle * circle;
+            int dr = ((int)circle) / W;
+
+            float vx = sx > dstx ? 1 : -1;
+            float vy = sy > dsty ? 1 : -1;
+            bool f = true;
+            for (int r = 1; r <= dr; r++)
+            {
+                for (int v = 1; v <= 4; v++)
+                {
+                    float xx = dstx + W * r * vx;
+                    float yy = dsty + H * r * vy;
+                    for (int dx = f ? 0 : 1; f ? dx <= r : dx < r; dx++)
+                    {
+                        float x = dstx + dx * W * vx;
+                        if (MathVector.getDistanceSquare(x, yy, dstx, dsty) < squCircle)
+                        {
+                            if (!path_finder.TouchMapBlock(((int)x) / W, ((int)yy) / H))
+                            {
+                                outx = x;
+                                outy = yy;
+                                return true;
+                            }
+                        }
+                    }
+
+                    for (int dy = f ? 1 : 0; f ? dy < r : dy <= r; dy++)
+                    {
+                        float y = dsty + dy * H * vy;
+                        if (MathVector.getDistanceSquare(xx, y, dstx, dsty) < squCircle)
+                        {
+                            if (!path_finder.TouchMapBlock(((int)xx) / W, ((int)y) / H))
+                            {
+                                outx = xx;
+                                outy = y;
+                                return true;
+                            }
+                        }
+                    }
+                    if (f) vy *= -1;
+                    else vx *= -1;
+                    f = !f;
+                }
+            }
+
+            outx = -1;
+            outy = -1;
+            return false;
+        }
+
         //---------------------------------------------------------------------------------------------------------------
         #region _Deprecated_
         /// <summary>

+ 2 - 0
test/app.config

@@ -14,6 +14,8 @@
 		<add key="iceConfig.isWarnConnections" value="true"/>
 		<add key="fastStreamConfig.port" value="3370"/>
 		<add key="game.server.id" value=""/>
+
+		<!--开关打开后,一些Log会以warn等级打印;性能日志从2个小时频率增加为300秒-->
 		<add key="game.bstest" value="true"/>
 		<!--add key="gameServer.start.bat" value="E:\work\服务器运行环境\xmds-server\xmds-game.bat" /-->
 		<add key="ClientSettingsProvider.ServiceUri" value=""/>