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.Tabs;
- import org.powerbot.game.api.methods.Walking;
- import org.powerbot.game.api.methods.Widgets;
- import org.powerbot.game.api.methods.input.Keyboard;
- 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.2, authors = {"Tobdan"})
- public class MiningGuildMiner extends ActiveScript implements PaintListener, MessageListener, MouseListener{
- final static int Coal_IDS[] = {5770, 5771, 5772};
- final static int Item_IDS[] = {453, 1617, 1619, 1621, 1623};
- 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(3045, 9745, 0), new Tile(3033,9738,0), new Tile(3024,9738,0)};
- final static Tile[] StairsToBank = {new Tile(3030,3345,0), new Tile(3025,3359,0), new Tile(3012,3356,0)};
- final static Tile[] BankToStairs = {new Tile(3025,3359,0), new Tile(3030,3345,0), new Tile(3019,3337,0)};
- SceneObject oldRock;
- static Image img1 = null;
- static boolean hidePaint = false;
- long startTime;
- static int startExp, startLvl, oresMined;
- final static int coalPrice = 250;
- static String status = "";
- @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()[Skills.MINING];
- startLvl = Skills.getLevels()[Skills.MINING];
- }
- private final class Walk implements Task, Condition {
- private boolean toBank = false;
- public boolean validate() {
- 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).validate())
- {
- 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()){
- status = "Going Up Ladder";
- SceneEntities.getNearest(Ladder_Up_ID).click(true);
- } else {
- status = "Walking Towards Ladder Up";
- Walking.newTilePath(Exit_MG).traverse();
- }
- } else {
- status = "Walking Towards Bank";
- Walking.newTilePath(StairsToBank).traverse();
- }
- } else {
- if(!MINING_AREA.contains(Players.getLocal().getLocation())){
- if(!SceneEntities.getNearest(Ladder_Down_ID).isOnScreen())
- {
- status = "Walking Towards Ladder Down";
- Walking.newTilePath(BankToStairs).traverse();
- } else {
- status = "Going Down Ladder";
- SceneEntities.getNearest(Ladder_Down_ID).click(true);
- }
- }
- }
- 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()) && !Players.getLocal().isMoving();
- }
- @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())
- {
- status = "Mining Ore";
- if(ore.click(true))
- {
- Camera.turnTo(ore);
- oldRock = ore;
- Time.sleep(Random.nextInt(250, 850));
- }
- }else{
- status = "Walking Towards Ore";
- Walking.walk(ore.getLocation());
- Camera.turnTo(ore);
- }
- }
- }
- }
- }
- private final class Bank implements Task, Condition {
- public boolean validate() {
- return Inventory.getCount() == 28 && BANK_AREA.contains(Players.getLocal().getLocation());
- }
- @Override
- public void run() {
- status = "Banking";
- if(SceneEntities.getNearest(Bank_ID).isOnScreen())
- {
- if(Widgets.get(762, 1).validate())
- {
- for(int i = 0; i <= Item_IDS.length -1; i++)
- Inventory.getItem(Item_IDS[i]).getWidgetChild().interact("Deposit-All");
- } 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, 100);
- switch(rnd)
- {
- case 1:
- status = "Antiban - Camera Angle";
- Camera.setAngle(Random.nextInt(1, 100));
- break;
- case 2:
- status = "Antiban - Camera Pitch";
- Camera.setPitch(Camera.getPitch() + Random.nextInt(-50, 50));
- break;
- case 3:
- status = "Antiban - Enable Run";
- if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled())
- Walking.setRun(true);
- break;
- case 5:
- status = "Antiban - Check Friends";
- if (Tabs.getCurrent() != Tabs.FRIENDS) Tabs.FRIENDS.open();
- break;
- case 10:
- status = "Antiban - Check Stats";
- if (Tabs.getCurrent() != Tabs.STATS) Tabs.STATS.open();
- break;
- case 15:
- status = "Antiban - Move Mouse";
- 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() {
- status = "Loading Paint";
- img1 = getImage("http://i47.tinypic.com/2cohm5z.png");
- }
- }
- private final class WidgetCloser implements Task, Condition {
- public boolean validate() {
- return Widgets.get(1218, 1).validate();
- }
- @Override
- public void run() {
- status = "Closing Widget";
- Widgets.get(1218, 76).click(true);
- Time.sleep(Random.nextInt(875, 1450));
- }
- }
- //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) + " (" + Integer.toString(expPerHour) + "/Hr)", 110, 385);
- g.drawString(Integer.toString(Skills.getLevels()[Skills.MINING]) + " (" + Integer.toString(levelsGained) + ")", 120, 419);
- g.drawString(status, 75, 452);
- g.drawString(Integer.toString(moneyGained) + " (" + Integer.toString(moneyPerHour) + "/Hr)", 333, 385);
- g.drawString(Integer.toString(oresMined), 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++;
- }
- if(i.contains("Mining Level") || i.contains("Mining Lvl")) {
- Keyboard.sendText("I'm level " + Skills.getLevels()[Skills.MINING] + " :D", true);
- }
- }
- 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