Tobdan

MGMiner V2

Apr 6th, 2012
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.15 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.Calculations;
  17. import org.powerbot.game.api.methods.Tabs;
  18. import org.powerbot.game.api.methods.Walking;
  19. import org.powerbot.game.api.methods.Widgets;
  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, 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 Pick_IDS[] = {1265, 1267, 1269, 1271, 1275, 15259};
  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(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.     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 = 247;
  54.    
  55.     @Override
  56.     protected void setup() {
  57.         final Walk walk = new Walk();
  58.         final MineCoal mineCoal = new MineCoal();
  59.         final Bank bank = new Bank();
  60.         final AntiBan antiBan = new AntiBan();
  61.         final ImageLoader iL = new ImageLoader();
  62.         final WidgetCloser wCloser = new WidgetCloser();
  63.        
  64.         final Strategy walkStrategy = new Strategy(walk,walk);
  65.         final Strategy mineCoalStrategy = new Strategy(mineCoal, mineCoal);
  66.         final Strategy bankStrategy = new Strategy(bank, bank);
  67.         final Strategy antiBanStrategy = new Strategy(antiBan, antiBan);
  68.         final Strategy iLStrategy = new Strategy(iL,iL);
  69.         final Strategy wCloserStrategy = new Strategy(wCloser,wCloser);
  70.        
  71.         provide(walkStrategy);
  72.         provide(mineCoalStrategy);
  73.         provide(bankStrategy);
  74.         provide(antiBanStrategy);
  75.         provide(iLStrategy);
  76.         provide(wCloserStrategy);
  77.        
  78.         startTime = System.currentTimeMillis();
  79.         startExp = Skills.getExperiences()[14];
  80.         startLvl = Skills.getLevels()[14];
  81.     }
  82.    
  83.     private final class Walk implements Task, Condition {
  84.         private boolean toBank = false;
  85.         public boolean validate() {
  86.             if(Players.getLocal().isMoving()) {
  87.                 return false;
  88.             }
  89.             return Inventory.getCount() == 28 && !BANK_AREA.contains(Players.getLocal().getLocation()) || Inventory.getCount() != 28 && !MINING_AREA.contains(Players.getLocal().getLocation());
  90.         }
  91.        
  92.         @Override
  93.         public void run() {
  94.             if(Widgets.get(762, 1).isOnScreen())
  95.             {
  96.                 Widgets.get(762, 45).click(true);
  97.                 Time.sleep(Random.nextInt(875, 1450));
  98.             }
  99.             if(Inventory.getCount() == 28)
  100.             {
  101.                 toBank = true;
  102.             } else {
  103.                 toBank = false;
  104.             }
  105.             if(toBank){
  106.                 if(MINING_AREA.contains(Players.getLocal().getLocation())){
  107.                     if(SceneEntities.getNearest(Ladder_Up_ID).isOnScreen()){
  108.                         if(SceneEntities.getNearest(Ladder_Up_ID).click(true)){
  109.                             Time.sleep(Random.nextInt(2025, 3250));
  110.                         }
  111.                     } else {
  112.                         if(walkPath(Exit_MG));
  113.                     }
  114.                 } else {
  115.                     if(walkPath(StairsToBank));
  116.                 }
  117.             } else {
  118.                 if(!MINING_AREA.contains(Players.getLocal().getLocation())){
  119.                     if(!SceneEntities.getNearest(Ladder_Down_ID).isOnScreen())
  120.                     {
  121.                         if(walkPath(reversedStairsToBank));
  122.                     } else {
  123.                         if(SceneEntities.getNearest(Ladder_Down_ID).click(true)){
  124.                             Time.sleep(Random.nextInt(2025, 3050));
  125.                         }
  126.                     }
  127.                 }
  128.             }
  129.             Time.sleep(Random.nextInt(1450, 1925));
  130.         }      
  131.     }
  132.     private final class MineCoal implements Task, Condition {
  133.         public boolean validate() {
  134.             return Inventory.getCount() != 28 && MINING_AREA.contains(Players.getLocal().getLocation());
  135.         }
  136.  
  137.         @Override
  138.         public void run() {
  139.             if(Tabs.getCurrent() != Tabs.INVENTORY) Tabs.INVENTORY.open();
  140.             if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled()) Walking.setRun(true);
  141.            
  142.             SceneObject ore = SceneEntities.getNearest(new Filter<SceneObject>(){
  143.                 public boolean accept(final SceneObject loc) {
  144.                     for(int id : Coal_IDS) {
  145.                         if(loc.getId() == id && MINING_AREA.contains(loc.getLocation())){
  146.                             return true;
  147.                         }
  148.                     }
  149.                     return false;
  150.                 }
  151.             });
  152.            
  153.             if(ore != null)
  154.             {
  155.                 if(oldRock == null || !ore.getLocation().equals(oldRock.getLocation()) || Players.getLocal().getAnimation() == -1)
  156.                 {
  157.                     if(ore.isOnScreen())
  158.                     {
  159.                         if(ore.click(true))
  160.                         {
  161.                             Camera.turnTo(ore);
  162.                             oldRock = ore;
  163.                             Time.sleep(Random.nextInt(850, 1250));
  164.                         }
  165.                     }else{
  166.                         Walking.walk(ore.getLocation());
  167.                         Camera.turnTo(ore);
  168.                         Time.sleep(Random.nextInt(1250, 1850));
  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.             if(SceneEntities.getNearest(Bank_ID).isOnScreen())
  182.             {
  183.                 if(Widgets.get(762, 1).isOnScreen())
  184.                 {
  185.                     if(Widgets.get(762, 34).click(true)){
  186.                         Time.sleep(350);
  187.                         Widgets.get(762, 99).click(true);
  188.                     }                  
  189.                 } else {
  190.                     SceneEntities.getNearest(Bank_ID).interact("Bank");
  191.                     Time.sleep(Random.nextInt(780, 1250));
  192.                 }
  193.             } else {
  194.                 Walking.walk(SceneEntities.getNearest(Bank_ID).getLocation());
  195.                 Time.sleep(Random.nextInt(780, 1250));
  196.             }
  197.         }
  198.     }
  199.     private final class AntiBan implements Task, Condition {
  200.         public boolean validate() {
  201.             return Players.getLocal().getAnimation() != -1;
  202.         }
  203.  
  204.         @Override
  205.         public void run() {
  206.             int rnd = Random.nextInt(1, 40);
  207.             switch(rnd)
  208.             {
  209.             case 1:
  210.                 Camera.setAngle(Random.nextInt(1, 100));
  211.                 break;
  212.             case 2:
  213.                 Camera.setPitch(Random.nextInt(1, 100));
  214.                 break;
  215.             case 3:
  216.                 if(Walking.getEnergy() > Random.nextInt(30, 50) && !Walking.isRunEnabled())
  217.                 {
  218.                     Walking.setRun(true);
  219.                 }
  220.                 break;
  221.             case 5:
  222.                 if (Tabs.getCurrent() != Tabs.FRIENDS) Tabs.FRIENDS.open();
  223.                 break;
  224.             case 10:
  225.                 if (Tabs.getCurrent() != Tabs.STATS) Tabs.STATS.open();
  226.                 break;
  227.             case 15:
  228.                 Mouse.move(Random.nextInt(0, 250), Random.nextInt(0, 200));
  229.                 break;
  230.             }
  231.             Time.sleep(Random.nextInt(800, 1250));
  232.         }
  233.     }
  234.     private final class ImageLoader implements Task, Condition {
  235.  
  236.         @Override
  237.         public boolean validate() {
  238.             if(img1 == null){
  239.                 return true;
  240.             }
  241.             return false;
  242.         }
  243.         @Override
  244.         public void run() {
  245.             img1 = getImage("http://i39.tinypic.com/25ks8qr.png");
  246.         }
  247.     }
  248.    
  249.     private final class WidgetCloser implements Task, Condition {
  250.         public boolean validate() {
  251.             return Widgets.get(1218, 1).isOnScreen();
  252.         }
  253.        
  254.         @Override
  255.         public void run() {
  256.             Widgets.get(1218, 76).click(true);
  257.             Time.sleep(Random.nextInt(875, 1450));
  258.         }
  259.     }
  260.    
  261.     private boolean walkPath(Tile[] path) {
  262.         if(Walking.getEnergy() > Random.nextInt(15, 40)) Walking.setRun(true);
  263.         int pos = 0;
  264.         Tile dest = path[pos];
  265.         while(dest != null) {
  266.                 if(Calculations.distanceTo(dest) <= 8) {
  267.                         if(pos + 1 >= path.length) break;
  268.                         dest = path[++pos];
  269.                 } else {
  270.                         if(Players.getLocal().isMoving()) {
  271.                                 Time.sleep(100);
  272.                         } else {
  273.                                 Walking.walk(dest);
  274.                         }
  275.                 }
  276.         }
  277.         return Calculations.distanceTo(path[path.length - 1]) <= 8;
  278.         }
  279.    
  280.     private static Tile[] reversePath(Tile tiles[]) {
  281.         Tile r[] = new Tile[tiles.length];
  282.         int i;
  283.         for (i = 0; i < tiles.length; i++) {
  284.             r[i] = tiles[(tiles.length - 1) - i];
  285.             }
  286.         return r;
  287.     }
  288.    
  289.     //START: Code generated using Enfilade's Easel
  290.     private Image getImage(String url) {
  291.         try {
  292.             return ImageIO.read(new URL(url));
  293.         } catch(IOException e) {
  294.             return null;
  295.         }
  296.     }
  297.    
  298.     public void onRepaint(Graphics g1) {
  299.         Graphics2D g = (Graphics2D)g1;
  300.         if(hidePaint)
  301.         {
  302.             g.drawString("Show Paint", 320, 358);
  303.         } else {
  304.             int levelsGained = Skills.getLevels()[14] - startLvl;
  305.             int expGained = Skills.getExperiences()[14] - startExp;
  306.             long elapsedTime = System.currentTimeMillis() - startTime;
  307.             int expPerHour = (int) ((3600000.0 / elapsedTime) * expGained);
  308.             int moneyGained = coalPrice * oresMined;
  309.             int moneyPerHour = (int) ((3600000.0 / elapsedTime) * moneyGained);
  310.            
  311.             g.drawImage(img1, 5, 343, null);
  312.             g.drawString(Integer.toString(expGained), 110, 385);
  313.             g.drawString(Integer.toString(expPerHour), 92, 411);
  314.             g.drawString(Integer.toString(levelsGained), 125, 435);
  315.             g.drawString(Integer.toString(moneyGained), 333, 385);
  316.             g.drawString(Integer.toString(moneyPerHour), 316, 419);
  317.             g.drawString(formatTime(elapsedTime), 320, 452);
  318.             g.drawString("Hide Paint", 320, 358);
  319.         }
  320.     }
  321.     //END: Code generated using Enfilade's Easel
  322.    
  323.     private String formatTime(long time) {
  324.         final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
  325.         return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
  326.                 + (s < 10 ? "0" + s : s);
  327.     }
  328.    
  329.     public void messageReceived(MessageEvent msg) {
  330.         String i = msg.getMessage().toLowerCase();
  331.         if (i.contains("you manage to mine some")) {
  332.                 oresMined++;
  333.         }
  334.     }
  335.    
  336.     public void mouseClicked(MouseEvent mouse) {
  337.         int x = mouse.getX();
  338.         int y = mouse.getY();
  339.         if (x >= 320 && x <= 390 && y >= 345 && y <= 358) {
  340.             hidePaint = !hidePaint;
  341.         }
  342.     }
  343.     public void mouseEntered(MouseEvent arg0) {
  344.     }
  345.     public void mouseExited(MouseEvent arg0) {
  346.     }
  347.     public void mousePressed(MouseEvent arg0) {
  348.     }
  349.     public void mouseReleased(MouseEvent arg0) {
  350.     }
  351. }
Advertisement
Add Comment
Please, Sign In to add comment