Advertisement
Deedlit

AttackableAI movementDisable() NPE fix

Jun 26th, 2011
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.74 KB | None | 0 0
  1. Index: java/com/l2jserver/gameserver/ai/L2AttackableAI.java
  2. ===================================================================
  3. --- java/com/l2jserver/gameserver/ai/L2AttackableAI.java    (revision 4694)
  4. +++ java/com/l2jserver/gameserver/ai/L2AttackableAI.java    (working copy)
  5. @@ -1699,14 +1699,32 @@
  6.         double dist = 0;
  7.         double dist2 = 0;
  8.         int range = 0;
  9. +       if (_attackTarget == null && getTarget() == null && getCastTarget() == null)
  10. +       {
  11. +           notifyEvent(CtrlEvent.EVT_CANCEL);
  12. +           return;
  13. +       }
  14. +      
  15.         try
  16.         {
  17. -           if (npc.getTarget() == null)
  18. -               npc.setTarget(getAttackTarget());
  19. -           dist = Math.sqrt(npc.getPlanDistanceSq(getAttackTarget().getX(), getAttackTarget().getY()));
  20. -           dist2 = dist - npc.getTemplate().collisionRadius;
  21. -           range = npc.getPhysicalAttackRange() + npc.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius;
  22. -           if (getAttackTarget().isMoving())
  23. +           L2Character _attackTargetCpy = _attackTarget;
  24. +           if (npc.getTarget() == null && _attackTargetCpy != null)
  25. +               npc.setTarget(_attackTargetCpy);
  26. +           else if (_attackTargetCpy == null && getTarget() != null)
  27. +           {
  28. +               _attackTargetCpy = (L2Character) getTarget();
  29. +               setAttackTarget(_attackTargetCpy);
  30. +           }
  31. +           else
  32. +           {
  33. +               notifyEvent(CtrlEvent.EVT_CANCEL);
  34. +               return;
  35. +           }
  36. +          
  37. +           dist = Math.sqrt(npc.getPlanDistanceSq(_attackTargetCpy.getX(), _attackTargetCpy.getY()));
  38. +           dist2 = dist - npc.getActiveTemplateOrPolymorph().collisionRadius;
  39. +           range = npc.getPhysicalAttackRange() + npc.getActiveTemplateOrPolymorph().collisionRadius + _attackTargetCpy.getActiveTemplateOrPolymorph().collisionRadius;
  40. +           if (_attackTargetCpy.isMoving())
  41.             {
  42.                 dist = dist - 30;
  43.                 if (npc.isMoving())
  44. @@ -1719,17 +1737,17 @@
  45.                 //-------------------------------------------------------------
  46.                 //Try to stop the target or disable the target as priority
  47.                 int random = Rnd.get(100);
  48. -               if (_skillrender.hasImmobiliseSkill() && !getAttackTarget().isImmobilized() && random < 2)
  49. +               if (_skillrender.hasImmobiliseSkill() && !_attackTargetCpy.isImmobilized() && random < 2)
  50.                 {
  51.                     for (L2Skill sk : _skillrender._immobiliseskills)
  52.                     {
  53. -                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  54. +                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getActiveTemplateOrPolymorph().collisionRadius + _attackTargetCpy.getActiveTemplateOrPolymorph().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  55.                         {
  56.                             continue;
  57.                         }
  58.                         if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
  59.                             continue;
  60. -                       if (getAttackTarget().getFirstEffect(sk) == null)
  61. +                       if (_attackTargetCpy.getFirstEffect(sk) == null)
  62.                         {
  63.                             clientStopMoving(null);
  64.                             //L2Object target = getAttackTarget();
  65. @@ -1746,13 +1764,13 @@
  66.                 {
  67.                     for (L2Skill sk : _skillrender._cotskills)
  68.                     {
  69. -                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  70. +                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getActiveTemplateOrPolymorph().collisionRadius + _attackTargetCpy.getActiveTemplateOrPolymorph().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  71.                         {
  72.                             continue;
  73.                         }
  74.                         if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
  75.                             continue;
  76. -                       if (getAttackTarget().getFirstEffect(sk) == null)
  77. +                       if (_attackTargetCpy.getFirstEffect(sk) == null)
  78.                         {
  79.                             clientStopMoving(null);
  80.                             //L2Object target = getAttackTarget();
  81. @@ -1768,13 +1786,13 @@
  82.                 {
  83.                     for (L2Skill sk : _skillrender._debuffskills)
  84.                     {
  85. -                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  86. +                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getActiveTemplateOrPolymorph().collisionRadius + _attackTargetCpy.getActiveTemplateOrPolymorph().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  87.                         {
  88.                             continue;
  89.                         }
  90.                         if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
  91.                             continue;
  92. -                       if (getAttackTarget().getFirstEffect(sk) == null)
  93. +                       if (_attackTargetCpy.getFirstEffect(sk) == null)
  94.                         {
  95.                             clientStopMoving(null);
  96.                             //L2Object target = getAttackTarget();
  97. @@ -1791,13 +1809,13 @@
  98.                 {
  99.                     for (L2Skill sk : _skillrender._negativeskills)
  100.                     {
  101. -                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  102. +                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getActiveTemplateOrPolymorph().collisionRadius + _attackTargetCpy.getActiveTemplateOrPolymorph().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  103.                         {
  104.                             continue;
  105.                         }
  106.                         if (!GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
  107.                             continue;
  108. -                       if (getAttackTarget().getFirstEffect(L2EffectType.BUFF) != null)
  109. +                       if (_attackTargetCpy.getFirstEffect(L2EffectType.BUFF) != null)
  110.                         {
  111.                             clientStopMoving(null);
  112.                             //L2Object target = getAttackTarget();
  113. @@ -1815,7 +1833,7 @@
  114.                 {
  115.                     for (L2Skill sk : _skillrender._atkskills)
  116.                     {
  117. -                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  118. +                       if (sk.getMpConsume() >= npc.getCurrentMp() || npc.isSkillDisabled(sk) || (sk.getCastRange() + npc.getActiveTemplateOrPolymorph().collisionRadius + _attackTargetCpy.getActiveTemplateOrPolymorph().collisionRadius <= dist2 && !canAura(sk)) || (sk.isMagic() && npc.isMuted()) || (!sk.isMagic() && npc.isPhysicalMuted()))
  119.                         {
  120.                             continue;
  121.                         }
  122. @@ -1838,7 +1856,7 @@
  123.                     {
  124.                         if(sk.getMpConsume()>=_actor.getCurrentMp()
  125.                                 || _actor.isSkillDisabled(sk.getId())
  126. -                               ||(sk.getCastRange()+ _actor.getTemplate().collisionRadius + getAttackTarget().getTemplate().collisionRadius <= dist2 && !canAura(sk))
  127. +                               ||(sk.getCastRange()+ _actor.getActiveTemplateOrPolymorph().collisionRadius + _attackTargetCpy.getActiveTemplateOrPolymorph().collisionRadius <= dist2 && !canAura(sk))
  128.                                 ||(sk.isMagic()&&_actor.isMuted())
  129.                                 ||(!sk.isMagic()&&_actor.isPhysicalMuted()))
  130.                         {
  131. @@ -1874,7 +1892,7 @@
  132.            
  133.             if (dist > range || !GeoData.getInstance().canSeeTarget(npc, getAttackTarget()))
  134.             {
  135. -               if (getAttackTarget().isMoving())
  136. +               if (_attackTargetCpy.isMoving())
  137.                     range -= 100;
  138.                 if (range < 5)
  139.                     range = 5;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement