Browse Source

修改monster优先以标识为更高价值的单位为目标(GameStatusType),即使受到攻击也不会被吸引仇恨

大爷 1 year ago
parent
commit
454da84049

+ 0 - 2
Common/CommonAI/Zone/Instance/InstanceNpcs.cs

@@ -596,8 +596,6 @@ namespace CommonAI.Zone.Instance
             onAddEnemy(attacker, true, AttackReason.Damaged);
         }
 
-
-
         protected virtual void onAddEnemy(InstanceUnit target, bool group, AttackReason reason)
         {
             if (onAddEnemyInternal(target, group, reason))

+ 52 - 4
XmdsCommonServer/Plugin/Units/XmdsInstanceMonster.cs

@@ -314,17 +314,43 @@ namespace XmdsCommonServer.Plugin.Units
                 {
                     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) =>
                     {
-                        if (Parent.IsAttackable(this, u, ret.Data.ExpectTarget, AttackReason.Look, Info))
+                        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 (min_len > len && len < this.Info.GuardRange)
+                            return;
+                        }
+
+                        if (!Parent.IsAttackable(this, u, ret.Data.ExpectTarget, AttackReason.Look, Info))
+                        {
+                            return;
+                        }
+
+                        if (u.Info.Properties is XmdsUnitProperties prop && prop.GameStatusType > XmdsUnitProperties.StatusType.Normal)
+                        {
+                            if (isSpecial)
+                            {
+                                if (len < min_len)
+                                {
+                                    min = u;
+                                    min_len = len;
+                                }
+                            }
+                            else
                             {
-                                min_len = len;
                                 min = u;
+                                min_len = len;
+                                isSpecial = true;
                             }
                         }
+                        else if (!isSpecial && min_len > len)
+                        {
+                            min_len = len;
+                            min = u;
+                        }
                     });
 
                     if (min != null)
@@ -380,5 +406,27 @@ namespace XmdsCommonServer.Plugin.Units
         {
             (this.Virtual as XmdsVirtual_Monster).onBack2PositionEnd();
         }
+
+        protected override void onAddEnemy(InstanceUnit target, bool group, AttackReason reason)
+        {
+            var state = CurrentState;
+            if (state is StateFollowAndAttack attackstate)
+            {
+                //当前正在追踪一个价值更高的目标时,不理会小啰啰的攻击
+                var tar = attackstate.TargetUnit;
+                if (tar != null && tar.Info.Properties is XmdsUnitProperties prop && prop.GameStatusType > XmdsUnitProperties.StatusType.Normal)
+                {
+                    if(target.Info.Properties is XmdsUnitProperties propnew && propnew.GameStatusType > prop.GameStatusType)
+                    {
+                    }
+                    else
+                    {
+                        return;
+                    }
+                }
+            }
+
+            base.onAddEnemy(target, group, reason);
+        }
     }
 }