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.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.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.Locations;
- 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.interactive.Player;
- import org.powerbot.game.api.wrappers.node.Item;
- import org.powerbot.game.api.wrappers.node.Location;
- 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 = 1.0, authors = {"Tobdan"})
- public class MiningGuildMiner extends ActiveScript implements PaintListener, MessageListener {
- final static int Coal_IDS[] = {5770, 5771, 5772};
- final static int Mithril_IDS[] = {5784, 5785, 5786};
- final static int Empty_Ore_IDS[] = {5763, 5764, 5765};
- final static int Bank_ID = 11758;
- final static int Ladder_Up_ID = 6226;
- final static int Ladder_Down_ID = 2113;
- final static Area MiningArea = new Area(new Tile(3017,9755,0), new Tile(3055,9732,0));
- final static Area BankArea = 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);
- long startTime;
- static int startExp, startLvl, oresMined;
- 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 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);
- provide(walkStrategy);
- provide(mineCoalStrategy);
- provide(bankStrategy);
- provide(antiBanStrategy);
- 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() {
- return Inventory.getCount() == 28 && !BankArea.contains(Players.getLocal().getPosition()) || Inventory.getCount() != 28 && !MiningArea.contains(Players.getLocal().getPosition());
- }
- @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(MiningArea.contains(Players.getLocal().getPosition())){
- if(Locations.getNearest(Ladder_Up_ID).isOnScreen()){
- if(Locations.getNearest(Ladder_Up_ID).click(true)){
- Time.sleep(Random.nextInt(5025, 6750));
- }
- } else {
- walkPath(Exit_MG);
- }
- } else {
- walkPath(StairsToBank);
- }
- } else {
- if(!MiningArea.contains(Players.getLocal().getPosition())){
- if(!Locations.getNearest(Ladder_Down_ID).isOnScreen())
- {
- walkPath(reversedStairsToBank);
- } else {
- if(Locations.getNearest(Ladder_Down_ID).click(true)){
- Time.sleep(Random.nextInt(5025, 6750));
- }
- }
- }
- }
- Time.sleep(Random.nextInt(1450, 1925));
- }
- }
- private final class MineCoal implements Task, Condition {
- public boolean validate() {
- return Inventory.getCount() != 28 && Players.getLocal().getAnimation() == -1;
- }
- @Override
- public void run() {
- if(Tabs.getCurrent() != Tabs.INVENTORY) Tabs.INVENTORY.open();
- Location ore = Locations.getNearest(new Filter<Location>(){
- public boolean accept(final Location loc) {
- for(int id : Coal_IDS) {
- if (loc.getId() == id && MiningArea.contains(loc.getPosition()))
- return true;
- }
- return false;
- }
- });
- if(ore != null)
- {
- if(ore.isOnScreen())
- {
- if(ore.click(true))
- {
- Time.sleep(Random.nextInt(1500, 2250));
- }
- }else{
- Walking.walk(ore.getPosition());
- Time.sleep(Random.nextInt(3750, 4250));
- }
- }
- Time.sleep(Random.nextInt(800, 1250));
- }
- }
- private final class Bank implements Task, Condition {
- public boolean validate() {
- return Inventory.getCount() == 28 && BankArea.contains(Players.getLocal().getPosition());
- }
- @Override
- public void run() {
- if(Locations.getNearest(Bank_ID).isOnScreen())
- {
- if(Widgets.get(762, 1).isOnScreen())
- {
- for(Item item : Inventory.getItems())
- {
- if(item.getId() == 453)
- {
- item.getWidgetChild().interact("Deposit-All");
- break;
- }
- }
- } else {
- Locations.getNearest(Bank_ID).interact("Bank");
- }
- } else {
- Walking.walk(Locations.getNearest(Bank_ID).getPosition());
- }
- 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, 50);
- 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.QUESTS) Tabs.QUESTS.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;
- case 25:
- Time.sleep(Random.nextInt(10000, 20000));
- break;
- case 40:
- Player player = Players.getNearest(new Filter<Player>(){
- @Override
- public boolean accept(Player player) {
- player.isOnScreen();
- return false;
- }
- });
- player.interact("Cancel");
- break;
- }
- Time.sleep(Random.nextInt(800, 1250));
- }
- }
- boolean walkPath(Tile tiles[]) {
- for (int i = tiles.length - 1; i >= 0; i--) {
- if (Walking.walk(tiles[i]))
- break;
- }
- return false;
- }
- 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;
- }
- }
- final Image img1 = getImage("http://i39.tinypic.com/25ks8qr.png");
- public void onRepaint(Graphics g1) {
- 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);
- Graphics2D g = (Graphics2D)g1;
- 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, 383);
- g.drawString(Integer.toString(moneyPerHour), 316, 418);
- g.drawString(formatTime(elapsedTime), 320, 452);
- }
- //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++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment