Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.io.IOException;
- import java.net.URL;
- import java.util.Arrays;
- import javax.imageio.ImageIO;
- import org.osbot.rs07.api.filter.Filter;
- import org.osbot.rs07.api.map.Position;
- import org.osbot.rs07.api.model.Entity;
- import org.osbot.rs07.api.model.NPC;
- import org.osbot.rs07.api.model.RS2Object;
- import org.osbot.rs07.api.ui.Option;
- import org.osbot.rs07.api.ui.RS2Widget;
- import org.osbot.rs07.canvas.paint.Painter;
- import org.osbot.rs07.input.mouse.EntityDestination;
- import org.osbot.rs07.input.mouse.MiniMapTileDestination;
- import org.osbot.rs07.input.mouse.RectangleDestination;
- import org.osbot.rs07.script.MethodProvider;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import org.osbot.rs07.utility.ConditionalSleep;
- import com.scripts.mrsdefnerd.api.TimeHandler;
- @ScriptManifest(author = "Mrsdefnerd", info = "Planks logs", logo = "?", name = "Auto planker pro", version = 0.1D)
- public class AutoPlanker extends Script implements Painter {
- public static final Position[] PATH = {new Position(3253, 3421, 0), new Position(3259, 3428, 0), new Position(3270, 3428, 0), new Position(3280, 3429, 0),
- new Position(3280, 3429, 0), new Position(3286, 3438, 0), new Position(3287, 3449, 0), new Position(3291, 3459, 0), new Position(3296, 3469, 0), new Position(3300, 3483, 0),
- new Position(3302, 3491, 0)};
- private Image cursor;
- public static final Plank PLANK = Plank.OAK_PLANK;
- public static final String SAW_NPC = "Sawmill operator";
- public static final int INTERACE_ID = 403;
- private long timeRan;
- private int nextRun = MethodProvider.random(25, 40);
- private int planksMade = 0;
- private String state = "N/A";
- public void onStart() {
- this.antiBan.unregisterAllBehaviors();
- warn("Loading essentials, please wait..");
- timeRan = System.currentTimeMillis();
- this.cursor = getImage("http://i.imgur.com/ACfxYs3.png");
- }
- @Override
- public int onLoop() throws InterruptedException {
- if (!settings.isRunning() && settings.getRunEnergy() >= nextRun) {
- if (settings.setRunning(true))
- new ConditionalSleep(1000, 2000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return settings.isRunning();
- }
- }.sleep();
- nextRun = MethodProvider.random(25, 40);
- }
- if (inventory.contains(PLANK.getLogName()) && inventory.getAmount(995) >= PLANK.getCost() * 27 && inventory.isFull()) {
- if (widgets.isVisible(INTERACE_ID)) {
- state = "Converting logs..";
- RS2Widget w = widgets.get(INTERACE_ID, PLANK.getChildId());
- if (w != null && w.isVisible()) {
- if (interact(w, "All")) {
- int amount = (int) inventory.getAmount(PLANK.getName());
- if (new ConditionalSleep(1000, 2000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return !inventory.contains(PLANK.getLogName());
- }
- }.sleep()) {
- planksMade += (int) inventory.getAmount(PLANK.getName()) - amount;
- }
- }
- }
- } else {
- NPC sawman = getSawmillNpc();
- if (sawman != null && sawman.isVisible()) {
- state = "Interacting with sawman..";
- if (sawman.interact("Buy-plank"))
- new ConditionalSleep(2500, 4000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return widgets.isVisible(INTERACE_ID);
- }
- }.sleep();
- } else {
- state = "Walking to sawmill..";
- traverse(PATH, true);
- }
- }
- } else {
- if (PATH[0].distance(myPosition()) <= 7) {
- final RS2Object bank = getBankBooth();
- if (bank != null) {
- if (getBank().isOpen()) {
- state = "Banking..";
- if (!getBank().contains(PLANK.getLogName()) || getBank().getAmount(995) < PLANK.getCost() * 27) {
- warn("Out of required items, stopping..");
- stop();
- return 0;
- }
- if (inventory.contains(PLANK.getName())) {
- if (getBank().depositAll(PLANK.getName()))
- new ConditionalSleep(1000, 2000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return !inventory.contains(PLANK.getName());
- }
- }.sleep();
- } else {
- if (inventory.getAmount(995) < 27 * PLANK.getCost()) {
- if (inventory.isFull() && !inventory.contains(995))
- if (getBank().deposit(PLANK.getLogName(), 1))
- new ConditionalSleep(1000, 2000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return !inventory.isFull();
- }
- }.sleep();
- if (getBank().withdraw(995, 27 * PLANK.getCost()))
- new ConditionalSleep(1000, 2000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return inventory.contains(PLANK.getLogName());
- }
- }.sleep();
- }
- if (inventory.getAmount(995) >= 27 * PLANK.getCost())
- if (getBank().withdrawAll(PLANK.getLogName()))
- new ConditionalSleep(1000, 2000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return inventory.contains(PLANK.getLogName());
- }
- }.sleep();
- }
- } else {
- state = "Opening bank..";
- if (bank.isVisible()) {
- if (interact(bank, "Bank")) {
- new ConditionalSleep(3500, 4000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return getBank().isOpen();
- }
- }.sleep();
- }
- } else {
- if (walk(bank.getPosition()))
- new ConditionalSleep(3500, 4000) {
- @Override
- public boolean condition()
- throws InterruptedException {
- return bank.isVisible();
- }
- }.sleep();
- }
- }
- }
- } else {
- state = "Walking to bank..";
- traverse(PATH, false);
- }
- }
- return 250;
- }
- private long lastClick = 0;
- @Override
- public void onPaint(Graphics2D g) {
- int x = getMouse().getPosition().x, y = getMouse().getPosition().y;
- if (System.currentTimeMillis() - lastClick < 500)
- g.setColor(Color.red);
- else
- g.setColor(Color.WHITE);
- g.drawImage(cursor, x, y, null);
- g.setColor(Color.black);
- g.drawRect(325, 196, 190, 142);
- g.setColor(new Color(118, 118, 118, 100));
- g.fillRect(325, 196, 190, 142);
- g.setColor(Color.WHITE);
- g.drawString("Planks (hr): "+TimeHandler.formatNumber(planksMade)+" ("+TimeHandler.perHour(timeRan, planksMade)+")", 330, 210);
- g.drawString("State: "+state, 330, 225);
- g.drawString("Time ran: "+TimeHandler.runTime(timeRan), 330, 240);
- g.drawString("X: "+x+" Y: "+y, 200, 300);
- }
- private boolean traverse(Position[] path, boolean reverse) {
- for (int i = reverse ? path.length - 1 : 0; reverse ? i >= 0 : i < path.length;) {
- Position p = path[i];
- if (p != null && p.distance(myPosition()) <= 17) {
- if (getMap().getDestination() == null || getMap().getDestination().distance(p) > 4) {
- p = new Position(p.getX() + MethodProvider.random(-2, 2), p.getY() + MethodProvider.random(-2, 2), p.getZ());
- if (walk(p))
- return true;
- }
- return false;
- }
- if (reverse)
- i--;
- else
- i++;
- }
- return false;
- }
- private boolean walk(Position pos) {
- MiniMapTileDestination dest = new MiniMapTileDestination(bot, pos);
- return getMouse().click(dest);
- }
- private RS2Object getBankBooth() {
- RS2Object ob = null;
- int distance = -1;
- for (RS2Object o : objects.getAll())
- if (ob == null || distance(o.getPosition(), myPosition()) < distance) {
- if (o != null && o.getName().equals("Bank booth") && o.getPosition().distance(myPosition()) <= 10 && Arrays.deepToString(o.getDefinition().getActions()).contains("Bank")) {
- ob = o;
- distance = distance(o.getPosition(), myPosition());
- }
- }
- return ob;
- }
- @SuppressWarnings("unchecked")
- private NPC getSawmillNpc() {
- return npcs.closest(new Filter<NPC>() {
- @Override
- public boolean match(NPC n) {
- if (n != null && n.getName().equals(SAW_NPC) && n.getPosition().distance(myPosition()) <= 10)
- return true;
- return false;
- }
- });
- }
- private boolean interact(Entity e, String action) throws InterruptedException {
- if (e != null) {
- if (e.isVisible()) {
- EntityDestination dest = new EntityDestination(bot, e);
- Option o = getAction(action);
- if (o == null)
- getMouse().move(dest);
- return selectAction(action);
- }
- }
- return false;
- }
- private boolean interact(RS2Widget w, String action) throws InterruptedException {
- if (w != null) {
- if (w.isVisible()) {
- Rectangle r = shrink(w.getRectangle());
- RectangleDestination dest = new RectangleDestination(bot, r);
- if (!r.contains(getMouse().getPosition())) {
- getMouse().move(dest);
- MethodProvider.sleep(MethodProvider.random(50, 100));
- }
- Option o = getAction(action);
- if (o != null)
- return selectAction(action);
- }
- }
- return false;
- }
- private boolean selectAction(String action) throws InterruptedException {
- int index = getIndex(action);
- if (index > -1) {
- if (getMouse().click(true)) {
- MethodProvider.sleep(MethodProvider.random(100, 250));
- if (getMenuAPI().isOpen()) {
- Point p = getPointForIndex(index);
- if (getMenuAPI().getMenu().get(index).action.toLowerCase().contains(action.toLowerCase()))
- return getMouse().click(p.x, p.y, false);
- }
- }
- }
- return false;
- }
- private int distance(Position pos, Position pos1) {
- if (pos1.getX() == pos.getX())
- return Math.abs(pos.getX() - pos.getX());
- else if (pos.getY() == pos1.getY())
- return Math.abs(pos.getY() - pos.getY());
- return (int) Math.ceil(Math.sqrt(Math.pow(pos1.getX() - pos.getX(), 2) + Math.pow(pos1.getY() - pos.getY(), 2)));
- }
- private int getIndex(String action) {
- int i = 0;
- for (Option o : getMenuAPI().getMenu()) {
- if (o.action.toLowerCase().contains(action.toLowerCase()))
- return i;
- i++;
- }
- return -1;
- }
- private Point getPointForIndex(int index) {
- int x = getMenuAPI().getX() + 15 + MethodProvider.random(0, getMenuAPI().getWidth() - 40);
- int y = getMenuAPI().getY() + 18 + index * 15 + MethodProvider.random(4, 12);
- return new Point(x, y);
- }
- private Option getAction(String action) {
- for (Option o : getMenuAPI().getMenu()) {
- if (o.action.toLowerCase().contains(action.toLowerCase())) {
- return o;
- }
- }
- return null;
- }
- private Rectangle shrink(Rectangle rect) {
- return new Rectangle((int) (rect.x + rect.width * 0.25), (int) (rect.y + rect.height * 0.25), (int) (rect.width - rect.width * 0.35), (int) (rect.height - rect.height * 0.35));
- }
- private Image getImage(String url) {
- try { return ImageIO.read(new URL(url)); }
- catch(IOException e) { return null; }
- }
- public enum Plank {
- PLANK("Logs", 100, 104),
- OAK_PLANK("Oak logs", 250, 110),
- TEAK_PLANK("Teak logs", 500, 115),
- MAHOGANY_PLANK("Mahogany logs", 1500, 120);
- private String logName;
- private int childId, cost;
- Plank(String logName, int cost, int childId) {
- this.logName = logName;
- this.childId = childId;
- this.cost = cost;
- }
- @Override
- public String toString() {
- final String name = super.name();
- return name.charAt(0) + name.substring(1).toLowerCase().replace("_", " ");
- }
- public final String getName() {
- return toString();
- }
- public final String getLogName() {
- return this.logName;
- }
- public final int getCost() {
- return this.cost;
- }
- public final int getChildId() {
- return this.childId;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement