Author Topic: Grand Crusade Servitors defend mode - FREE source  (Read 282 times)

Offline vass

  • Vassal
  • *
  • Posts: 1
Servitors defend mode - FREE source
« on: April 17, 2020, 07:30:34 AM »
I've noticed the defending of servitors work quite a bit different to NA Live I've played a while ago - below is not perfect but a lot closer:
- all servitors defend when one of them is attacked
- servitors attack the target until it's dead
- no limit on how far the servitors where when defending against attacks (could be sent into a pack of monsters and kill them all by defending)


+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/ai/SummonAI.java
@@ -225,7 +225,7 @@ public class SummonAI extends PlayableAI implements Runnable

                if (_isDefending)
                {
-                       defendAttack(attacker);
+                       allServitorsDefend(attacker);
                }
                else
                {
@@ -240,7 +240,7 @@ public class SummonAI extends PlayableAI implements Runnable

                if (_isDefending)
                {
-                       defendAttack(attacker);
+                       allServitorsDefend(attacker);
                }
                else
                {
@@ -248,6 +248,20 @@ public class SummonAI extends PlayableAI implements Runnable
                }
        }

+       private void allServitorsDefend(Creature attacker)
+       {
+               final Creature Owner = getActor().getOwner();
+
+               if ((Owner != null) && Owner.getActingPlayer().hasServitors())
+               {
+                       Owner.getActingPlayer().getServitors().values().stream().filter(summon -> ((SummonAI) summon.getAI()).isDefending()).forEach(summon -> ((SummonAI) summon.getAI()).defendAttack(attacker));
+               }
+               else
+               {
+                       defendAttack(attacker);
+               }
+       }
+
        private void avoidAttack(Creature attacker)
        {
                // Don't move while casting. It breaks casting animation, but still casts the skill... looks so bugged.
@@ -273,9 +287,9 @@ public class SummonAI extends PlayableAI implements Runnable
                }

                final Summon summon = getActor();
-               if ((summon.getOwner() != null) && (summon.getOwner() != attacker) && !summon.isMoving() && summon.canAttack(attacker, false) && summon.getOwner().isInsideRadius3D(_actor, 2 * AVOID_RADIUS))
+               if ((summon.getOwner() != null) && (summon.getOwner() != attacker) && !summon.isMoving() && summon.canAttack(attacker, false))
                {
-                       summon.doAutoAttack(attacker);
+                       summon.doAttack(attacker);
                }
        }

Online Mobius

  • Administrator
  • Distinguished King
  • *****
  • Posts: 7353
Re: Servitors defend mode - FREE source
« Reply #1 on: April 17, 2020, 02:08:31 PM »
Please use pastebin to share patches.
Plain forum text make the patch unusable.
https://pastebin.com/M3A6TEF0

Thank you for sharing.