Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import org.tribot.api.DynamicClicking;
- import org.tribot.api.General;
- import org.tribot.api2007.*;
- import org.tribot.api2007.GameTab.TABS;
- import org.tribot.api2007.types.*;
- import org.tribot.script.*;
- import org.tribot.script.interfaces.*;
- import org.tribot.api.input.*;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import java.awt.*;
- @ScriptManifest(authors = { "Moose" }, category = "Mining", name = "Moose's essence miner")
- public class MooseEssence extends Script implements ActionListener, Painting, Ending {
- @Override
- public void run() {
- running = true;
- onStart();
- while(running) {
- try {
- loop();
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * MooseEssence
- * @author Mooselet
- * Free to use and modify as you like.
- * Didn't put many comments because I made the code very easy to understand.
- */
- private boolean running = false;
- private final boolean debug = false;
- private boolean paintEnabled = true;
- private final int ESSENCE_ID = 10074;
- private final int PORTAL_ID = 10075;
- private final int AUBURY_ID = 158;
- private final int RUNE_ESSENCE = 1436;
- private final int PURE_ESSENCE = 7936;
- private final int CLOSED_DOOR_ID = 24381;
- private final int BROKEN_PICK_ID = 466;
- private final RSTile AT_ESSENCE = new RSTile(2910, 4831);
- private final RSTile IN_RUNE_SHOP = new RSTile(3253, 3401);
- private final RSTile IN_BANK = new RSTile(3253, 3420);
- private final RSTile IN_ABYSS = new RSTile(2338, 4747);
- private final int[] MINING_ANIMATIONS = {624, 628, 629, 627, 626, 625};
- private final int[] PICK_HEADS = {480, 482, 484, 486, 488, 490};
- private final int[] PICKAXE_IDS = {1265, 1267, 1269, 1271, 1273, 1275};
- private int essenceMined = 0;
- private Image proggyImage;
- private long startTime = 0;
- private int antiBanFreq = 40;
- private final RSTile IN_THE_MIDDLE = new RSTile(3256, 3408);
- private String emailAddress = null;
- private JFrame jf;
- private int uploadAttempts = 0;
- public boolean inMine() {
- return AT_ESSENCE.distanceTo(Player.getPosition()) < 100;
- }
- public boolean inAbyss() {
- return IN_ABYSS.distanceTo(Player.getPosition()) < 2;
- }
- public boolean isLost() {
- return (IN_THE_MIDDLE.distanceTo(Player.getPosition()) > 30 && !inMine() && !inAbyss())/* || Players.getLocal().getHeight() != 0*/; //is getHeight() broken too? Causes this function to return true even when height=0
- }
- public void doDoor() {
- RSObject fagDoor = getNearest(CLOSED_DOOR_ID);
- if(fagDoor != null && !isMoving()) {
- if(fagDoor.getPosition().getX() == 3253 && fagDoor.getPosition().getY() == 3398 && fagDoor.getPosition().distanceTo(Player.getPosition()) < 6) {
- if(fagDoor.isOnScreen()) {
- customLog("Opening door cuz kids r mad");
- fagDoor.click("Open", new Point(-10, 10), new Point(0, -40));
- sleep(300, 700);
- } else {
- customWalkTo(fagDoor.getPosition());
- }
- }
- }
- }
- public void homeTeleport() {
- /*
- customLog("We're lost - Home teleport!");
- GameTab.open(TABS.MAGIC);
- sleep(750, 3000);
- Point p = Widgets.get(192).getChild(0).getPoint();
- p.y += 5;
- p.x += 5;
- Mouse.move(p);
- sleep(200, 1000);
- Mouse.click(p);
- sleep(10000, 20000);
- Game.openTab(Tab.INVENTORY);
- */
- //Not really needed anymore but there'll probably eventually be a use.
- }
- public boolean hasPickaxeHead() {
- return Inventory.getCount(PICK_HEADS) > 0;
- }
- public boolean hasPickaxe() {
- if(Inventory.getCount(PICKAXE_IDS) > 0) {
- return true;
- }
- RSItem[] equipment = getEquipment();
- for(int j = 0; j < PICKAXE_IDS.length; j++) {
- for(int i = 0; i < equipment.length; i++) {
- if(equipment[i].getID() == PICKAXE_IDS[j])
- return true;
- }
- }
- return false;
- }
- public void putPickaxeTogether() {
- if(Inventory.getCount(BROKEN_PICK_ID) < 1) {
- unequipItem(BROKEN_PICK_ID);
- } else {
- RSItem[] brokenPicks = Inventory.find(BROKEN_PICK_ID);
- RSItem brokenPick = null;
- RSItem[] pickaxes = Inventory.find(PICK_HEADS);
- RSItem pickaxe = null;
- if(brokenPicks.length < 1 || pickaxes.length < 1)
- return;
- brokenPick = brokenPicks[0];
- pickaxe = pickaxes[0];
- brokenPick.click(null);
- pickaxe.click(null);
- }
- }
- public boolean pickupPickHead() {
- customLog("Finding pickaxe head");
- RSGroundItem[] pickHeads = GroundItems.findNearest(PICK_HEADS);
- RSGroundItem pickHead = null;
- if(pickHeads.length < 1) {
- return false;
- }
- pickHead = pickHeads[0];
- if(pickHead != null) {
- if(pickHead.isOnScreen()) {
- pickHead.click("Take");
- } else {
- customWalkTo(pickHead.getPosition());
- }
- return true;
- }
- return false;
- }
- public void attemptAbyssSolve() {
- customLog("In the abyss..");
- int random = General.random(12722, 12725);
- RSObject appendage = getNearest(random);
- if(appendage == null)
- return;
- if(appendage.isOnScreen()) {
- if(appendage.click("Operate")) {
- sleep(2000, 3000);
- customLog("Guessing on appendage..");
- return;
- } else {
- //Camera.turnToRSTile(appendage.getPosition());
- Camera.turnToTile(appendage.getPosition());
- sleep(300, 750);
- customLog("Turning camera to see appendage");
- }
- }
- }
- public void goDownstairs() {
- if(IN_BANK.distanceTo(Player.getPosition()) < 6)
- return;
- RSObject stairs;
- stairs = getNearest(24353);
- if(stairs == null)
- return;
- if(stairs.isOnScreen()) {
- if(stairs.click("Climb-down")) {
- sleep(2000, 4000);
- customLog("Attempting to go back downstairs");
- return;
- } else {
- Camera.turnToTile(stairs.getPosition());
- sleep(300, 750);
- customLog("Finding stairs..");
- }
- }
- }
- public boolean isMining() {
- for(int i = 0; i < MINING_ANIMATIONS.length; i++) {
- if(Player.getAnimation() == MINING_ANIMATIONS[i]) {
- return true;
- }
- }
- return false;
- }
- @Override
- public void onEnd() {
- println("Moose's essence miner is shutting down- Generating proggy!");
- println("Ran for " + runTime(startTime));
- println("Mined "+essenceMined+" essences");
- //uploadProggy(Account.getWbotUsername(), System.currentTimeMillis() - startTime, essenceMined);
- //Proggys are for another day.
- }
- public void uploadProggy(String username, long time, int essence) {
- // Had code to upload proggies here but I don't want to open-source it for obvious reasons.
- }
- public RSObject getNearest(int ID) {
- RSObject[] obj = Objects.findNearest(104, ID);
- if(obj.length < 1)
- return null;
- return obj[0];
- }
- public boolean mineEssence() {
- RSObject ess = getNearest(ESSENCE_ID);
- if(ess == null)
- return false;
- if(ess.isOnScreen()) {
- if(isMining()) { //Are we mining?
- sleep(2000);
- return true;
- } else if(!isMining()) { //Let's double check if we're mining so we don't doubleclick
- sleep(1500);
- if(isMining())
- return true;
- }
- int fails = 0;
- while(!DynamicClicking.clickRSObject(ess, "Mine Rune Essence") && !isMining()) {
- //sleep(700);
- //while(!ess.click("Mine Rune Essence", new Point(General.random(-100, 100), General.random(-100, 100)), null) && !isMining()) {
- fails++;
- if(fails == 5) {
- customWalkTo(ess.getPosition());
- if(General.random(1, 3) == 3)
- Camera.setCameraRotation(General.random(10, 360));
- fails = 0;
- }
- }
- customLog("Mining");
- sleep(600);
- while(isMoving())
- sleep(1000);
- return true;
- } else {
- if(!inMine())
- customLog("We're not in Kansas anymore todo~!"); //This is bad.
- walkToEssence(); //We're either in a random or in the center of the essence mine
- }
- return false;
- }
- public void walkToEssence() {
- RSObject ess = getNearest(ESSENCE_ID);
- if(ess != null) {
- if(ess.getPosition().distanceTo(Player.getPosition()) < 30 && !isMoving() && !isMining()) {
- customWalkTo(ess.getPosition());
- return;
- }
- }
- RSTile[] t = new RSTile[4];
- t[0] = new RSTile(2919, 4840);
- t[1] = new RSTile(2902, 4841);
- t[2] = new RSTile(2902, 4822);
- t[3] = new RSTile(2919, 4822);
- RSTile nearest = getNearest(t);
- if(nearest.distanceTo(Player.getPosition()) < 30 && !isMoving()) {
- customWalkTo(nearest);
- sleep(500, 1000);
- }
- }
- public static RSTile getNearest(RSTile[] t){
- RSTile nearest = null;
- double distance = 9999999;
- for (RSTile object : t){
- if (object.distanceTo(Player.getPosition()) < distance){
- nearest = object;
- distance = object.distanceTo(Player.getPosition());
- }
- }
- return nearest;
- }
- public boolean isMoving() {
- //if(!Player.isMoving())
- // return false;
- //return Calculations.distanceTo(Walking.getDestination()) >= 3;
- //Walking.
- return Player.isMoving();
- }
- public boolean usePortal() {
- RSObject portal = getNearest(PORTAL_ID);
- if(portal == null)
- return false;
- if(portal.isOnScreen()) {
- if(DynamicClicking.clickRSObject(portal, "Use")) {
- int fails = 0;
- while(portal.isOnScreen() && fails < 11) {
- sleep(200, 400);
- fails++;
- }
- customLog("Teleported.");
- return true;
- } else if(General.random(0, 10) == 10) {
- Camera.turnToTile(portal.getPosition());
- }
- } else {
- if(portal.getPosition().distanceTo(Player.getPosition()) < 20 && !isMoving()) {
- customWalkTo(portal.getPosition());
- }
- }
- return false;
- }
- public boolean inRuneShop() {
- for(int i = 0; i < randomAubury.length; i++) {
- if(Player.getPosition().equals(randomAubury[i]))
- return true;
- }
- return false;
- }
- public boolean inBank() {
- if(IN_BANK.distanceTo(Player.getPosition()) < 5)
- return true;
- return false;
- }
- public static Image getImage(String url) {
- Image img = null;
- try {
- URL link = new URL(url);
- img = ImageIO.read(link);
- } catch (Exception e) {
- }
- return img;
- }
- public boolean openBank() {
- return General.random(1,2) == 1 ? Banking.openBankBooth() : Banking.openBankBanker();
- }
- public boolean doBank() {
- int fails = 0;
- GameTab.open(TABS.INVENTORY);
- if(!GameTab.getOpen().equals(TABS.INVENTORY))
- return false;
- boolean success = false;
- if (openBank()) {
- sleep(500);
- fails = 0;
- while(isMoving()) {
- sleep(100);
- fails++;
- if(fails == 15)
- break;
- }
- if(isMoving() || !Banking.isBankScreenOpen())
- return false;
- if(Inventory.getCount(PURE_ESSENCE) > 0) //Do we have pure essence?
- if(Banking.deposit(28, PURE_ESSENCE)) {
- success = true;
- //sleep(200, 500);
- }
- if(Inventory.getCount(RUNE_ESSENCE) > 0) //Do we have rune essence?
- if(Banking.deposit(28, RUNE_ESSENCE)) {
- success = true;
- //sleep(200, 500);
- }
- if(Inventory.getCount(PURE_ESSENCE + 1) > 0) //Do we have pure essence(noted)?
- if(Banking.deposit(999, PURE_ESSENCE + 1)) {
- success = true;
- //sleep(200, 500);
- }
- if(Inventory.getCount(995) > 0) //Do we have $?
- if(Banking.deposit(99999, 995)) {
- success = true;
- //sleep(200, 500);
- }
- sleep(500, 600);
- return success;
- } else {
- if(!isMoving())
- customWalkTo(IN_BANK);
- }
- return false;
- }
- public boolean teleportIntoMine() {
- RSNPC[] AuburyArray = NPCs.find(AUBURY_ID);
- RSNPC Aubury;
- if(AuburyArray.length < 1)
- return false;
- else
- Aubury = AuburyArray[0];
- if(Aubury == null)
- return false;
- if(Aubury.getPosition().distanceTo(Player.getPosition()) > 4)
- return false;
- doDoor();
- if(Aubury.isOnScreen()) {
- if(Aubury.click("Teleport")) {
- int fails = 0;
- while(IN_RUNE_SHOP.distanceTo(Player.getPosition()) < 10) {
- sleep(200, 400);
- fails++;
- if(fails > 15)
- break;
- }
- } else if(General.random(0, 10) == 10) {
- Camera.turnToTile(Aubury.getPosition());
- }
- } else if(Aubury.getPosition().distanceTo(Player.getPosition()) < 8 && !isMoving()) {
- Walking.blindWalkTo(randomAubury[General.random(0, randomAubury.length - 1)]);
- }
- return false;
- }
- public void loop() throws Exception {
- sleep(100);
- if(isLost()) {
- if(PathFinding.canReach(IN_BANK, false))
- PathFinding.aStarWalk(IN_BANK);
- //homeTeleport();
- }
- if(inAbyss())
- attemptAbyssSolve();
- goDownstairs(); //Failsafe..
- if(inMine() && Inventory.isFull()) {
- if(!usePortal())
- customLog("Searching for portal..");
- }
- if(!inMine() && !inBank() && Inventory.isFull()) {
- if(IN_BANK.distanceTo(Player.getPosition()) < 60 && !isMoving()) {
- doDoor();
- customWalkTo(IN_BANK);
- sleep(400, 600);
- }
- customLog("Walking to the bank");
- } else {
- if(!inMine() && !inRuneShop() && !Inventory.isFull()) {
- if(IN_RUNE_SHOP.distanceTo(Player.getPosition()) < 60 && !isMoving()) {
- doDoor();
- Walking.blindWalkTo(randomAubury[General.random(0, randomAubury.length - 1)]);
- sleep(400, 700);
- }
- customLog("Walking to the rune shop");
- }
- }
- if(inBank() && Inventory.isFull()) {
- int essThisRun = Inventory.getCount(PURE_ESSENCE) + Inventory.getCount(RUNE_ESSENCE);
- if(doBank())
- essenceMined += essThisRun;
- customLog("Banking.");
- }
- if(inRuneShop() && !Inventory.isFull()) {
- if(!teleportIntoMine())
- customLog("Teleporting via Aubury..");
- }
- if(isMining()) { //Do antiban as we mine the essence
- antiban();
- }
- if(inMine() && !Inventory.isFull()) {
- if(!hasPickaxe()) {
- if(!hasPickaxeHead()) {
- pickupPickHead();
- sleep(700, 1700);
- } else if(hasPickaxeHead()) {
- putPickaxeTogether();
- sleep(700, 1700);
- } else {
- println("We completely lost our pickaxe.. Sorry.");
- }
- return;
- }
- if(Player.getRSPlayer().isInCombat()) {
- usePortal();
- return;
- }
- if(!mineEssence())
- customLog("Searching for essence deposit..");
- }
- if(!(Login.getLoginState() == Login.STATE.INGAME) || jf != null) {
- customLog("Not logged in");
- }
- }
- public boolean onStart() {
- startTime = System.currentTimeMillis();
- proggyImage = getImage("http://i.imgur.com/NBRkT7v.png");
- Mouse.setSpeed(140);
- //initComponents();
- customLog("MooseEssence starting up.. Report bugs on the thread!!");
- return true;
- }
- private Object lastText;
- public void customLog(Object text) { //Prevent spam from the script..
- if(debug)
- println(text);
- lastText = text;
- }
- public void customWalkTo(RSTile t) {
- Walking.control_click = true;
- t = new RSTile(t.getX() + General.random(-1, +1), t.getY() + General.random(-1, +1));
- if(t.distanceTo(Player.getPosition()) < 6 && General.random(1, 2) == 1)
- Walking.walkScreenPath(Walking.generateStraightPath(t));
- else
- Walking.walkPath(Walking.generateStraightPath(t));
- sleep(50, 200);
- if(Objects.getAt(t) != null) { //There's an object blocking our path.
- if(General.random(1, 2) == 1)
- Camera.setCameraRotation(General.random(0, 360));
- else
- Camera.setCameraAngle(General.random(0, 100));
- }
- sleep(200, 400);
- }
- public void antiban() { //Leeched from Cona's willow script :)
- int random = General.random(1, antiBanFreq * 2);
- String antibanString = null;
- switch (random) {
- case 1:
- antibanString = "Antiban - Camera Pitch";
- Camera.setCameraRotation(General.random(200, 300));
- break;
- case 2:
- antibanString = "Antiban - Camera Angle";
- Camera.setCameraAngle(General.random(10, 360));
- break;
- case 3:
- antibanString = "Antiban - Mouse movement";
- Mouse.move(General.random(1, 200), General.random(1, 200));
- break;
- case 4:
- antibanString = "Antiban - Stat Check";
- Point p = new Point(562 + General.random(0, 162), 216 + General.random(0, 200));
- GameTab.open(TABS.STATS);
- sleep(200, 500);
- Mouse.move(p);
- sleep(1000, 6000);
- GameTab.open(TABS.INVENTORY);
- break;
- case 5:
- antibanString = "Antiban - View player";
- Camera.turnToTile(Player.getPosition());
- break;
- case 6:
- RSPlayer[] players = Players.getAll();
- if(players.length < 1)
- break;
- players[General.random(0, players.length - 1)].hover();
- antibanString = "Viewing another player";
- break;
- case 7:
- GameTab.open(TABS.values()[General.random(0, TABS.values().length - 1)]);
- antibanString = "Opening a random tab";
- break;
- default:
- antibanString = null;
- break;
- }
- if(antibanString != null)
- customLog(antibanString);
- }
- @Override
- public void onPaint(Graphics g1) {
- if(!paintEnabled)
- return;
- Graphics2D g = (Graphics2D)g1;
- if(proggyImage != null) {
- g.drawImage(proggyImage, 6, 344, null);
- if(lastText != null)
- g.drawString(lastText.toString(), 182, 402);
- g.drawString(""+essenceMined+"", 251, 446);
- g.drawString(""+runTime(startTime)+"", 195, 424);
- } else {
- g.drawString("Moose's essence miner", 10, 295);
- if(lastText != null)
- g.drawString("Status: " +lastText.toString(), 10, 310);
- g.drawString("Essences mined: "+essenceMined+"", 10, 320);
- g.drawString("Time running: "+runTime(startTime)+"", 10, 330);
- }
- }
- public String runTime(long i)
- {
- DecimalFormat nf = new DecimalFormat("00");
- long millis = System.currentTimeMillis() - i;
- long hours = millis / 3600000L;
- millis -= hours * 3600000L;
- long minutes = millis / 60000L;
- millis -= minutes * 60000L;
- long seconds = millis / 1000L;
- return nf.format(hours) + ":" + nf.format(minutes) + ":" + nf.format(seconds);
- }
- private final RSTile[] randomAubury = {
- new RSTile(3255, 3401),
- new RSTile(3254, 3401),
- new RSTile(3253, 3401),
- new RSTile(3252, 3401),
- new RSTile(3252, 3400),
- new RSTile(3253, 3400),
- new RSTile(3252, 3399),
- new RSTile(3253, 3399),
- new RSTile(3254, 3402),
- new RSTile(3253, 3402),
- new RSTile(3252, 3402),
- new RSTile(3252, 3403),
- new RSTile(3253, 3403)
- };
- private void initComponents() {
- // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
- // Generated using JFormDesigner Evaluation license
- jf = new JFrame();
- jf.setVisible(true);
- label3 = new JLabel();
- label4 = new JLabel();
- label1 = new JLabel();
- slider1 = new JSlider(1, 10);
- slider1.setInverted(true);
- label2 = new JLabel();
- textField1 = new JTextField();
- radioButton1 = new JRadioButton();
- radioButton2 = new JRadioButton();
- button1 = new JButton();
- //======== this ========
- Container contentPane = jf.getContentPane();
- contentPane.setLayout(new GridLayout(10, 1));
- //---- label3 ----
- label3.setText("---------- Moose's essence miner settings ----------");
- contentPane.add(label3);
- contentPane.add(label4);
- //---- label1 ----
- label1.setText("Antiban Frequency(1-10)");
- contentPane.add(label1);
- contentPane.add(slider1);
- //---- label2 ----
- label2.setText("E-mail address(Can be blank):");
- contentPane.add(label2);
- contentPane.add(textField1);
- //---- radioButton1 ----
- radioButton1.setText("Send e-mail on script terminate");
- contentPane.add(radioButton1);
- //---- radioButton2 ----
- radioButton2.setText("Hide paint");
- contentPane.add(radioButton2);
- //---- button1 ----
- button1.setText("Start");
- contentPane.add(button1);
- jf.pack();
- jf.setLocationRelativeTo(jf.getOwner());
- // JFormDesigner - End of component initialization //GEN-END:initComponents
- button1.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e) {
- if(radioButton1.isSelected())
- emailAddress = textField1.getText();
- paintEnabled = !radioButton2.isSelected();
- antiBanFreq = slider1.getValue();
- jf.dispose();
- jf = null;
- }
- private RSItem[] getEquipment(){
- RSInterfaceChild equip = Interfaces.get(387, 28);
- RSItem[] items = null;
- if(equip != null){
- items = equip.getItems();
- }
- return items;
- }
- public boolean unequipItem(int itemID) {
- GameTab.open(TABS.EQUIPMENT);
- RSItem[] items = getEquipment();
- for(RSItem item: items) {
- if(item.getID() == itemID) {
- item.click("Remove");
- return true;
- }
- }
- return false;
- }
- // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
- // Generated using JFormDesigner Evaluation license
- private JLabel label3;
- private JLabel label4;
- private JLabel label1;
- private JSlider slider1;
- private JLabel label2;
- private JTextField textField1;
- private JRadioButton radioButton1;
- private JRadioButton radioButton2;
- private JButton button1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement