瀏覽代碼

修复怪兽在攻塔时,偶尔会被被吸引到其它目标的问题

大爷 1 年之前
父節點
當前提交
2797555ff1

+ 1 - 1
Common/CommonAI/Zone/ZoneEditor/EditorDatas.cs

@@ -742,7 +742,7 @@ namespace CommonAI.Zone.ZoneEditor
         //---------------------------------------------------------
         [DescAttribute("单位掉线即离开场景", "网络")]
         public bool RemoveUnitOnDisconnect = false;
-        [DescAttribute("客户端同步范围", "网络")]
+        [DescAttribute("客户端同步范围,(废弃)", "网络")]
         public float ClientSyncRange = 20;
         //---------------------------------------------------------
 

+ 55 - 51
XmdsCommonServer/Plugin/Units/XmdsInstanceMonster.cs

@@ -304,65 +304,63 @@ namespace XmdsCommonServer.Plugin.Units
 
         public override void guard()
         {
-            #region 遍历可使用的技能,以技能目标类型作为搜寻条件.
-
-            if (IsNoneSkill == false)
+            if (IsNoneSkill)
             {
-                SkillState ret = GetAvailableSkillExceptDefaultSkill();
+                mTracingTarget = null;
+                base.startIdle();
+                return;
+            }
 
-                if (ret != null && this.Info.GuardRange > 0)
+            if (this.Info.GuardRange > 0)
+            {
+                InstanceUnit min = null;
+                float min_len = float.MaxValue;
+                bool isSpecial = false;
+                float guardRangSqua = mGuardRange * mGuardRange;
+                Parent.ForEachNearObjects(this.X, this.Y, this.Info.GuardRange, (InstanceUnit u, ref bool cancel) =>
                 {
-                    InstanceUnit min = null;
-                    float min_len = float.MaxValue;
-                    bool isSpecial = false;
-                    float guardRangSqua = mGuardRange * mGuardRange;
-                    Parent.ForEachNearObjects(this.X, this.Y, this.Info.GuardRange, (InstanceUnit u, ref bool cancel) =>
+                    float len = MathVector.getDistanceSquare(u.X, u.Y, this.X, this.Y);
+                    if (len > guardRangSqua)
                     {
-                        float len = MathVector.getDistanceSquare(u.X, u.Y, this.X, this.Y);
-                        if (len > guardRangSqua)
-                        {
-                            return;
-                        }
+                        return;
+                    }
 
-                        if (!Parent.IsAttackable(this, u, ret.Data.ExpectTarget, AttackReason.Look, Info))
-                        {
-                            return;
-                        }
+                    if (!Parent.IsAttackable(this, u, SkillTemplate.CastTarget.Enemy, AttackReason.Look, Info))
+                    {
+                        return;
+                    }
 
-                        if (u.Info.Properties is XmdsUnitProperties prop && prop.GameStatusType > XmdsUnitProperties.StatusType.Normal)
+                    if (u.Info.Properties is XmdsUnitProperties prop && prop.GameStatusType > XmdsUnitProperties.StatusType.Normal)
+                    {
+                        if (isSpecial)
                         {
-                            if (isSpecial)
-                            {
-                                if (len < min_len)
-                                {
-                                    min = u;
-                                    min_len = len;
-                                }
-                            }
-                            else
+                            if (len < min_len)
                             {
                                 min = u;
                                 min_len = len;
-                                isSpecial = true;
                             }
                         }
-                        else if (!isSpecial && min_len > len)
+                        else
                         {
-                            min_len = len;
                             min = u;
+                            min_len = len;
+                            isSpecial = true;
                         }
-                    });
-
-                    if (min != null)
+                    }
+                    else if (!isSpecial && min_len > len)
                     {
-                        changeState(new StateFollowAndAttack(this, min, ret.Data.ExpectTarget));
-                        return;
+                        min_len = len;
+                        min = u;
                     }
+                });
+
+                if (min != null)
+                {
+                    changeState(new StateFollowAndAttack(this, min, SkillTemplate.CastTarget.Enemy));
+                    return;
                 }
             }
-
-            #endregion
-
+            
             base.guard();
         }
 
@@ -410,22 +408,28 @@ namespace XmdsCommonServer.Plugin.Units
         protected override void onAddEnemy(InstanceUnit target, bool group, AttackReason reason)
         {
             var state = CurrentState;
+            InstanceUnit nowTarget = null;
             if (state is StateFollowAndAttack attackstate)
             {
-                //当前正在追踪一个价值更高的目标时,不理会小啰啰的攻击
-                var tar = attackstate.TargetUnit;
-                if (tar != null && tar.Info.Properties is XmdsUnitProperties prop && prop.GameStatusType > XmdsUnitProperties.StatusType.Normal)
+                nowTarget = attackstate.TargetUnit;
+            }
+            else if(state is StateSkill skillstate)
+            {
+                nowTarget = skillstate.TargetUnit;
+            }
+
+            //当前正在追踪/攻击一个价值更高的目标时,不理会小啰啰的攻击
+            if (nowTarget != null && nowTarget.Info.Properties is XmdsUnitProperties prop && prop.GameStatusType > XmdsUnitProperties.StatusType.Normal)
+            {
+                if(target.Info.Properties is XmdsUnitProperties propnew && propnew.GameStatusType > prop.GameStatusType)
                 {
-                    if(target.Info.Properties is XmdsUnitProperties propnew && propnew.GameStatusType > prop.GameStatusType)
-                    {
-                    }
-                    else
-                    {
-                        return;
-                    }
+                }
+                else
+                {
+                    return;
                 }
             }
-
+            
             base.onAddEnemy(target, group, reason);
         }
     }

+ 1 - 2
XmdsCommonServer/Plugin/Units/XmdsInstancePlayer.cs

@@ -620,8 +620,7 @@ namespace XmdsCommonServer.Plugin.Units
 			if (IsGuard)
 			{
 				// 旋风斩贴近目标 //
-				var state = CurrentState as StateSkill;
-				if (state != null)
+				if (CurrentState is StateSkill state)
                 {
 					Vector2 movePos = (mXmdsFocusTarget == null) ? state.GetMoveToPos() : new Vector2(mXmdsFocusTarget.Target.X, mXmdsFocusTarget.Target.Y);