Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Walker;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import org.osbot.script.Script;
- import org.osbot.script.rs2.map.Position;
- import org.osbot.script.rs2.model.Player;
- import org.osbot.script.rs2.model.RS2Object;
- public class Walker {
- private Script s;
- public Walker(Script scr) {
- this.s = scr;
- }
- public void walkPath(Path path) throws InterruptedException {
- Player p = this.s.client.getMyPlayer();
- this.manageRun(50, 10);
- if (!path.isWalking()) {
- path.start();
- }
- if (!path.shouldStop()) {
- if (p.isMoving()) {
- if (path.shouldNext()) {
- this.walk(path.next());
- }
- } else {
- this.walk(path.next());
- }
- } else {
- path.stop();
- }
- }
- private void walk(PathTile p) throws InterruptedException {
- if (!this.detectDoor()) {
- this.s.walkMiniMap(p);
- } else {
- this.openDoor();
- }
- }
- private boolean detectDoor() {
- RS2Object door = this.s.closestObjectForName("Door");
- if (door != null
- && this.s.client.getMyPlayer().getPosition()
- .distance(door.getPosition()) <= 2
- && !this.checkOpenDoor(door)) {
- return true;
- }
- return false;
- }
- // True == open False == close
- private boolean checkOpenDoor(RS2Object door) {
- int orientation = door.getOrientation();
- if (orientation == 0 || orientation == 2) {
- Position check1 = new Position(door.getX() - 1, door.getY(),
- door.getZ());
- Position check2 = new Position(door.getX() + 1, door.getY(),
- door.getZ());
- if (this.s.canReach(check1) && this.s.canReach(check2)) {
- return true;
- }
- }
- if (orientation == 1 || orientation == 3) {
- Position check1 = new Position(door.getX(), door.getY() - 1,
- door.getZ());
- Position check2 = new Position(door.getX(), door.getY() + 1,
- door.getZ());
- if (this.s.canReach(check1) && this.s.canReach(check2)) {
- return true;
- }
- }
- return false;
- }
- private void openDoor() throws InterruptedException {
- RS2Object door = this.s.closestObjectForName("Door");
- if (door != null
- && this.s.client.getMyPlayer().getPosition()
- .distance(door.getPosition()) <= 2) {
- door.interact("Open");
- this.s.sleep(2500);
- }
- }
- private void manageRun(int start, int stop) throws InterruptedException {
- if (this.s.client.getRunEnergy() >= start
- && this.s.client.getRunEnergy() > stop) {
- this.s.setRunning(true);
- }
- if (this.s.client.getRunEnergy() < stop && this.s.isRunning()) {
- this.s.setRunning(false);
- }
- }
- public void drawDebug(Graphics g, Path p) {
- int widthAcross = this.s.client.getInterface(548).getChild(98)
- .getWidth();
- int heightAcross = this.s.client.getInterface(548).getChild(98)
- .getHeight();
- int paintWidth = widthAcross;
- g.setColor(new Color(0, 0, 0, 150));
- g.fill3DRect(547, 205, paintWidth, heightAcross, true);
- int x = 559;
- int y = 224;
- Color white = new Color(255, 255, 255);
- Font arial = new Font("Arial", 0, 12);
- g.setColor(white);
- g.setFont(arial);
- g.drawString("should Walk Next:" + p.shouldNext(), x, y);
- y += 15;
- g.drawString("Walking: " + p.isWalking(), x, y);
- y += 15;
- g.drawString("Path Index: " + p.index, x, y);
- y += 15;
- g.drawString("Max Index: " + p.maxIndex, x, y);
- y += 15;
- g.drawString("Should stop: " + p.shouldStop(), x, y);
- y += 15;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement