Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.35 KB | None | 0 0
  1. package Walker;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6.  
  7. import org.osbot.script.Script;
  8. import org.osbot.script.rs2.map.Position;
  9. import org.osbot.script.rs2.model.Player;
  10. import org.osbot.script.rs2.model.RS2Object;
  11.  
  12. public class Walker {
  13.  
  14.     private Script s;
  15.  
  16.     public Walker(Script scr) {
  17.     this.s = scr;
  18.     }
  19.  
  20.     public void walkPath(Path path) throws InterruptedException {
  21.     Player p = this.s.client.getMyPlayer();
  22.     this.manageRun(50, 10);
  23.     if (!path.isWalking()) {
  24.         path.start();
  25.     }
  26.     if (!path.shouldStop()) {
  27.         if (p.isMoving()) {
  28.         if (path.shouldNext()) {
  29.             this.walk(path.next());
  30.         }
  31.         } else {
  32.         this.walk(path.next());
  33.         }
  34.     } else {
  35.         path.stop();
  36.     }
  37.     }
  38.  
  39.     private void walk(PathTile p) throws InterruptedException {
  40.     if (!this.detectDoor()) {
  41.         this.s.walkMiniMap(p);
  42.     } else {
  43.         this.openDoor();
  44.     }
  45.     }
  46.  
  47.     private boolean detectDoor() {
  48.     RS2Object door = this.s.closestObjectForName("Door");
  49.     if (door != null
  50.         && this.s.client.getMyPlayer().getPosition()
  51.             .distance(door.getPosition()) <= 2
  52.         && !this.checkOpenDoor(door)) {
  53.         return true;
  54.     }
  55.     return false;
  56.     }
  57.  
  58.     // True == open False == close
  59.     private boolean checkOpenDoor(RS2Object door) {
  60.     int orientation = door.getOrientation();
  61.     if (orientation == 0 || orientation == 2) {
  62.         Position check1 = new Position(door.getX() - 1, door.getY(),
  63.             door.getZ());
  64.         Position check2 = new Position(door.getX() + 1, door.getY(),
  65.             door.getZ());
  66.         if (this.s.canReach(check1) && this.s.canReach(check2)) {
  67.         return true;
  68.         }
  69.     }
  70.     if (orientation == 1 || orientation == 3) {
  71.         Position check1 = new Position(door.getX(), door.getY() - 1,
  72.             door.getZ());
  73.         Position check2 = new Position(door.getX(), door.getY() + 1,
  74.             door.getZ());
  75.         if (this.s.canReach(check1) && this.s.canReach(check2)) {
  76.         return true;
  77.         }
  78.     }
  79.     return false;
  80.     }
  81.  
  82.     private void openDoor() throws InterruptedException {
  83.     RS2Object door = this.s.closestObjectForName("Door");
  84.     if (door != null
  85.         && this.s.client.getMyPlayer().getPosition()
  86.             .distance(door.getPosition()) <= 2) {
  87.         door.interact("Open");
  88.         this.s.sleep(2500);
  89.     }
  90.     }
  91.  
  92.     private void manageRun(int start, int stop) throws InterruptedException {
  93.     if (this.s.client.getRunEnergy() >= start
  94.         && this.s.client.getRunEnergy() > stop) {
  95.         this.s.setRunning(true);
  96.     }
  97.     if (this.s.client.getRunEnergy() < stop && this.s.isRunning()) {
  98.         this.s.setRunning(false);
  99.     }
  100.     }
  101.  
  102.     public void drawDebug(Graphics g, Path p) {
  103.     int widthAcross = this.s.client.getInterface(548).getChild(98)
  104.         .getWidth();
  105.     int heightAcross = this.s.client.getInterface(548).getChild(98)
  106.         .getHeight();
  107.     int paintWidth = widthAcross;
  108.     g.setColor(new Color(0, 0, 0, 150));
  109.     g.fill3DRect(547, 205, paintWidth, heightAcross, true);
  110.     int x = 559;
  111.     int y = 224;
  112.     Color white = new Color(255, 255, 255);
  113.     Font arial = new Font("Arial", 0, 12);
  114.     g.setColor(white);
  115.     g.setFont(arial);
  116.     g.drawString("should Walk Next:" + p.shouldNext(), x, y);
  117.     y += 15;
  118.     g.drawString("Walking: " + p.isWalking(), x, y);
  119.     y += 15;
  120.     g.drawString("Path Index: " + p.index, x, y);
  121.     y += 15;
  122.     g.drawString("Max Index: " + p.maxIndex, x, y);
  123.     y += 15;
  124.     g.drawString("Should stop: " + p.shouldStop(), x, y);
  125.     y += 15;
  126.     }
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement