Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.io.IOException;
- import java.net.URL;
- import javax.imageio.ImageIO;
- import org.powerbot.concurrent.Task;
- import org.powerbot.concurrent.strategy.Condition;
- import org.powerbot.concurrent.strategy.Strategy;
- import org.powerbot.game.api.ActiveScript;
- import org.powerbot.game.api.Manifest;
- import org.powerbot.game.api.methods.Calculations;
- import org.powerbot.game.api.methods.Tabs;
- import org.powerbot.game.api.methods.Walking;
- import org.powerbot.game.api.methods.Widgets;
- import org.powerbot.game.api.methods.input.Mouse;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.node.SceneEntities;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.methods.tab.Skills;
- import org.powerbot.game.api.methods.widget.Camera;
- import org.powerbot.game.api.util.Filter;
- import org.powerbot.game.api.util.Random;
- import org.powerbot.game.api.util.Time;
- import org.powerbot.game.api.wrappers.Area;
- import org.powerbot.game.api.wrappers.Tile;
- import org.powerbot.game.api.wrappers.node.SceneObject;
- import org.powerbot.game.bot.event.MessageEvent;
- import org.powerbot.game.bot.event.listener.MessageListener;
- import org.powerbot.game.bot.event.listener.PaintListener;
- @Manifest(name = "Mining Guild Miner", description = "Mines coal in the mining guild. And banks!", version = 2, authors = {"Tobdan"})
- public class MiningGuildMiner extends ActiveScript implements PaintListener, MessageListener, MouseListener{
- final static int Coal_IDS[] = {5770, 5771, 5772};
- final static int Pick_IDS[] = {1265, 1267, 1269, 1271, 1275, 15259};
- final static int Bank_ID = 11758;
- final static int Ladder_Up_ID = 6226;
- final static int Ladder_Down_ID = 2113;
- final static Area MINING_AREA = new Area(new Tile(3017,9756,0), new Tile(3055,9732,0));
- final static Area BANK_AREA = new Area(new Tile(3009,3355,0), new Tile(3018,3358,0));
- final static Tile[] Exit_MG = {new Tile(3037,9738,0), new Tile(3021,9739,0)};
- final static Tile[] StairsToBank = {new Tile(3019,3337,0), new Tile(3031,3348,0), new Tile(3022,3361,0), new Tile(3012,3356,0)};
- final static Tile[] reversedStairsToBank = reversePath(StairsToBank);
- SceneObject oldRock;
- static Image img1 = null;
- static boolean hidePaint = false;
- long startTime;
- static int startExp, startLvl, oresMined;
- final static int coalPrice = 247;
- @Override
- protected void setup() {
- final Walk walk = new Walk();
- final MineCoal mineCoal = new MineCoal();
- final Bank bank = new Bank();
- final AntiBan antiBan = new AntiBan();
- final ImageLoader iL = new ImageLoader();
- final WidgetCloser wCloser = new WidgetCloser();
- final Strategy walkStrategy = new Strategy(walk,walk);
- final Strategy mineCoalStrategy = new Strategy(mineCoal, mineCoal);
- final Strategy bankStrategy = new Strategy(bank, bank);
- final Strategy antiBanStrategy = new Strategy(antiBan, antiBan);
- final Strategy iLStrategy = new Strategy(iL,iL);
- final Strategy wCloserStrategy = new Strategy(wCloser,wCloser);
- provide(walkStrategy);
- provide(mineCoalStrategy);
- provide(bankStrategy);
- provide(antiBanStrategy);
- provide(iLStrategy);
- provide(wCloserStrategy);
- startTime = System.currentTimeMillis();
- startExp = Skills.getExperiences()[14];
- startLvl = Skills.getLevels()[14];
- }
- private final class Walk implements Task, Condition {
- private boolean toBank = false;
- public boolean validate() {
- if(Players.getLocal().isMoving()) {
- return false;
- }
- return Inventory.getCount() == 28 && !BANK_AREA.contains(Players.getLocal().getLocation()) || Inventory.getCount() != 28 && !MINING_AREA.contains(Players.getLocal().getLocation());
- }
- @Override
- public void run() {
- if(Widgets.get(762, 1).isOnScreen())
- {
- Widgets.get(762, 45).click(true);
- Time.sleep(Random.nextInt(875, 1450));
- }
- if(Inventory.getCount() == 28)
- {
- toBank = true;
- } else {
- toBank = false;
- }
- if(toBank){
- if(MINING_AREA.contains(Players.getLocal().getLocation())){
- if(SceneEntities.getNearest(Ladder_Up_ID).isOnScreen()){
- if(SceneEntities.getNearest(Ladder_Up_ID).click(true)){
- Time.sleep(Random.nextInt(2025, 3250));
- }
- } else {
- if(walkPath(Exit_MG));
- }
- } else {
- if(walkPath(StairsToBank));
- }
- } else {
- if(!MINING_AREA.contains(Players.getLocal().getLocation())){
- if(!SceneEntities.getNearest(Ladder_Down_ID).isOnScreen())
- {
- if(walkPath(reversedStairsToBank));
- } else {
- if(SceneEntities.getNearest(Ladder_Down_ID).click(true)){
- Time.sleep(Random.nextInt(2025, 3050));
- }
- }
- }
- }
- Time.sleep(Random.nextInt(1450, 1925));
- }
- }
- private final class MineCoal implements Task, Condition {
- public boolean validate() {
- return Inventory.getCount() != 28 && MINING_AREA.contains(Players.getLocal().getLocation());
- }
- @Override
- public void run() {
- if(Tabs.getCurrent() != Tabs.INVENTORY) Tabs.INVENTORY.open();
- if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled()) Walking.setRun(true);
- SceneObject ore = SceneEntities.getNearest(new Filter<SceneObject>(){
- public boolean accept(final SceneObject loc) {
- for(int id : Coal_IDS) {
- if(loc.getId() == id && MINING_AREA.contains(loc.getLocation())){
- return true;
- }
- }
- return false;
- }
- });
- if(ore != null)
- {
- if(oldRock == null || !ore.getLocation().equals(oldRock.getLocation()) || Players.getLocal().getAnimation() == -1)
- {
- if(ore.isOnScreen())
- {
- if(ore.click(true))
- {
- Camera.turnTo(ore);
- oldRock = ore;
- Time.sleep(Random.nextInt(850, 1250));
- }
- }else{
- Walking.walk(ore.getLocation());
- Camera.turnTo(ore);
- Time.sleep(Random.nextInt(1250, 1850));
- }
- }
- }
- }
- }
- private final class Bank implements Task, Condition {
- public boolean validate() {
- return Inventory.getCount() == 28 && BANK_AREA.contains(Players.getLocal().getLocation());
- }
- @Override
- public void run() {
- if(SceneEntities.getNearest(Bank_ID).isOnScreen())
- {
- if(Widgets.get(762, 1).isOnScreen())
- {
- if(Widgets.get(762, 34).click(true)){
- Time.sleep(350);
- Widgets.get(762, 99).click(true);
- }
- } else {
- SceneEntities.getNearest(Bank_ID).interact("Bank");
- Time.sleep(Random.nextInt(780, 1250));
- }
- } else {
- Walking.walk(SceneEntities.getNearest(Bank_ID).getLocation());
- Time.sleep(Random.nextInt(780, 1250));
- }
- }
- }
- private final class AntiBan implements Task, Condition {
- public boolean validate() {
- return Players.getLocal().getAnimation() != -1;
- }
- @Override
- public void run() {
- int rnd = Random.nextInt(1, 40);
- switch(rnd)
- {
- case 1:
- Camera.setAngle(Random.nextInt(1, 100));
- break;
- case 2:
- Camera.setPitch(Random.nextInt(1, 100));
- break;
- case 3:
- if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled())
- {
- Walking.setRun(true);
- }
- break;
- case 5:
- if (Tabs.getCurrent() != Tabs.FRIENDS) Tabs.FRIENDS.open();
- break;
- case 10:
- if (Tabs.getCurrent() != Tabs.STATS) Tabs.STATS.open();
- break;
- case 15:
- Mouse.move(Random.nextInt(0, 250), Random.nextInt(0, 200));
- break;
- }
- Time.sleep(Random.nextInt(800, 1250));
- }
- }
- private final class ImageLoader implements Task, Condition {
- @Override
- public boolean validate() {
- if(img1 == null){
- return true;
- }
- return false;
- }
- @Override
- public void run() {
- img1 = getImage("http://i39.tinypic.com/25ks8qr.png");
- }
- }
- private final class WidgetCloser implements Task, Condition {
- public boolean validate() {
- return Widgets.get(1218, 1).isOnScreen();
- }
- @Override
- public void run() {
- Widgets.get(1218, 76).click(true);
- Time.sleep(Random.nextInt(875, 1450));
- }
- }
- private boolean walkPath(Tile[] path) {
- if(Walking.getEnergy() > Random.nextInt(15, 40)) Walking.setRun(true);
- int pos = 0;
- Tile dest = path[pos];
- while(dest != null) {
- if(Calculations.distanceTo(dest) <= 8) {
- if(pos + 1 >= path.length) break;
- dest = path[++pos];
- } else {
- if(Players.getLocal().isMoving()) {
- Time.sleep(100);
- } else {
- Walking.walk(dest);
- }
- }
- }
- return Calculations.distanceTo(path[path.length - 1]) <= 8;
- }
- private static Tile[] reversePath(Tile tiles[]) {
- Tile r[] = new Tile[tiles.length];
- int i;
- for (i = 0; i < tiles.length; i++) {
- r[i] = tiles[(tiles.length - 1) - i];
- }
- return r;
- }
- //START: Code generated using Enfilade's Easel
- private Image getImage(String url) {
- try {
- return ImageIO.read(new URL(url));
- } catch(IOException e) {
- return null;
- }
- }
- public void onRepaint(Graphics g1) {
- Graphics2D g = (Graphics2D)g1;
- if(hidePaint)
- {
- g.drawString("Show Paint", 320, 358);
- } else {
- int levelsGained = Skills.getLevels()[14] - startLvl;
- int expGained = Skills.getExperiences()[14] - startExp;
- long elapsedTime = System.currentTimeMillis() - startTime;
- int expPerHour = (int) ((3600000.0 / elapsedTime) * expGained);
- int moneyGained = coalPrice * oresMined;
- int moneyPerHour = (int) ((3600000.0 / elapsedTime) * moneyGained);
- g.drawImage(img1, 5, 343, null);
- g.drawString(Integer.toString(expGained), 110, 385);
- g.drawString(Integer.toString(expPerHour), 92, 411);
- g.drawString(Integer.toString(levelsGained), 125, 435);
- g.drawString(Integer.toString(moneyGained), 333, 385);
- g.drawString(Integer.toString(moneyPerHour), 316, 419);
- g.drawString(formatTime(elapsedTime), 320, 452);
- g.drawString("Hide Paint", 320, 358);
- }
- }
- //END: Code generated using Enfilade's Easel
- private String formatTime(long time) {
- final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
- return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
- + (s < 10 ? "0" + s : s);
- }
- public void messageReceived(MessageEvent msg) {
- String i = msg.getMessage().toLowerCase();
- if (i.contains("you manage to mine some")) {
- oresMined++;
- }
- }
- public void mouseClicked(MouseEvent mouse) {
- int x = mouse.getX();
- int y = mouse.getY();
- if (x >= 320 && x <= 390 && y >= 345 && y <= 358) {
- hidePaint = !hidePaint;
- }
- }
- public void mouseEntered(MouseEvent arg0) {
- }
- public void mouseExited(MouseEvent arg0) {
- }
- public void mousePressed(MouseEvent arg0) {
- }
- public void mouseReleased(MouseEvent arg0) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment