Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.mining.essminer;
- 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.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.Camera;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Login;
- import org.tribot.api2007.Player;
- 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.RSNPC;
- 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;
- /**
- * @author Ian
- *
- */
- @ScriptManifest(authors = { "Ian" }, category = "Mining", name = "iEssenceMiner")
- public class EssMiner extends EnumScript<EssState> implements Painting,
- MouseSplinePainting, MousePainting, MouseActions {
- public static final boolean DEBUG = true; // debug the script
- private EssState state = null; // state of the script
- private EssPickaxe pickaxe = null; // pickaxe instance
- private EssLumbridge lumbridge = null; // lumbridge instance
- private EssWalking walking = null; // walking instance
- private EssBanking banking = null; // banking instance
- private EssData data = null; // data instance
- private long lastPlayerRan = 0; // time last player ran
- private long timeout = 0;
- private final String PAINT_PICTURE_URL = "http://i44.tinypic.com/20h3uwo.png";
- private final Image PAINT_IMG = Methods.getImage(PAINT_PICTURE_URL);
- @Override
- public void onPaint(Graphics g) {
- ((Graphics2D)g).drawImage(PAINT_IMG, -40, 310, null);
- g.setFont(new Font("Verdana", Font.BOLD, 11));
- g.setColor(Color.BLUE);
- g.drawString(getState().toString().replaceAll("_", " "), 11, 357);
- int totalEssMined = (Skills.getXP(Skills.SKILLS.MINING) - getData().getStartXP()) / 5;
- int essPerHr = (int) (totalEssMined / ((System.currentTimeMillis() - getData().getStartTime()) / 3600000D));
- g.drawString(totalEssMined + " (" +essPerHr+")", 135, 379);
- g.drawString((Skills.getXP(Skills.SKILLS.MINING) - getData().getStartXP()) + " (" + (Skills.getXPToNextLevel(Skills.SKILLS.MINING)) + ")", 105, 402);
- g.drawString(getData().getCurrentLevel() + " (" + (getData().getCurrentLevel() - getData().getStartLevel()) + ")", 120, 425);
- g.drawString(Timing.msToString(Timing.timeFromMark(getData().getStartTime())), 318, 376);
- int tripsPerHr = (int) (getData().getTripCount()/ ((System.currentTimeMillis() - getData().getStartTime()) / 3600000D));
- g.drawString(getData().getTripCount() + " (" + tripsPerHr + ")", 268, 395);
- g.drawString(Timing.msToString(getData().getLastTripTime()), 333, 412);
- g.drawString(Timing.msToString(getData().getAverageTripTime()), 333, 429);
- }
- /**
- * Sets the state of the script upon start
- */
- @Override
- public EssState getInitialState() {
- if(getData() == null) {
- setData(new EssData(this)); // initialize data instance
- }
- if(getPickaxe() == null) {
- setPickaxe(new EssPickaxe(this)); // initialize pickaxe instance
- }
- if(getLumbridge() == null) {
- setLumbridge(new EssLumbridge(this)); // initialize lumbridge instance
- }
- if(getWalking() == null) {
- setWalking(new EssWalking(this)); // initialize walking instance
- }
- if(getBanking() == null) {
- setBanking(new EssBanking(this)); // initialize banking instance
- }
- getData().getInitialData(); // on paint data
- Walking.setWalkingTimeout(2000); // set the walking timeout
- Mouse.setSpeed(180); // set the mouse speed
- if(EssConstants.isInsideLumbridgeCastle()) { // check lumbridge area for player position
- return EssState.WALKING_TO_LUMBRIDGE_BANK; // set walking to lumbridge bank
- } else if(EssConstants.isInsideBank()) { // check bank area for player position
- return EssState.BANKING; // set the state banking
- } else if(EssConstants.isInsideShop()
- || EssConstants.isInsideEastVarrock()) { // check shop or east varrock area for player position
- if(!Inventory.isFull())
- return EssState.WALKING_TO_AUBURY; // set walking to aubury if you have inventory spaces
- else
- return EssState.WALKING_TO_BANK; // set walking to bank if your inventory is full
- } else if(EssConstants.isInsideMine()) { // check mine area for player position
- if(Inventory.isFull())
- return EssState.WALKING_TO_PORTAL; // set walking to portal if inventory is full
- else
- return EssState.WALKING_TO_ESSENCE; // set walking to essence if you have inventory spaces
- } else
- return EssState.BANKING; // set banking
- }
- private boolean endScript = false;
- 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;
- }
- }
- @Override
- public EssState handleState(EssState state) {
- if(isEndScript()) {
- Thread.currentThread().interrupt();
- return null;
- } else if(!isOnBreak() && !isPaused()) {
- 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));
- if(DEBUG)
- println(state.toString());
- switch(state) {
- case AT_BANK:
- case BANKING:
- if(EssConstants.isInsideBank()) {
- if(getBanking().isCompleted()) {
- return EssState.WALKING_TO_AUBURY;
- }
- }
- return EssState.WALKING_TO_BANK;
- case WALKING_TO_AUBURY:
- if(EssConstants.isInsideEastVarrock()) {
- if(getWalking().walkToAubury()) {
- if(EssConstants.isInsideShop()) {
- return EssState.TELEPORTING;
- }
- }
- }
- return EssState.WALKING_TO_AUBURY;
- case TELEPORTING:
- if(EssConstants.isInsideShop()) {
- teleport();
- return EssState.TELEPORTING;
- }
- if(!EssConstants.isInsideEastVarrock()) {
- setState(EssState.WALKING_TO_ESSENCE);
- return EssState.WALKING_TO_ESSENCE;
- }
- return EssState.WALKING_TO_AUBURY;
- case WALKING_TO_ESSENCE:
- if(EssConstants.isInsideShop()) {
- setState(EssState.TELEPORTING);
- return EssState.TELEPORTING;
- }
- if(EssConstants.isInsideEastVarrock()) {
- setState(EssState.WALKING_TO_AUBURY);
- return EssState.WALKING_TO_AUBURY;
- }
- if(EssConstants.isInsideMine()) {
- if(getWalking().walkToEssence()) {
- if(getData().getEssenceRock() != null) {
- return EssState.MINING_ESSENCE;
- }
- }
- }
- return EssState.TELEPORTING;
- case MINING_ESSENCE:
- if(EssConstants.isInsideMine()) {
- if(mineEssence(getData().getEssenceRock())) {
- if(Inventory.isFull()) {
- return EssState.WALKING_TO_PORTAL;
- }
- }
- return EssState.WALKING_TO_ESSENCE;
- }
- return EssState.WALKING_TO_AUBURY;
- case WALKING_TO_PORTAL:
- if(EssConstants.isInsideShop() || EssConstants.isInsideEastVarrock()) {
- println(getState().toString() + ": Inside shop or east varrock.");
- setState(EssState.WALKING_TO_BANK);
- return EssState.WALKING_TO_BANK;
- }
- if(EssConstants.isInsideMine()) {
- //println(getState().toString() + ": Inside essence mine.");
- if(getWalking().walkToPortal()) {
- if(EssConstants.isInsideShop() || EssConstants.isInsideEastVarrock()) {
- setState(EssState.WALKING_TO_BANK);
- return EssState.WALKING_TO_BANK;
- }
- }
- return EssState.WALKING_TO_PORTAL;
- }
- println(getState().toString() + ": Not inside shop, east varrock, or essence mine.");
- setState(EssState.WALKING_TO_BANK);
- return EssState.WALKING_TO_BANK;
- case WALKING_TO_BANK:
- if(EssConstants.isInsideEastVarrock()) {
- if(getWalking().walkToBank()) {
- if(EssConstants.isInsideBank()) {
- return EssState.AT_BANK;
- }
- }
- }
- return EssState.WALKING_TO_BANK;
- case WALKING_TO_LUMBRIDGE_BANK:
- if(EssConstants.isInsideLumbridgeCastle()) {
- if(getLumbridge().walkToBank()) {
- return EssState.AT_BANK;
- }
- }
- return EssState.BANKING;
- }
- }
- return null;
- }
- /**
- * Teleports using Aubury to the Essence mine
- * @return Inside essence mine
- */
- private boolean teleport() {
- /*
- * Attempt to teleport
- */
- setTimeout(System.currentTimeMillis());
- while(EssConstants.isInsideEastVarrock() && !isTimedOut(7000, 8000)) {
- if(DEBUG)
- println(getState().toString() + ": Teleport loop");
- /*
- * Open blocking shop door
- */
- if(getWalking().nearClosedDoor()) {
- getWalking().openDoor();
- }
- RSNPC aubury = Methods.findNPCByModelPoints(new int[]{EssConstants.AUBURY});
- if(aubury != null) {
- /*
- * Walk to aubury farther than 3 squares away
- */
- if(!Player.isMoving() && Methods.distanceTo(this, aubury.getPosition()) > 3)
- WebWalking.walkTo(aubury);
- aubury.click("Teleport");
- /*
- * Change state once in the mine
- */
- if(isFinishedTeleporting(500)) {
- setState(EssState.WALKING_TO_ESSENCE);
- return true;
- }
- } else {
- if(DEBUG)
- println(getState().toString() + ": AUBURY NULL");
- }
- }
- return false;
- }
- /**
- * Mines the closest essence rock
- * @param essence - RSObject essence rock
- * @return full inventory
- */
- public boolean mineEssence(RSObject essence) {
- setState(EssState.MINING_ESSENCE);
- /*
- * Checks if your inventory is full
- */
- if(isInventoryFull()) {
- return true;
- }
- /*
- * Finds a new essence rock if the parameter returns null
- */
- if(essence == null) {
- essence = Methods.findObjectByModelPoints(new int[]{EssConstants.ESSENCE_ROCK});
- }
- /*
- * Checks if the parameter essence rock is the distance
- * of the closest essence rock
- */
- if(!isCorrectDistance(Methods.distanceTo(this, essence.getPosition()))) {
- return false;
- }
- Inventory.open();
- Camera.turnToTile(essence);
- /*
- * Attempt to click essence rock
- */
- setTimeout(System.currentTimeMillis());
- while(Player.getAnimation() <= -1 && !isTimedOut(4000, 5000)) {
- if(DEBUG)
- println(getState().toString() + ": no animation loop");
- if(essence.getPosition().distanceTo(Player.getPosition()) > 4) {
- WebWalking.walkTo(essence);
- }
- Camera.turnToTile(essence);
- essence.click("Mine");
- startedMining(2000);
- }
- /*
- * Sleep while mining animations are being played
- */
- setTimeout(System.currentTimeMillis());
- while(Player.getAnimation() >= 624 && Player.getAnimation() <= 630 && !isTimedOut(90000, 120000)) {
- if(DEBUG)
- println(getState().toString() + ": animation loop");
- if(isInventoryFull()) {
- return true;
- }
- finishedMining(2000);
- }
- /*
- * failsafe, attempt the method again if inventory
- * still has spaces and you don't have an animation
- */
- if(!isInventoryFull() && Player.getAnimation() <= -1) {
- return mineEssence(essence);
- }
- return false;
- }
- /**
- *
- * @param object - RSObject portal
- * @param npc - RSNPC portal
- * @return Used portal successfully
- */
- public boolean usePortal(RSObject object, RSNPC npc) {
- /*
- * Portal sometimes is an object or an npc
- */
- if(object != null) {
- if(!object.isOnScreen()) {
- Camera.turnToTile(object);
- }
- /*
- * Farther than 4 squares away then walk to the portal
- */
- if(Methods.distanceTo(this, object.getPosition()) > 4) {
- WebWalking.walkTo(object);
- }
- /*
- * Attempt to click portal
- */
- setTimeout(System.currentTimeMillis());
- while(Methods.distanceTo(this, object.getPosition()) < 5 && !isTimedOut(7000, 8000)) {
- object.click(new String[]{"Use", "Exit"});
- usedPortal(500);
- }
- /*
- * Walk to the bank if you made it to the shop
- */
- if(EssConstants.isInsideShop()) {
- setState(EssState.WALKING_TO_BANK);
- return true;
- }
- }
- if(npc != null) {
- if(!npc.isOnScreen()) {
- Camera.turnToTile(npc);
- }
- /*
- * Farther than 4 squares away then walk to the portal
- */
- if(Methods.distanceTo(this, npc.getPosition()) > 4) {
- WebWalking.walkTo(npc);
- }
- /*
- * Attempt to click portal
- */
- setTimeout(System.currentTimeMillis());
- while(Methods.distanceTo(this, npc.getPosition()) < 5 && !isTimedOut(7000, 8000)) {
- npc.click(new String[]{"Use", "Exit"});
- usedPortal(500);
- }
- /*
- * Walk to the bank if you made it to the shop
- */
- if(EssConstants.isInsideShop()) {
- setState(EssState.WALKING_TO_BANK);
- return true;
- }
- }
- return false;
- }
- public boolean isTimedOut(int min, int max) {
- if(System.currentTimeMillis() - getTimeout() < General.random(min, max)) {
- return false;
- }
- return true;
- }
- private int distanceToClosestEssenceRock() {
- return Methods.findObjectByModelPoints(new int[]{EssConstants.ESSENCE_ROCK}).getPosition().distanceTo(Player.getPosition());
- }
- private boolean isInventoryFull() {
- if(Inventory.isFull()) {
- getData().setEssenceRock(null);
- setState(EssState.WALKING_TO_PORTAL);
- return true;
- }
- return false;
- }
- public boolean isCorrectDistance(int distance) {
- if(distance > distanceToClosestEssenceRock()) {
- setState(EssState.WALKING_TO_ESSENCE);
- getData().setEssenceRock(Methods.findObjectByModelPoints(new int[]{EssConstants.ESSENCE_ROCK}));
- return false;
- }
- return true;
- }
- public boolean isFinishedTeleporting(int time) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < time) {
- if (!EssConstants.isInsideEastVarrock()) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean finishedMining(int time) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < time) {
- if (Inventory.isFull() || Player.getAnimation() <= -1) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean startedMining(int time) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < time) {
- if (Player.getAnimation() >= 624 && Player.getAnimation() <= 630) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean usedPortal(int time) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < time) {
- if (EssConstants.isInsideShop()) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- public void setPickaxe(EssPickaxe pickaxe) {
- this.pickaxe = pickaxe;
- }
- public EssPickaxe getPickaxe() {
- return pickaxe;
- }
- public void setLumbridge(EssLumbridge essLumbridge) {
- this.lumbridge = essLumbridge;
- }
- public EssLumbridge getLumbridge() {
- return lumbridge;
- }
- public void setWalking(EssWalking walking) {
- this.walking = walking;
- }
- public EssWalking getWalking() {
- return walking;
- }
- public void setBanking(EssBanking banking) {
- this.banking = banking;
- }
- public EssBanking getBanking() {
- return banking;
- }
- public void setData(EssData data) {
- this.data = data;
- }
- public EssData getData() {
- return data;
- }
- public void setState(EssState state) {
- this.state = state;
- }
- public EssState getState() {
- return state;
- }
- public long getLastPlayerRan() {
- return lastPlayerRan;
- }
- public void setTimeout(long timeout) {
- this.timeout = timeout;
- }
- public long getTimeout() {
- return timeout;
- }
- public void setLastPlayerRan(long lastPlayerRan) {
- this.lastPlayerRan = lastPlayerRan;
- }
- public List<Cross> getClicks() {
- return clicks;
- }
- public Object getLock() {
- return lock;
- }
- public void setPaintClick(boolean paintClick) {
- this.paintClick = paintClick;
- }
- public boolean isPaintClick() {
- return paintClick;
- }
- 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;
- @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 (!getClicks().contains(newCross)) {
- getClicks().add(newCross);
- }
- }
- synchronized (getLock()) {
- Iterator<Cross> clickIterator = getClicks().listIterator();
- while (clickIterator.hasNext()) {
- Cross toDraw = clickIterator.next();
- if (toDraw.handle()) {
- drawPoint(toDraw.getLocation(), toDraw.getRot(), g,
- toDraw.getAlpha());
- } else {
- getClicks().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 mouseDragged(Point arg0, int arg1, boolean arg2) {
- }
- @Override
- public void mouseMoved(Point arg0, boolean arg1) {
- }
- @Override
- public void mouseReleased(Point arg0, int arg1, boolean arg2) {
- }
- @Override
- public void paintMouseSpline(Graphics arg0, ArrayList<Point> arg1) {
- }
- public boolean isEndScript() {
- return endScript;
- }
- public void setEndScript(boolean endScript) {
- this.endScript = endScript;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement