Tobdan

MGMiner

Apr 5th, 2012
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.21 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import java.awt.Graphics2D;
  3. import java.awt.Image;
  4. import java.io.IOException;
  5. import java.net.URL;
  6.  
  7. import javax.imageio.ImageIO;
  8.  
  9. import org.powerbot.concurrent.Task;
  10. import org.powerbot.concurrent.strategy.Condition;
  11. import org.powerbot.concurrent.strategy.Strategy;
  12. import org.powerbot.game.api.ActiveScript;
  13. import org.powerbot.game.api.Manifest;
  14. import org.powerbot.game.api.methods.Tabs;
  15. import org.powerbot.game.api.methods.Walking;
  16. import org.powerbot.game.api.methods.Widgets;
  17. import org.powerbot.game.api.methods.input.Mouse;
  18. import org.powerbot.game.api.methods.interactive.Players;
  19. import org.powerbot.game.api.methods.node.Locations;
  20. import org.powerbot.game.api.methods.tab.Inventory;
  21. import org.powerbot.game.api.methods.tab.Skills;
  22. import org.powerbot.game.api.methods.widget.Camera;
  23. import org.powerbot.game.api.util.Filter;
  24. import org.powerbot.game.api.util.Random;
  25. import org.powerbot.game.api.util.Time;
  26. import org.powerbot.game.api.wrappers.Area;
  27. import org.powerbot.game.api.wrappers.Tile;
  28. import org.powerbot.game.api.wrappers.interactive.Player;
  29. import org.powerbot.game.api.wrappers.node.Item;
  30. import org.powerbot.game.api.wrappers.node.Location;
  31. import org.powerbot.game.bot.event.MessageEvent;
  32. import org.powerbot.game.bot.event.listener.MessageListener;
  33. import org.powerbot.game.bot.event.listener.PaintListener;
  34.  
  35. @Manifest(name = "Mining Guild Miner", description = "Mines coal in the mining guild. And banks!", version = 1.0, authors = {"Tobdan"})
  36. public class MiningGuildMiner extends ActiveScript implements PaintListener, MessageListener {
  37.     final static int Coal_IDS[] = {5770, 5771, 5772};
  38.     final static int Mithril_IDS[] = {5784, 5785, 5786};
  39.     final static int Empty_Ore_IDS[] = {5763, 5764, 5765};
  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 MiningArea = new Area(new Tile(3017,9755,0), new Tile(3055,9732,0));
  44.     final static Area BankArea = new Area(new Tile(3009,3355,0), new Tile(3018,3358,0));
  45.     final static Tile[] Exit_MG = {new Tile(3037,9738,0), new Tile(3021,9739,0)};
  46.     final static Tile[] StairsToBank = {new Tile(3019,3337,0), new Tile(3031,3348,0), new Tile(3022,3361,0), new Tile(3012,3356,0)};
  47.     final static Tile[] reversedStairsToBank = reversePath(StairsToBank);
  48.     long startTime;
  49.     static int startExp, startLvl, oresMined;
  50.     static int coalPrice = 247;
  51.     @Override
  52.     protected void setup() {
  53.         final Walk walk = new Walk();
  54.         final MineCoal mineCoal = new MineCoal();
  55.         final Bank bank = new Bank();
  56.         final AntiBan antiBan = new AntiBan();
  57.        
  58.         final Strategy walkStrategy = new Strategy(walk,walk);
  59.         final Strategy mineCoalStrategy = new Strategy(mineCoal, mineCoal);
  60.         final Strategy bankStrategy = new Strategy(bank, bank);
  61.         final Strategy antiBanStrategy = new Strategy(antiBan, antiBan);
  62.        
  63.         provide(walkStrategy);
  64.         provide(mineCoalStrategy);
  65.         provide(bankStrategy);
  66.         provide(antiBanStrategy);
  67.        
  68.         startTime = System.currentTimeMillis();
  69.         startExp = Skills.getExperiences()[14];
  70.         startLvl = Skills.getLevels()[14];
  71.     }
  72.    
  73.     private final class Walk implements Task, Condition {
  74.         private boolean toBank = false;
  75.         public boolean validate() {
  76.             return Inventory.getCount() == 28 && !BankArea.contains(Players.getLocal().getPosition()) || Inventory.getCount() != 28 && !MiningArea.contains(Players.getLocal().getPosition());
  77.         }
  78.        
  79.         @Override
  80.         public void run() {
  81.             if(Widgets.get(762, 1).isOnScreen())
  82.             {
  83.                 Widgets.get(762, 45).click(true);
  84.                 Time.sleep(Random.nextInt(875, 1450));
  85.             }
  86.             if(Inventory.getCount() == 28)
  87.             {
  88.                 toBank = true;
  89.             } else {
  90.                 toBank = false;
  91.             }
  92.             if(toBank){
  93.                 if(MiningArea.contains(Players.getLocal().getPosition())){
  94.                     if(Locations.getNearest(Ladder_Up_ID).isOnScreen()){
  95.                         if(Locations.getNearest(Ladder_Up_ID).click(true)){
  96.                             Time.sleep(Random.nextInt(5025, 6750));
  97.                         }
  98.                     } else {
  99.                         walkPath(Exit_MG);
  100.                     }
  101.                 } else {
  102.                     walkPath(StairsToBank);
  103.                 }
  104.             } else {
  105.                 if(!MiningArea.contains(Players.getLocal().getPosition())){
  106.                     if(!Locations.getNearest(Ladder_Down_ID).isOnScreen())
  107.                     {
  108.                         walkPath(reversedStairsToBank);
  109.                     } else {
  110.                         if(Locations.getNearest(Ladder_Down_ID).click(true)){
  111.                             Time.sleep(Random.nextInt(5025, 6750));
  112.                         }
  113.                     }
  114.                 }
  115.             }
  116.             Time.sleep(Random.nextInt(1450, 1925));
  117.         }      
  118.     }
  119.     private final class MineCoal implements Task, Condition {
  120.         public boolean validate() {
  121.             return Inventory.getCount() != 28 && Players.getLocal().getAnimation() == -1;
  122.         }
  123.  
  124.         @Override
  125.         public void run() {
  126.             if(Tabs.getCurrent() != Tabs.INVENTORY) Tabs.INVENTORY.open();
  127.             Location ore = Locations.getNearest(new Filter<Location>(){
  128.  
  129.                 public boolean accept(final Location loc) {
  130.                    
  131.                     for(int id : Coal_IDS) {
  132.                         if (loc.getId() == id && MiningArea.contains(loc.getPosition()))
  133.                         return true;
  134.                     }
  135.                    
  136.                    
  137.                     return false;
  138.                 }
  139.                
  140.             });
  141.            
  142.             if(ore != null)
  143.             {
  144.                 if(ore.isOnScreen())
  145.                 {
  146.                     if(ore.click(true))
  147.                     {
  148.                         Time.sleep(Random.nextInt(1500, 2250));
  149.                     }
  150.                 }else{
  151.                     Walking.walk(ore.getPosition());
  152.                     Time.sleep(Random.nextInt(3750, 4250));
  153.                 }
  154.             }
  155.             Time.sleep(Random.nextInt(800, 1250));
  156.         }
  157.     }
  158.     private final class Bank implements Task, Condition {
  159.         public boolean validate() {
  160.             return Inventory.getCount() == 28 && BankArea.contains(Players.getLocal().getPosition());
  161.         }
  162.  
  163.         @Override
  164.         public void run() {
  165.             if(Locations.getNearest(Bank_ID).isOnScreen())
  166.             {
  167.                 if(Widgets.get(762, 1).isOnScreen())
  168.                 {
  169.                     for(Item item : Inventory.getItems())
  170.                     {
  171.                         if(item.getId() == 453)
  172.                         {
  173.                             item.getWidgetChild().interact("Deposit-All");
  174.                            
  175.                             break;
  176.                         }
  177.                     }
  178.                 } else {
  179.                     Locations.getNearest(Bank_ID).interact("Bank");
  180.                 }
  181.             } else {
  182.                 Walking.walk(Locations.getNearest(Bank_ID).getPosition());
  183.             }
  184.             Time.sleep(Random.nextInt(780, 1250));
  185.         }
  186.     }
  187.     private final class AntiBan implements Task, Condition {
  188.         public boolean validate() {
  189.             return Players.getLocal().getAnimation() != -1;
  190.         }
  191.  
  192.         @Override
  193.         public void run() {
  194.             int rnd = Random.nextInt(1, 50);
  195.             switch(rnd)
  196.             {
  197.             case 1:
  198.                 Camera.setAngle(Random.nextInt(1, 100));
  199.                 break;
  200.             case 2:
  201.                 Camera.setPitch(Random.nextInt(1, 100));
  202.                 break;
  203.             case 3:
  204.                 if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled())
  205.                 {
  206.                     Walking.setRun(true);
  207.                 }
  208.                 break;
  209.             case 5:
  210.                 if (Tabs.getCurrent() != Tabs.QUESTS) Tabs.QUESTS.open();
  211.                 break;
  212.             case 10:
  213.                 if (Tabs.getCurrent() != Tabs.STATS) Tabs.STATS.open();
  214.                 break;
  215.             case 15:
  216.                 Mouse.move(Random.nextInt(0, 250), Random.nextInt(0, 200));
  217.                 break;
  218.             case 25:
  219.                 Time.sleep(Random.nextInt(10000, 20000));
  220.             break;
  221.             case 40:
  222.                 Player player = Players.getNearest(new Filter<Player>(){
  223.                     @Override
  224.                     public boolean accept(Player player) {
  225.                         player.isOnScreen();
  226.                         return false;
  227.                     }
  228.                 });
  229.                 player.interact("Cancel");
  230.             break;
  231.             }
  232.             Time.sleep(Random.nextInt(800, 1250));
  233.         }
  234.     }
  235.    
  236.     boolean walkPath(Tile tiles[]) {
  237.         for (int i = tiles.length - 1; i >= 0; i--) {
  238.             if (Walking.walk(tiles[i]))
  239.                 break;
  240.             }
  241.         return false;
  242.         }
  243.    
  244.     static Tile[] reversePath(Tile tiles[]) {    
  245.         Tile r[] = new Tile[tiles.length];
  246.         int i;
  247.         for (i = 0; i < tiles.length; i++) {
  248.             r[i] = tiles[(tiles.length - 1) - i];
  249.         }
  250.         return r;
  251.         }
  252.    
  253.     //START: Code generated using Enfilade's Easel
  254.     private Image getImage(String url) {
  255.         try {
  256.             return ImageIO.read(new URL(url));
  257.         } catch(IOException e) {
  258.             return null;
  259.         }
  260.     }
  261.    
  262.     final Image img1 = getImage("http://i39.tinypic.com/25ks8qr.png");
  263.  
  264.     public void onRepaint(Graphics g1) {
  265.         int levelsGained = Skills.getLevels()[14] - startLvl;
  266.         int expGained = Skills.getExperiences()[14] - startExp;
  267.         long elapsedTime = System.currentTimeMillis() - startTime;
  268.         int expPerHour = (int) ((3600000.0 / elapsedTime) * expGained);
  269.         int moneyGained = coalPrice * oresMined;
  270.         int moneyPerHour = (int) ((3600000.0 / elapsedTime) * moneyGained);
  271.        
  272.         Graphics2D g = (Graphics2D)g1;
  273.         g.drawImage(img1, 5, 343, null);
  274.         g.drawString(Integer.toString(expGained), 110, 385);
  275.         g.drawString(Integer.toString(expPerHour), 92, 411);
  276.         g.drawString(Integer.toString(levelsGained), 125, 435);
  277.         g.drawString(Integer.toString(moneyGained), 333, 383);
  278.         g.drawString(Integer.toString(moneyPerHour), 316, 418);
  279.         g.drawString(formatTime(elapsedTime), 320, 452);
  280.     }
  281.     //END: Code generated using Enfilade's Easel
  282.    
  283.     private String formatTime(long time) {
  284.         final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
  285.         return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
  286.                 + (s < 10 ? "0" + s : s);
  287.     }
  288.    
  289.     public void messageReceived(MessageEvent msg) {
  290.         String i = msg.getMessage().toLowerCase();
  291.         if (i.contains("you manage to mine some")) {
  292.                 oresMined++;
  293.         }
  294.     }
  295.  
  296. }
Advertisement
Add Comment
Please, Sign In to add comment