Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. public class SluttyTree extends Script {
  2.  
  3.     private CachedNPC cache;
  4.  
  5.     @Override
  6.     public int onLoop() throws InterruptedException {
  7.         if (cache == null || cache.isDead()) {
  8.             NPC npc = getNpcs().closest("Ent");
  9.             if (npc != null) {
  10.                 cache = new CachedNPC(npc);
  11.             }
  12.         } else {
  13.             cache.checkPosition(getBot());
  14.             if (cache.isSafeSpotted(myPlayer())) {
  15.                 if (!myPlayer().isInteracting(cache.getNpc())) {
  16.                     //TODO - Attack
  17.                 }
  18.             } else {
  19.                 //TODO - Walk to position
  20.             }
  21.         }
  22.         return 600;
  23.     }
  24.  
  25.     @Override
  26.     public void onPaint(Graphics2D g) {
  27.         if (cache != null) cache.draw(g);
  28.     }
  29. }
  30.  
  31. class CachedNPC {
  32.  
  33.     private final NPC npc;
  34.     private Position position;
  35.     private Area area;
  36.     private List<Polygon> polygons;
  37.  
  38.     public CachedNPC(NPC npc) {
  39.         this.npc = npc;
  40.     }
  41.  
  42.     public boolean isDead() {
  43.         return npc == null || !npc.exists();
  44.     }
  45.  
  46.     public void checkPosition(Bot bot) {
  47.         Position pos = npc.getPosition();
  48.         if (position == null || pos.distance(position) != 0) {
  49.             this.position = pos;
  50.             this.area = new Area(pos.getX(), pos.getY(), pos.getX() + 1, pos.getY() + 1);
  51.             this.polygons = new ArrayList<>();
  52.             this.area.getPositions().forEach(p -> this.polygons.add(p.getPolygon(bot)));
  53.         }
  54.     }
  55.  
  56.     public void draw(Graphics2D g) {
  57.         if (polygons != null && polygons.size() > 0) {
  58.             polygons.forEach(g::drawPolygon);
  59.         }
  60.     }
  61.  
  62.     public boolean isSafeSpotted(Player player) {
  63.         if (!player.isUnderAttack()) {
  64.             if (npc.isInteracting(player)) {
  65.                 if (!npc.isMoving()) {
  66.                     return true;
  67.                 }
  68.             }
  69.         }
  70.         return false;
  71.     }
  72.  
  73.     public NPC getNpc() {
  74.         return npc;
  75.     }
  76.  
  77.     public Area getArea() {
  78.         return area;
  79.     }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement