Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.moneymaking.iplankfarmer;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.List;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Mouse;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Login;
- import org.tribot.api2007.Login.STATE;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.Screen;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.WebWalking;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.script.EnumScript;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.MouseActions;
- import org.tribot.script.interfaces.MousePainting;
- import org.tribot.script.interfaces.MouseSplinePainting;
- import org.tribot.script.interfaces.Painting;
- import scripts.methods.Methods;
- import scripts.moneymaking.iplankfarmer.banking.Bank;
- import scripts.moneymaking.iplankfarmer.banking.Potions;
- import scripts.moneymaking.iplankfarmer.banking.VarrockTab;
- import scripts.moneymaking.iplankfarmer.equipment.Axe;
- import scripts.moneymaking.iplankfarmer.equipment.DuelRing;
- import scripts.moneymaking.iplankfarmer.player.Data;
- import scripts.moneymaking.iplankfarmer.sawmill.Sawmill;
- import scripts.moneymaking.iplankfarmer.types.EnergyPotion;
- import scripts.moneymaking.iplankfarmer.types.LoginState;
- import scripts.moneymaking.iplankfarmer.types.Plank;
- import scripts.moneymaking.iplankfarmer.types.ScriptTask;
- import scripts.moneymaking.iplankfarmer.types.State;
- import scripts.moneymaking.iplankfarmer.utils.AntiBan;
- import scripts.moneymaking.iplankfarmer.utils.Constants;
- import scripts.moneymaking.iplankfarmer.utils.Locations;
- import scripts.moneymaking.iplankfarmer.woodcutting.Woodcutting;
- @ScriptManifest(authors = { "iant06" }, category = "Money Making", name = "iPlankFarmer")
- public class Script extends EnumScript<State> implements Painting,
- MouseSplinePainting, MousePainting, MouseActions {
- private AntiBan antiBan = null;
- private Axe axe = null;
- private Bank banking = null;
- private Data data = null;
- private DuelRing duelRing = null;
- private Potions potions = null;
- private Sawmill sawmill = null;
- private Woodcutting woodcutting = null;
- private VarrockTab varrockTab = null;
- private GUI gui = null;
- private EnergyPotion energyPotion = null;
- private DecimalFormat decimalFormat = new DecimalFormat("#.##");
- private ScriptTask task;
- private Plank plank;
- private State state;
- private double plankPrice = -1;
- private double logPrice = -1;
- private double energyPotionPrice = -1;
- private double crushedNestPrice = -1;
- private double duelRingPrice = -1;
- private double hoursToRun = -1;
- private boolean endScript = false;
- public final String PAINT_PICTURE_URL = "http://i42.tinypic.com/2i9ines.png";
- public final Image PAINT_IMG = Methods.getImage(PAINT_PICTURE_URL);
- @Override
- public void onPaint(Graphics g) {
- ((Graphics2D)g).drawImage(PAINT_IMG, 1, 265, null);
- g.setColor(Color.WHITE);
- g.setFont(new Font("default", Font.BOLD, 12));
- g.drawString(Methods.correctCapitalization(getState().toString()), 190, 358);
- g.drawString(Methods.correctCapitalization(getPlank().toString()), 115, 377);
- int planksPerHr = (int) (getData().getPlanksMade() / ((getRunningTime()) / 3600000D));
- g.drawString(getData().getPlanksMade() + " (" + planksPerHr + ")", 160, 397);
- double moneyMade = getData().getMoneyMade();
- double moneySpent = getData().getMoneySpent();
- double gpMade = (moneyMade - moneySpent);
- double gpPerHour = (double) (gpMade / ((getRunningTime()) / 3600000D));
- g.drawString(setInMoneyFormat(gpMade) + " (" + setInMoneyFormat(gpPerHour) + ")", 136, 417);
- g.drawString("Running for: " + Timing.msToString(getRunningTime()), 77, 455);
- int tripsPerHr = (int) (getData().getTripCount() / ((getRunningTime()) / 3600000D));
- g.drawString(getData().getTripCount() + " (" + tripsPerHr + ")", 157, 437);
- g.drawString(Timing.msToString(getData().getLastTripTime()), 436, 377);
- g.drawString(Timing.msToString(getData().getAverageTripTime()), 436, 397);
- g.drawString("" + getData().getEntsDetected(), 436, 417);
- g.setFont(new Font("default", Font.BOLD, 14));
- g.drawString("" + getData().getNestsFound(), 315, 446);
- g.drawString(Game.getRunEnergy() + "%", 415, 446);
- }
- @Override
- public State getInitialState() {
- setGui(new GUI(this));
- while(getGui().isVisible()) {
- sleep(50, 100);
- }
- if(data == null) {
- setData(new Data(this));
- }
- if(banking == null) {
- setBanking(new Bank(this));
- }
- if(duelRing == null) {
- setDuelRing(new DuelRing(this));
- }
- if(potions == null) {
- setPotions(new Potions(this));
- }
- if(axe == null) {
- setAxe(new Axe(this));
- }
- if(sawmill == null) {
- setSawmill(new Sawmill(this));
- }
- if(woodcutting == null) {
- setWoodcutting(new Woodcutting(this));
- }
- if(varrockTab == null) {
- setVarrockTab(new VarrockTab(this));
- }
- if(antiBan == null) {
- setAntiBan(new AntiBan(this));
- }
- //Walking.setControlClick(true);
- //WebWalking.setUseRun(true);
- println("Script Task: " + getTask().toString() + " Plank Type: " + getPlank().toString());
- println("Log Price: " + getLogPrice() + " Plank Price: " + getPlankPrice());
- setEnergyPotionPrice(grabEnergyPotionPrice());
- setCrushedNestPrice(grabCrushedNestPrice());
- setDuelRingPrice(grabDuelRingPrice());
- getData().getInitialData();
- Mouse.setSpeed(125 + General.random(10, 25));
- if(getAxe().isAxeBroken()) {
- setState(State.WALKING_TO_BOB);
- return State.WALKING_TO_BOB;
- }
- if(getWoodcutting().isInsideForest()) {
- setState(State.CHOPPING_DOWN_TREE);
- return State.CHOPPING_DOWN_TREE;
- }
- setState(State.WALKING_TO_BANK);
- return State.WALKING_TO_BANK;
- }
- @Override
- public State handleState(State state) {
- if(isEndScript()) {
- getData().endScriptPrint();
- Thread.currentThread().interrupt();
- return null;
- }
- if(!isOnBreak() && !isPaused()) {
- if(Game.getCurrentWorld() >= 380) {
- Login.logout();
- openWorldScreen();
- if(isWorldScreenOpen()) {
- selectWorld(randomWorlds[General.random(0, randomWorlds.length - 1)]);
- }
- }
- long t = 0;
- switch (LoginState()) {
- case WELCOME_SCREEN:
- case LOGIN_SCREEN:
- Login.login();
- break;
- case HOW_TO_PLAY:
- Mouse.moveBox(13, 470, 97, 491);
- General.sleep(100, 300);
- Mouse.click(1);
- t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < General.random(7000, 10000) && LoginState().equals(LoginState.HOW_TO_PLAY)) {
- General.sleep(300);
- }
- General.sleep(100);
- break;
- case LOBBY:
- Mouse.moveBox(280, 296, 495, 374);
- General.sleep(100, 300);
- Mouse.click(1);
- t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < General.random(7000, 10000) && LoginState().equals(LoginState.LOBBY)) {
- General.sleep(300);
- }
- General.sleep(100);
- break;
- }
- state = getState() != null ? getState() : getInitialState();
- getData().setCurrentXP(Skills.getXP(Skills.SKILLS.MINING));
- getData().setCurrentLevel(Skills.getActualLevel(Skills.SKILLS.MINING));
- getData().checkPlayerRun();
- if(Game.getPlane() >= 1) {
- RSObject[] stairs = Objects.findNearest(10, "Staircase");
- if(stairs != null && stairs.length > 0) {
- if(stairs[0].click("Climb-down")) {
- println("Successfully climbed down stairs");
- }
- } else {
- println("Not correct height level, can't find stairs.");
- }
- }
- switch(state) {
- case BANKING:
- if(Locations.isInsideBank() || Locations.isInsideCastleWars()) {
- getBanking().performBankTask();
- if(getBanking().isFinished()) {
- switch(getTask()) {
- case CHOP_LOGS:
- setState(State.WALKING_TO_TREE);
- return State.WALKING_TO_TREE;
- case CHOP_AND_PLANK:
- if(getPlank().equals(Plank.TEAK)) {
- if(Locations.isInsideBank()) {
- setState(State.WALKING_TO_SAWMILL);
- return State.WALKING_TO_SAWMILL;
- }
- }
- setState(State.WALKING_TO_TREE);
- return State.WALKING_TO_TREE;
- case MAKE_PLANKS:
- setState(State.WALKING_TO_SAWMILL);
- return State.WALKING_TO_SAWMILL;
- }
- }
- }
- setState(State.BANKING);
- return State.BANKING;
- case WALKING_TO_TREE:
- getWoodcutting().walkToForest();
- return State.WALKING_TO_TREE;
- case CHOPPING_DOWN_TREE:
- if(getWoodcutting().canChop()) {
- getWoodcutting().chopTree(getWoodcutting().getClosestTree());
- return State.CHOPPING_DOWN_TREE;
- }
- switch(getTask()) {
- case CHOP_LOGS:
- case CHOP_AND_PLANK:
- if(getPlank().equals(Plank.TEAK)) {
- if(getDuelRing().isWearing()) {
- getDuelRing().rub();
- } else {
- getVarrockTab().teleport();
- }
- setState(State.WALKING_TO_BANK);
- return State.WALKING_TO_BANK;
- }
- setState(State.WALKING_TO_SAWMILL);
- return State.WALKING_TO_SAWMILL;
- }
- setState(State.CHOPPING_DOWN_TREE);
- return State.CHOPPING_DOWN_TREE;
- case WALKING_TO_SAWMILL:
- if(!inventorySetup()) {
- setState(State.WALKING_TO_BANK);
- return State.WALKING_TO_BANK;
- }
- getSawmill().walkToOperator();
- return State.WALKING_TO_SAWMILL;
- case MAKING_PLANKS:
- if(Locations.isInsideSawmill()) {
- getSawmill().performSawmillTask();
- if(getSawmill().isFinished()) {
- setState(State.WALKING_TO_BANK);
- return State.WALKING_TO_BANK;
- }
- return State.MAKING_PLANKS;
- }
- setState(State.WALKING_TO_SAWMILL);
- return State.WALKING_TO_SAWMILL;
- case WALKING_TO_BANK:
- getBanking().walkToBooth();
- return State.WALKING_TO_BANK;
- case WALKING_TO_BOB:
- getAxe().walkToShop();
- return State.WALKING_TO_BOB;
- case REPAIRING_AXE:
- getAxe().repairAxe();
- return State.REPAIRING_AXE;
- }
- return null;
- }
- return State.WAITING;
- }
- private boolean inventorySetup() {
- int amt = getAxe().wearing() ? 0 : 1;
- int logAmount = Inventory.getCount(getPlank().getLogId());
- switch(getTask()) {
- case MAKE_PLANKS:
- if(logAmount > 0) {
- if(Inventory.getCount(995) >= (logAmount * getPlank().getPricePerPlank())) {
- return true;
- }
- }
- return false;
- case CHOP_LOGS:
- return Inventory.getAll().length == amt;
- case CHOP_AND_PLANK:
- int plankPrice = getPlank().getPricePerPlank();
- return (Inventory.getAll().length
- == (amt + 1)
- && Inventory.getCount(995)
- >= (logAmount * plankPrice));
- }
- return false;
- }
- private String getStateToString() {
- switch(getState()) {
- case BANKING:
- return "Banking";
- case WALKING_TO_TREE:
- return "Walking to Tree";
- case CHOPPING_DOWN_TREE:
- return "Chopping Down Tree";
- case WALKING_TO_SAWMILL:
- return "Walking to Sawmill";
- case MAKING_PLANKS:
- return "Making Planks";
- case WALKING_TO_BANK:
- return "Walking to Bank";
- case WALKING_TO_BOB:
- return "Walking to Bob";
- case REPAIRING_AXE:
- return "Repairing Axe";
- case WAITING:
- return "Waiting";
- }
- return "Waiting";
- }
- final int[] randomWorlds = {303,304,305,306,309,310,311,312,313,314,317,318,
- 319,320,321,322,326,327,328,329,333,334,335,336,338,
- 341,342,343,344,345,346,349,350,351,352,353,354,357,358,359,360,
- 361,362,366,367,368,369,370,373,374,375,376,377,378
- };
- final int[] WORLD_COLUMN_1 = {301,302,303,304,305,306,308,309,310,311,312,313,314,316,317,318},
- WORLD_COLUMN_2 = {319,320,321,322,325,326,327,328,329,330,333,334,335,336,337,338},
- WORLD_COLUMN_3 = {341,342,343,344,345,346,349,350,351,352,353,354,357,358,359,360},
- WORLD_COLUMN_4 = {361,362,365,366,367,368,369,370,373,374,375,376,377,378};
- final int[][] WORLD_LIST = { WORLD_COLUMN_1, WORLD_COLUMN_2, WORLD_COLUMN_3, WORLD_COLUMN_4 };
- final int topX = 220,
- topY = 80,
- X_MULTIPLIER = 100,
- Y_MULTIPLIER = 24;
- private boolean isLoggedOut() {
- return !(Login.getLoginState() == STATE.INGAME);
- }
- private void openWorldScreen(){
- if(isLoggedOut()){
- Mouse.clickBox(10, 471, 88, 488, 1);
- sleep(1000,1500);
- }
- }
- private boolean isWorldScreenOpen(){
- Color wScreen = Screen.getColorAt(100, 100);
- return (wScreen.getRed() == 0 && wScreen.getGreen() == 0 && wScreen.getBlue() == 0);
- }
- private boolean selectWorld(int world) {
- int wNum = 0,
- xPos = 0,
- yPos = 0;
- for(int x = 0; x < WORLD_LIST.length; x++){
- for(int y = 0; y < WORLD_LIST[x].length; y++){
- wNum = WORLD_LIST[x][y];
- if(wNum == world){
- xPos = x * X_MULTIPLIER + topX;
- yPos = y * Y_MULTIPLIER + topY;
- Mouse.click(xPos, yPos, 1);
- sleep(1000, 1500);
- return true;
- }
- }
- }
- return false;
- }
- private String getPlankToString() {
- switch(getPlank()) {
- case REGULAR:
- return "Regular Planks";
- case OAK:
- return "Oak Planks";
- case TEAK:
- return "Teak Planks";
- case MAHOGANY:
- return "Mahogany Planks";
- }
- return "";
- }
- private int grabDuelRingPrice() {
- return Methods.getPrice(Constants.DUEL_RING[0]);
- }
- private int grabEnergyPotionPrice() {
- int averagePrice = 0;
- switch(getEnergyPotion()) {
- case REGULAR:
- averagePrice = Methods.getPrice(Constants.ENERGY_POTION[3]);
- break;
- case SUPER:
- averagePrice = Methods.getPrice(Constants.SUPER_ENERGY_POTION[3]);
- break;
- }
- return averagePrice;
- }
- private int grabCrushedNestPrice() {
- return Methods.getPrice(Constants.CRUSHED_NEST);
- }
- public String setInMoneyFormat(double amount) {
- final int ONE_K = 1000;
- final int ONE_M = 1000000;
- if(amount >= ONE_M) {
- return decimalFormat.format(((double) amount / ONE_M)) + "M";
- }
- if(amount >= ONE_K) {
- return decimalFormat.format(((double) amount / ONE_K)) + "K";
- }
- return "" + decimalFormat.format(amount);
- }
- public LoginState LoginState() {
- if (Screen.getColorAt(98, 129).equals(new Color(0, 0, 0))) {
- return LoginState.WORLD_MENU;
- } else if (Screen.getColorAt(423, 248).equals(new Color(255, 255, 0))) {
- return LoginState.WELCOME_SCREEN;
- } else if (Screen.getColorAt(534, 341).equals(new Color(11, 11, 11))) {
- return LoginState.LOGIN_SCREEN;
- } else if (Screen.getColorAt(382, 323).equals(new Color(255, 255, 255))) {
- return LoginState.HOW_TO_PLAY;
- } else if (Screen.getColorAt(365, 340).equals(new Color(255, 255, 255))) {
- return LoginState.LOBBY;
- } else {
- return LoginState.ERROR;
- }
- }
- public Bank getBanking() {
- return banking;
- }
- public void setBanking(Bank banking) {
- this.banking = banking;
- }
- public Data getData() {
- return data;
- }
- public void setData(Data data) {
- this.data = data;
- }
- public Sawmill getSawmill() {
- return sawmill;
- }
- public void setSawmill(Sawmill sawmill) {
- this.sawmill = sawmill;
- }
- public Woodcutting getWoodcutting() {
- return woodcutting;
- }
- public void setWoodcutting(Woodcutting woodcutting) {
- this.woodcutting = woodcutting;
- }
- public void setState(State state) {
- this.state = state;
- }
- public State getState() {
- return state;
- }
- public void setPlank(Plank plank) {
- this.plank = plank;
- }
- public Plank getPlank() {
- return plank;
- }
- public Axe getAxe() {
- return axe;
- }
- public void setAxe(Axe axe) {
- this.axe = axe;
- }
- public void setPlankPrice(double plankPrice) {
- this.plankPrice = plankPrice;
- }
- public double getPlankPrice() {
- return plankPrice;
- }
- public void setEndScript(boolean endScript) {
- this.endScript = endScript;
- }
- public boolean isEndScript() {
- if(getRunningTime() >= (getHoursToRun() * 3600000)) {
- return true;
- }
- return endScript;
- }
- public double getHoursToRun() {
- return hoursToRun;
- }
- public void setHoursToRun(double hoursToRun) {
- this.hoursToRun = hoursToRun;
- }
- public void setGui(GUI gui) {
- this.gui = gui;
- }
- public GUI getGui() {
- return gui;
- }
- public void setEnergyPotion(EnergyPotion energyPotion) {
- this.energyPotion = energyPotion;
- }
- public EnergyPotion getEnergyPotion() {
- return energyPotion;
- }
- public void setEnergyPotionPrice(int energyPotionPrice) {
- this.energyPotionPrice = energyPotionPrice;
- }
- public double getEnergyPotionPrice() {
- return energyPotionPrice;
- }
- public ScriptTask getTask() {
- return task;
- }
- public void setTask(ScriptTask task) {
- this.task = task;
- }
- public void setLogPrice(double logPrice) {
- this.logPrice = logPrice;
- }
- public double getLogPrice() {
- return logPrice;
- }
- public void setCrushedNestPrice(double crushedNestPrice) {
- this.crushedNestPrice = crushedNestPrice;
- }
- public double getCrushedNestPrice() {
- return crushedNestPrice;
- }
- public DuelRing getDuelRing() {
- return duelRing;
- }
- public void setDuelRing(DuelRing duelRing) {
- this.duelRing = duelRing;
- }
- public double getDuelRingPrice() {
- return duelRingPrice;
- }
- public void setDuelRingPrice(double duelRingPrice) {
- this.duelRingPrice = duelRingPrice;
- }
- public void setPotions(Potions potions) {
- this.potions = potions;
- }
- public Potions getPotions() {
- return potions;
- }
- public VarrockTab getVarrockTab() {
- return varrockTab;
- }
- public void setVarrockTab(VarrockTab varrockTab) {
- this.varrockTab = varrockTab;
- }
- public void setAntiBan(AntiBan antiBan) {
- this.antiBan = antiBan;
- }
- public AntiBan getAntiBan() {
- return antiBan;
- }
- private class Cross {
- private final long time;
- private final Point location;
- private final double rot;
- public Cross(long lifetime, long st, Point loc, double rot) {
- this.time = System.currentTimeMillis() + lifetime;
- location = loc;
- this.rot = rot;
- }
- public long getAge() {
- return time - System.currentTimeMillis();
- }
- public int getAlpha() {
- return Math.min(255,
- Math.max(0, (int) (256.0D * (getAge() / 1500.0D))));
- }
- public boolean handle() {
- return System.currentTimeMillis() <= time;
- }
- public double getRot() {
- return rot;
- }
- public Point getLocation() {
- return location;
- }
- @Override
- public boolean equals(Object o) {
- if (o instanceof Cross) {
- Cross oo = (Cross) o;
- return oo.location.equals(this.location);
- }
- return false;
- }
- }
- public double getRot() {
- return System.currentTimeMillis() % 3600 / 5.0D;
- }
- private final List<Cross> clicks = new LinkedList<Cross>();
- private final Object lock = new Object();
- private boolean paintClick;
- public boolean isPaintClick() {
- return paintClick;
- }
- public void setPaintClick(boolean paintClick) {
- this.paintClick = paintClick;
- }
- @Override
- public void mouseDragged(Point arg0, int arg1, boolean arg2) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseMoved(Point arg0, boolean arg1) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseReleased(Point arg0, int arg1, boolean arg2) {
- // TODO Auto-generated method stub
- }
- @Override
- public void paintMouse(Graphics g, Point arg1, Point arg2) {
- final Point location = new Point(Mouse.getPos().x, Mouse.getPos().y);
- g.setColor(Color.GREEN);
- g.drawLine(location.x, location.y - 5, location.x, location.y + 5);
- g.drawLine(location.x - 5, location.y, location.x + 5, location.y);
- if (isPaintClick()) {
- setPaintClick(false);
- Cross newCross = new Cross(1500, General.random(40, 300), location,
- getRot());
- if (!clicks.contains(newCross)) {
- clicks.add(newCross);
- }
- }
- synchronized (lock) {
- Iterator<Cross> clickIterator = clicks.listIterator();
- while (clickIterator.hasNext()) {
- Cross toDraw = clickIterator.next();
- if (toDraw.handle()) {
- drawPoint(toDraw.getLocation(), toDraw.getRot(), g,
- toDraw.getAlpha());
- } else {
- clicks.remove(toDraw);
- }
- }
- }
- }
- private void drawPoint(Point location, double rot, Graphics g, int al) {
- Graphics2D g1 = (Graphics2D) g.create();
- g1.setColor(new Color(255, 0, 0, 155));
- g1.rotate(rot, location.x, location.y);
- g1.drawLine(location.x, location.y - 5, location.x, location.y + 5);
- g1.drawLine(location.x - 5, location.y, location.x + 5, location.y);
- }
- @Override
- public void mouseClicked(Point p, int button, boolean isBot) {
- setPaintClick(true);
- }
- @Override
- public void paintMouseSpline(Graphics arg0, ArrayList<Point> arg1) {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement