Tobdan

MGMiner V2.2

May 1st, 2012
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.06 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import java.awt.Graphics2D;
  3. import java.awt.Image;
  4. import java.awt.event.MouseEvent;
  5. import java.awt.event.MouseListener;
  6. import java.io.IOException;
  7. import java.net.URL;
  8.  
  9. import javax.imageio.ImageIO;
  10.  
  11. import org.powerbot.concurrent.Task;
  12. import org.powerbot.concurrent.strategy.Condition;
  13. import org.powerbot.concurrent.strategy.Strategy;
  14. import org.powerbot.game.api.ActiveScript;
  15. import org.powerbot.game.api.Manifest;
  16. import org.powerbot.game.api.methods.Tabs;
  17. import org.powerbot.game.api.methods.Walking;
  18. import org.powerbot.game.api.methods.Widgets;
  19. import org.powerbot.game.api.methods.input.Keyboard;
  20. import org.powerbot.game.api.methods.input.Mouse;
  21. import org.powerbot.game.api.methods.interactive.Players;
  22. import org.powerbot.game.api.methods.node.SceneEntities;
  23. import org.powerbot.game.api.methods.tab.Inventory;
  24. import org.powerbot.game.api.methods.tab.Skills;
  25. import org.powerbot.game.api.methods.widget.Camera;
  26. import org.powerbot.game.api.util.Filter;
  27. import org.powerbot.game.api.util.Random;
  28. import org.powerbot.game.api.util.Time;
  29. import org.powerbot.game.api.wrappers.Area;
  30. import org.powerbot.game.api.wrappers.Tile;
  31. import org.powerbot.game.api.wrappers.node.SceneObject;
  32. import org.powerbot.game.bot.event.MessageEvent;
  33. import org.powerbot.game.bot.event.listener.MessageListener;
  34. import org.powerbot.game.bot.event.listener.PaintListener;
  35.  
  36. @Manifest(name = "Mining Guild Miner", description = "Mines coal in the mining guild. And banks!", version = 2.2, authors = {"Tobdan"})
  37. public class MiningGuildMiner extends ActiveScript implements PaintListener, MessageListener, MouseListener{
  38.     final static int Coal_IDS[] = {5770, 5771, 5772};
  39.     final static int Item_IDS[] = {453, 1617, 1619, 1621, 1623};
  40.     final static int Bank_ID = 11758;
  41.     final static int Ladder_Up_ID = 6226;
  42.     final static int Ladder_Down_ID = 2113;
  43.     final static Area MINING_AREA = new Area(new Tile(3017,9756,0), new Tile(3055,9732,0));
  44.     final static Area BANK_AREA = new Area(new Tile(3009,3355,0), new Tile(3018,3358,0));
  45.     final static Tile[] Exit_MG = {new Tile(3045, 9745, 0), new Tile(3033,9738,0), new Tile(3024,9738,0)};
  46.     final static Tile[] StairsToBank = {new Tile(3030,3345,0), new Tile(3025,3359,0), new Tile(3012,3356,0)};
  47.     final static Tile[] BankToStairs = {new Tile(3025,3359,0), new Tile(3030,3345,0), new Tile(3019,3337,0)};
  48.     SceneObject oldRock;
  49.     static Image img1 = null;
  50.     static boolean hidePaint = false;
  51.     long startTime;
  52.     static int startExp, startLvl, oresMined;
  53.     final static int coalPrice = 250;
  54.     static String status = "";
  55.    
  56.     @Override
  57.     protected void setup() {
  58.         final Walk walk = new Walk();
  59.         final MineCoal mineCoal = new MineCoal();
  60.         final Bank bank = new Bank();
  61.         final AntiBan antiBan = new AntiBan();
  62.         final ImageLoader iL = new ImageLoader();
  63.         final WidgetCloser wCloser = new WidgetCloser();
  64.        
  65.         final Strategy walkStrategy = new Strategy(walk,walk);
  66.         final Strategy mineCoalStrategy = new Strategy(mineCoal, mineCoal);
  67.         final Strategy bankStrategy = new Strategy(bank, bank);
  68.         final Strategy antiBanStrategy = new Strategy(antiBan, antiBan);
  69.         final Strategy iLStrategy = new Strategy(iL,iL);
  70.         final Strategy wCloserStrategy = new Strategy(wCloser,wCloser);
  71.        
  72.         provide(walkStrategy);
  73.         provide(mineCoalStrategy);
  74.         provide(bankStrategy);
  75.         provide(antiBanStrategy);
  76.         provide(iLStrategy);
  77.         provide(wCloserStrategy);
  78.        
  79.         startTime = System.currentTimeMillis();
  80.         startExp = Skills.getExperiences()[Skills.MINING];
  81.         startLvl = Skills.getLevels()[Skills.MINING];
  82.     }
  83.    
  84.     private final class Walk implements Task, Condition {
  85.         private boolean toBank = false;
  86.         public boolean validate() {
  87.             return Inventory.getCount() == 28 && !BANK_AREA.contains(Players.getLocal().getLocation()) || Inventory.getCount() != 28 && !MINING_AREA.contains(Players.getLocal().getLocation());
  88.         }
  89.        
  90.         @Override
  91.         public void run() {
  92.             if(Widgets.get(762, 1).validate())
  93.             {
  94.                 Widgets.get(762, 45).click(true);
  95.                 Time.sleep(Random.nextInt(875, 1450));
  96.             }
  97.             if(Inventory.getCount() == 28) {
  98.                 toBank = true;
  99.             } else {
  100.                 toBank = false;
  101.             }
  102.            
  103.             if(toBank){
  104.                 if(MINING_AREA.contains(Players.getLocal().getLocation())){
  105.                     if(SceneEntities.getNearest(Ladder_Up_ID).isOnScreen()){
  106.                         status = "Going Up Ladder";
  107.                         SceneEntities.getNearest(Ladder_Up_ID).click(true);
  108.                     } else {
  109.                         status = "Walking Towards Ladder Up";
  110.                         Walking.newTilePath(Exit_MG).traverse();
  111.                     }
  112.                 } else {
  113.                     status = "Walking Towards Bank";
  114.                     Walking.newTilePath(StairsToBank).traverse();
  115.                 }
  116.             } else {
  117.                 if(!MINING_AREA.contains(Players.getLocal().getLocation())){
  118.                     if(!SceneEntities.getNearest(Ladder_Down_ID).isOnScreen())
  119.                     {
  120.                         status = "Walking Towards Ladder Down";
  121.                         Walking.newTilePath(BankToStairs).traverse();
  122.                     } else {
  123.                         status = "Going Down Ladder";
  124.                         SceneEntities.getNearest(Ladder_Down_ID).click(true);
  125.                     }
  126.                 }
  127.             }
  128.             Time.sleep(Random.nextInt(1450, 1925));
  129.         }      
  130.     }
  131.     private final class MineCoal implements Task, Condition {
  132.         public boolean validate() {
  133.             return Inventory.getCount() != 28 && MINING_AREA.contains(Players.getLocal().getLocation()) && !Players.getLocal().isMoving();
  134.         }
  135.  
  136.         @Override
  137.         public void run() {
  138.             if(Tabs.getCurrent() != Tabs.INVENTORY) Tabs.INVENTORY.open();
  139.             if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled()) Walking.setRun(true);
  140.            
  141.             SceneObject ore = SceneEntities.getNearest(new Filter<SceneObject>(){
  142.                 public boolean accept(final SceneObject loc) {
  143.                     for(int id : Coal_IDS) {
  144.                         if(loc.getId() == id && MINING_AREA.contains(loc.getLocation())){
  145.                             return true;
  146.                         }
  147.                     }
  148.                     return false;
  149.                 }
  150.             });
  151.            
  152.             if(ore != null)
  153.             {
  154.                 if(oldRock == null || !ore.getLocation().equals(oldRock.getLocation()) || Players.getLocal().getAnimation() == -1)
  155.                 {
  156.                     if(ore.isOnScreen())
  157.                     {
  158.                         status = "Mining Ore";
  159.                         if(ore.click(true))
  160.                         {
  161.                             Camera.turnTo(ore);
  162.                             oldRock = ore;
  163.                             Time.sleep(Random.nextInt(250, 850));
  164.                         }
  165.                     }else{
  166.                         status = "Walking Towards Ore";
  167.                         Walking.walk(ore.getLocation());
  168.                         Camera.turnTo(ore);
  169.                     }
  170.                 }
  171.             }
  172.         }
  173.     }
  174.     private final class Bank implements Task, Condition {
  175.         public boolean validate() {
  176.             return Inventory.getCount() == 28 && BANK_AREA.contains(Players.getLocal().getLocation());
  177.         }
  178.  
  179.         @Override
  180.         public void run() {
  181.             status = "Banking";
  182.             if(SceneEntities.getNearest(Bank_ID).isOnScreen())
  183.             {
  184.                 if(Widgets.get(762, 1).validate())
  185.                 {
  186.                     for(int i = 0; i <= Item_IDS.length -1; i++)
  187.                         Inventory.getItem(Item_IDS[i]).getWidgetChild().interact("Deposit-All");
  188.                 } else {
  189.                     SceneEntities.getNearest(Bank_ID).interact("Bank");
  190.                     Time.sleep(Random.nextInt(780, 1250));
  191.                 }
  192.             } else {
  193.                 Walking.walk(SceneEntities.getNearest(Bank_ID).getLocation());
  194.                 Time.sleep(Random.nextInt(780, 1250));
  195.             }
  196.         }
  197.     }
  198.     private final class AntiBan implements Task, Condition {
  199.         public boolean validate() {
  200.             return Players.getLocal().getAnimation() != -1;
  201.         }
  202.  
  203.         @Override
  204.         public void run() {
  205.             int rnd = Random.nextInt(1, 100);
  206.             switch(rnd)
  207.             {
  208.             case 1:
  209.                 status = "Antiban - Camera Angle";
  210.                 Camera.setAngle(Random.nextInt(1, 100));
  211.                 break;
  212.             case 2:
  213.                 status = "Antiban - Camera Pitch";
  214.                 Camera.setPitch(Camera.getPitch() + Random.nextInt(-50, 50));
  215.                 break;
  216.             case 3:
  217.                 status = "Antiban - Enable Run";
  218.                 if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled())
  219.                     Walking.setRun(true);
  220.                 break;
  221.             case 5:
  222.                 status = "Antiban - Check Friends";
  223.                 if (Tabs.getCurrent() != Tabs.FRIENDS) Tabs.FRIENDS.open();
  224.                 break;
  225.             case 10:
  226.                 status = "Antiban - Check Stats";
  227.                 if (Tabs.getCurrent() != Tabs.STATS) Tabs.STATS.open();
  228.                 break;
  229.             case 15:
  230.                 status = "Antiban - Move Mouse";
  231.                 Mouse.move(Random.nextInt(0, 250), Random.nextInt(0, 200));
  232.                 break;
  233.             }
  234.             Time.sleep(Random.nextInt(800, 1250));
  235.         }
  236.     }
  237.     private final class ImageLoader implements Task, Condition {
  238.  
  239.         @Override
  240.         public boolean validate() {
  241.             if(img1 == null){
  242.                 return true;
  243.             }
  244.             return false;
  245.         }
  246.         @Override
  247.         public void run() {
  248.             status = "Loading Paint";
  249.             img1 = getImage("http://i47.tinypic.com/2cohm5z.png");
  250.         }
  251.     }
  252.    
  253.     private final class WidgetCloser implements Task, Condition {
  254.         public boolean validate() {
  255.             return Widgets.get(1218, 1).validate();
  256.         }
  257.        
  258.         @Override
  259.         public void run() {
  260.             status = "Closing Widget";
  261.             Widgets.get(1218, 76).click(true);
  262.             Time.sleep(Random.nextInt(875, 1450));
  263.         }
  264.     }
  265.    
  266.     //START: Code generated using Enfilade's Easel
  267.     private Image getImage(String url) {
  268.         try {
  269.             return ImageIO.read(new URL(url));
  270.         } catch(IOException e) {
  271.             return null;
  272.         }
  273.     }
  274.    
  275.     public void onRepaint(Graphics g1) {
  276.         Graphics2D g = (Graphics2D)g1;
  277.         if(hidePaint)
  278.         {
  279.             g.drawString("Show Paint", 320, 358);
  280.         } else {
  281.             int levelsGained = Skills.getLevels()[14] - startLvl;
  282.             int expGained = Skills.getExperiences()[14] - startExp;
  283.             long elapsedTime = System.currentTimeMillis() - startTime;
  284.             int expPerHour = (int) ((3600000.0 / elapsedTime) * expGained);
  285.             int moneyGained = coalPrice * oresMined;
  286.             int moneyPerHour = (int) ((3600000.0 / elapsedTime) * moneyGained);
  287.            
  288.             g.drawImage(img1, 5, 343, null);
  289.             g.drawString(Integer.toString(expGained) + " (" + Integer.toString(expPerHour) + "/Hr)", 110, 385);
  290.             g.drawString(Integer.toString(Skills.getLevels()[Skills.MINING]) + " (" + Integer.toString(levelsGained) + ")", 120, 419);
  291.             g.drawString(status, 75, 452);
  292.             g.drawString(Integer.toString(moneyGained) + " (" + Integer.toString(moneyPerHour) + "/Hr)", 333, 385);
  293.             g.drawString(Integer.toString(oresMined), 316, 419);
  294.             g.drawString(formatTime(elapsedTime), 320, 452);
  295.             g.drawString("Hide Paint", 320, 358);
  296.         }
  297.     }
  298.     //END: Code generated using Enfilade's Easel
  299.    
  300.     private String formatTime(long time) {
  301.         final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
  302.         return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
  303.                 + (s < 10 ? "0" + s : s);
  304.     }
  305.    
  306.     public void messageReceived(MessageEvent msg) {
  307.         String i = msg.getMessage().toLowerCase();
  308.         if (i.contains("you manage to mine some")) {
  309.                 oresMined++;
  310.         }
  311.         if(i.contains("Mining Level") || i.contains("Mining Lvl")) {
  312.             Keyboard.sendText("I'm level " + Skills.getLevels()[Skills.MINING] + " :D", true);
  313.         }
  314.     }
  315.    
  316.     public void mouseClicked(MouseEvent mouse) {
  317.         int x = mouse.getX();
  318.         int y = mouse.getY();
  319.         if (x >= 320 && x <= 390 && y >= 345 && y <= 358) {
  320.             hidePaint = !hidePaint;
  321.         }
  322.     }
  323.     public void mouseEntered(MouseEvent arg0) {
  324.     }
  325.     public void mouseExited(MouseEvent arg0) {
  326.     }
  327.     public void mousePressed(MouseEvent arg0) {
  328.     }
  329.     public void mouseReleased(MouseEvent arg0) {
  330.     }
  331. }
Advertisement
Add Comment
Please, Sign In to add comment