Advertisement
Deedlit

Untitled

Jun 28th, 2011
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. class FollowTask implements Runnable
  2.     {
  3.         private int _range = 70;
  4.         private int _destX = 0;
  5.         private int _destY = 0;
  6.        
  7.         public FollowTask()
  8.         {
  9.         }
  10.        
  11.         public FollowTask(int range)
  12.         {
  13.             _range = range;
  14.         }
  15.        
  16.         @Override
  17.         public void run()
  18.         {
  19.             try
  20.             {
  21.                 if (_followTask == null)
  22.                     return;
  23.                
  24.                 L2Character followTarget = _followTarget; // copy to prevent NPE
  25.                 if (followTarget == null)
  26.                 {
  27.                     if (_actor instanceof L2Summon)
  28.                         ((L2Summon) _actor).setFollowStatus(false);
  29.                     setIntention(AI_INTENTION_IDLE);
  30.                     return;
  31.                 }
  32.                
  33.                 if (!_actor.isInsideRadius(followTarget, _range, true, false, false))
  34.                 {
  35.                     if (!_actor.isInsideRadius(followTarget, 3000, true, false, false))
  36.                     {
  37.                         // if the target is too far (maybe also teleported)
  38.                         if (_actor instanceof L2Summon)
  39.                             ((L2Summon) _actor).setFollowStatus(false);
  40.                        
  41.                         setIntention(AI_INTENTION_IDLE);
  42.                         return;
  43.                     }
  44.                     if (getIntention() == AI_INTENTION_ATTACK && !(_actor instanceof L2PcInstance) && !(_actor instanceof L2Summon))
  45.                     {
  46.                         if (followTarget.getXdestination() != _destX || followTarget.getYdestination() != _destY)
  47.                         {
  48.                             _destX = followTarget.getXdestination();
  49.                             _destY = followTarget.getYdestination();
  50.                             //if (_actor.isMoving())
  51.                             //_actor.stopMove(null);
  52.                             //moveTo(_destX+Rnd.get(-120, 120), _destY+Rnd.get(-120, 120), followTarget.getZdestination()+30);
  53.                             //Location _vector = _actor.getMyLocation().getVector(followTarget.getMyLocation());
  54.                             //, _destinyLoc;
  55.                            
  56.                             _actor.moveToLocation(_destX + Rnd.get(-60, 60), _destY + Rnd.get(-60, 60), followTarget.getZdestination() + _actor.getObjectCollisionHeight(), 0);
  57.                         }
  58.                         else if (followTarget.isMoving() && !_actor.isMoving())
  59.                             _actor.moveToLocation(followTarget.getXdestination() + Rnd.get(-60, 60), followTarget.getYdestination() + Rnd.get(-60, 60), followTarget.getZdestination() + _actor.getObjectCollisionHeight(), 0);
  60.                     }
  61.                     else
  62.                     {
  63.                         _destX = 0;
  64.                         _destY = 0;
  65.                        
  66.                         //moveToPawn(followTarget, _range);
  67.                         if (!(_actor instanceof L2PcInstance) && !(_actor instanceof L2Summon))
  68.                             _actor.moveToLocation(followTarget.getXdestination() + ((int) Rnd.get(-followTarget.getCollisionRadius() / 2, followTarget.getCollisionRadius() / 2)),
  69.                                     followTarget.getYdestination() + ((int) Rnd.get(-followTarget.getCollisionRadius() / 2, followTarget.getCollisionRadius() / 2)),
  70.                                     followTarget.getZdestination() + _actor.getObjectCollisionHeight(), 0);
  71.                         else
  72.                             _actor.moveToLocation(followTarget.getX(), followTarget.getY(), followTarget.getZ(), 0);
  73.                        
  74.                     }
  75.                 }
  76.             }
  77.             catch (Exception e)
  78.             {
  79.                 _log.log(Level.WARNING, "", e);
  80.             }
  81.         }
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement