Guest User

Untitled

a guest
Jul 4th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.87 KB | None | 0 0
  1. package Walker;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Point;
  7. import java.awt.Polygon;
  8.  
  9. import org.osbot.script.Script;
  10. import org.osbot.script.rs2.map.Position;
  11. import org.osbot.script.rs2.model.Player;
  12. import org.osbot.script.rs2.model.RS2Object;
  13.  
  14. public class Walker {
  15.  
  16.     private Script s;
  17.     private boolean openDoors;
  18.     private int doorDistance;
  19.  
  20.     public Walker(Script scr, int doorDistance1) {
  21.     this.s = scr;
  22.     if (doorDistance1 > 0) {
  23.         this.doorDistance = doorDistance1;
  24.         this.openDoors = true;
  25.     } else {
  26.         this.doorDistance = 1;
  27.         this.openDoors = false;
  28.     }
  29.     }
  30.  
  31.     public void walkPath(Path path) throws InterruptedException {
  32.     Player p = this.s.client.getMyPlayer();
  33.     this.manageRun(50, 10);
  34.     if (!path.isWalking()) {
  35.         path.start();
  36.     }
  37.     if (!path.shouldStop()) {
  38.         if (p.isMoving()) {
  39.         if (path.shouldNext()) {
  40.             this.walk(path.next());
  41.         }
  42.         } else {
  43.         this.walk(path.next());
  44.         }
  45.     } else {
  46.         path.stop();
  47.     }
  48.     }
  49.  
  50.     private void walk(PathTile p) throws InterruptedException {
  51.     if (!this.detectDoor()) {
  52.         this.s.walkMiniMap(p);
  53.     } else {
  54.         this.openDoor();
  55.     }
  56.     }
  57.  
  58.     private boolean detectDoor() {
  59.     if (!this.openDoors) {
  60.         return false;
  61.     }
  62.     RS2Object door = this.s.closestObjectForName("Door");
  63.     if (door != null
  64.         && this.s.client.getMyPlayer().getPosition()
  65.             .distance(door.getPosition()) <= this.doorDistance
  66.         && !this.checkOpenDoor(door)) {
  67.         return true;
  68.     }
  69.     return false;
  70.     }
  71.  
  72.     // True == open False == close
  73.     private boolean checkOpenDoor(RS2Object door) {
  74.     int orientation = door.getOrientation();
  75.     if (orientation == 0 || orientation == 2) {
  76.         Position check1 = new Position(door.getX() - 1, door.getY(),
  77.             door.getZ());
  78.         Position check2 = new Position(door.getX() + 1, door.getY(),
  79.             door.getZ());
  80.         if (this.s.canReach(check1) && this.s.canReach(check2)) {
  81.         return true;
  82.         }
  83.     }
  84.     if (orientation == 1 || orientation == 3) {
  85.         Position check1 = new Position(door.getX(), door.getY() - 1,
  86.             door.getZ());
  87.         Position check2 = new Position(door.getX(), door.getY() + 1,
  88.             door.getZ());
  89.         if (this.s.canReach(check1) && this.s.canReach(check2)) {
  90.         return true;
  91.         }
  92.     }
  93.     return false;
  94.     }
  95.  
  96.     private void openDoor() throws InterruptedException {
  97.     RS2Object door = this.s.closestObjectForName("Door");
  98.     if (door != null
  99.         && this.s.client.getMyPlayer().getPosition()
  100.             .distance(door.getPosition()) <= 2) {
  101.         door.interact("Open");
  102.         this.s.sleep(2500);
  103.     }
  104.     }
  105.  
  106.     private void manageRun(int start, int stop) throws InterruptedException {
  107.     if (this.s.client.getRunEnergy() >= start
  108.         && this.s.client.getRunEnergy() > stop) {
  109.         this.s.setRunning(true);
  110.     }
  111.     if (this.s.client.getRunEnergy() < stop && this.s.isRunning()) {
  112.         this.s.setRunning(false);
  113.     }
  114.     }
  115.  
  116.     public void drawDebug(Graphics g, Path p) {
  117.     try {
  118.         this.drawPath(g, p, Color.CYAN, Color.RED);
  119.         int widthAcross = this.s.client.getInterface(548).getChild(98)
  120.             .getWidth();
  121.         int heightAcross = this.s.client.getInterface(548).getChild(98)
  122.             .getHeight();
  123.         int paintWidth = widthAcross;
  124.         g.setColor(new Color(0, 0, 0, 150));
  125.         g.fill3DRect(547, 205, paintWidth, heightAcross, true);
  126.         int x = 559;
  127.         int y = 224;
  128.         Color white = new Color(255, 255, 255);
  129.         Font arial = new Font("Arial", 0, 12);
  130.         g.setColor(white);
  131.         g.setFont(arial);
  132.         g.drawString("should Walk Next:" + p.shouldNext(), x, y);
  133.         y += 15;
  134.         g.drawString("Walking: " + p.isWalking(), x, y);
  135.         y += 15;
  136.         g.drawString("Path Index: " + p.index, x, y);
  137.         y += 15;
  138.         g.drawString("Max Index: " + p.maxIndex, x, y);
  139.         y += 15;
  140.         g.drawString("Should stop: " + p.shouldStop(), x, y);
  141.         y += 15;
  142.     } catch (Exception e) {
  143.         e.printStackTrace();
  144.     }
  145.     }
  146.  
  147.     // Credits to jelknab
  148.     public void drawPath(Graphics g, Path p, Color c1, Color c2) {
  149.     for (int a = 0; a < p.tiles.length; a++) {
  150.         Position position = p.tiles[a];
  151.         g.setColor(c1);
  152.  
  153.         if (position.isVisible(this.s.bot)) {
  154.         g.drawPolygon(position.getPolygon(this.s.bot));
  155.  
  156.         g.setColor(c2);
  157.         if (a != 0 && p.tiles[a - 1].isVisible(this.s.bot)) {
  158.             g.drawLine(getMiddle(position.getPolygon(this.s.bot)).x,
  159.                 getMiddle(position.getPolygon(this.s.bot)).y,
  160.                 getMiddle(p.tiles[a - 1].getPolygon(this.s.bot)).x,
  161.                 getMiddle(p.tiles[a - 1].getPolygon(this.s.bot)).y);
  162.         }
  163.         }
  164.     }
  165.     }
  166.  
  167.     // Credits to jelknab
  168.     private Point getMiddle(Polygon polygon) {
  169.     int totalX = 0;
  170.     int totalY = 0;
  171.  
  172.     for (Integer x : polygon.xpoints) {
  173.         totalX += x;
  174.     }
  175.     for (Integer y : polygon.ypoints) {
  176.         totalY += y;
  177.     }
  178.  
  179.     return new Point(totalX / polygon.xpoints.length, totalY
  180.         / polygon.ypoints.length);
  181.     }
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment