BrownBirdScripts

BBgoldMiner v0.1

Apr 26th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.75 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Point;
  4. import java.awt.Polygon;
  5. import java.awt.Rectangle;
  6.  
  7. import org.powerbot.concurrent.Task;
  8. import org.powerbot.concurrent.strategy.Condition;
  9. import org.powerbot.concurrent.strategy.Strategy;
  10. import org.powerbot.game.api.ActiveScript;
  11. import org.powerbot.game.api.Manifest;
  12. import org.powerbot.game.api.methods.Calculations;
  13. import org.powerbot.game.api.methods.Tabs;
  14. import org.powerbot.game.api.methods.Walking;
  15. import org.powerbot.game.api.methods.Widgets;
  16. import org.powerbot.game.api.methods.input.Mouse;
  17. import org.powerbot.game.api.methods.interactive.Players;
  18. import org.powerbot.game.api.methods.node.Menu;
  19. import org.powerbot.game.api.methods.node.SceneEntities;
  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.Random;
  24. import org.powerbot.game.api.util.Time;
  25. import org.powerbot.game.api.wrappers.Tile;
  26. import org.powerbot.game.api.wrappers.node.SceneObject;
  27. import org.powerbot.game.bot.event.MessageEvent;
  28. import org.powerbot.game.bot.event.listener.MessageListener;
  29. import org.powerbot.game.bot.event.listener.PaintListener;
  30.  
  31. import java.awt.*;
  32. import javax.imageio.ImageIO;
  33. import java.io.IOException;
  34. import java.net.URL;
  35.  
  36.  
  37. /**
  38. * @author BrownBirdScripts
  39. * @version 0.00
  40. * Copyright 2011 - 2012 All Rights Reserved
  41. * ONLY BrownBird may edit this script, no exception.
  42. * Website: www.brownbirdscripts.net78.net
  43. */
  44.  
  45. @Manifest(authors = { "BrownBirdScripts" }, name = "BBgoldMiner", description = "Mines gold ore for money.", version = 0.00, website = "http://www.brownbirdscripts.net78.net", premium = false)
  46. public class BBgoldMiner extends ActiveScript implements PaintListener, MessageListener{
  47.  
  48.  
  49.  
  50. //IDS
  51. final static private int[] goldOreRock = {9720, 9722};
  52. final static private int[] goldOreRockUsed = {9725, 9723};
  53. final static private int bank = 11758;
  54. final static private int goldOre = 444;
  55.  
  56. //PAINT
  57. private int startExp = 0;
  58. private int expGained;
  59. public int mined;
  60. public int gems;
  61. String status = "";
  62. public long startTime = 0;
  63. public long millis = 0;
  64. public long hours = 0;
  65. public long minutes = 0;
  66. public long seconds = 0;
  67. public long last = 0;
  68. public int expHour = 0;
  69.  
  70. //TILES
  71. private Tile[] pathToBank = new Tile[] { new Tile(2977, 3238, 0),
  72. new Tile(2978, 3245, 0), new Tile(2978, 3251, 0),
  73. new Tile(2981, 3258, 0), new Tile(2989, 3267, 0),
  74. new Tile(2996, 3275, 0), new Tile(3001, 3279, 0),
  75. new Tile(3005, 3284, 0), new Tile(3006, 3294, 0),
  76. new Tile(3006, 3306, 0), new Tile(3006, 3314, 0),
  77. new Tile(3006, 3321, 0), new Tile(3006, 3327, 0),
  78. new Tile(3007, 3332, 0), new Tile(3007, 3338, 0),
  79. new Tile(3007, 3345, 0), new Tile(3007, 3352, 0),
  80. new Tile(3007, 3359, 0), new Tile(3011, 3356, 0)};
  81. private Tile[] pathToMine = new Tile[] {new Tile(3011, 3356, 0),
  82. new Tile(3007, 3359, 0), new Tile(3007, 3352, 0),
  83. new Tile(3007, 3345, 0), new Tile(3007, 3338, 0),
  84. new Tile(3007, 3332, 0), new Tile(3006, 3327, 0),
  85. new Tile(3006, 3321, 0), new Tile(3006, 3314, 0),
  86. new Tile(3006, 3306, 0), new Tile(3006, 3294, 0),
  87. new Tile(3005, 3284, 0), new Tile(3001, 3279, 0),
  88. new Tile(2996, 3275, 0), new Tile(2989, 3267, 0),
  89. new Tile(2981, 3258, 0), new Tile(2978, 3251, 0),
  90. new Tile(2978, 3245, 0), new Tile(2977, 3238, 0),
  91. new Tile(2976, 3234, 0),};
  92.  
  93. @Override
  94. protected void setup() {
  95.  
  96. startTime = System.currentTimeMillis();
  97. startExp = Skills.getExperience(Skills.MINING);
  98.  
  99. mineGold mG = new mineGold();
  100. Strategy mGStrategy = new Strategy(mG, mG);
  101. provide(mGStrategy);
  102.  
  103. walkToBank wB = new walkToBank();
  104. Strategy wBStrategy = new Strategy(wB, wB);
  105. provide(wBStrategy);
  106.  
  107. useBank uB = new useBank();
  108. Strategy uBStrategy = new Strategy(uB, uB);
  109. provide(uBStrategy);
  110.  
  111. walkToMine wM = new walkToMine();
  112. Strategy wMStrategy = new Strategy(wM, wM);
  113. provide(wMStrategy);
  114.  
  115. Antiban ab = new Antiban();
  116. Strategy abStrategy = new Strategy(ab, ab);
  117. provide(abStrategy);
  118.  
  119.  
  120. }
  121.  
  122. private class mineGold implements Task, Condition {
  123.  
  124. @Override
  125. public void run() {
  126. if(SceneEntities.getNearest(goldOreRock).isOnScreen()){
  127.  
  128. status = "Mining Gold Ore...";
  129. if(SceneEntities.getNearest(goldOreRock).validate()){
  130. final SceneObject LS = SceneEntities.getNearest(goldOreRock);
  131. if (LS != null) {
  132. if (Calculations.distance(Players.getLocal().getLocation(),
  133. LS.getLocation()) > 4) {
  134. Walking.walk(getNextPathTile(LS.getLocation().derive(
  135. Random.nextInt(-3, 3), Random.nextInt(-3, 3))));
  136. } else {
  137. interact(LS, "Mine");
  138. Time.sleep(Random.nextInt(1000, 3000));
  139.  
  140. }
  141. }
  142.  
  143. }
  144. }
  145. }
  146.  
  147. @Override
  148. public boolean validate() {
  149. return (Tabs.INVENTORY.open() && Inventory.getCount() < 28 && Players.getLocal().getAnimation() == -1);
  150. }
  151.  
  152. }
  153.  
  154. private class walkToBank implements Task, Condition {
  155.  
  156. @Override
  157. public void run() {
  158.  
  159. status = "Walking to bank";
  160. walkPath(pathToBank);
  161. }
  162.  
  163.  
  164. @Override
  165. public boolean validate() {
  166. return (Inventory.getCount() >=28 && Players.getLocal().getAnimation() == -1);
  167. }
  168.  
  169. }
  170.  
  171. private class useBank implements Task, Condition {
  172.  
  173. @Override
  174. public void run() {
  175. if(SceneEntities.getNearest(bank).isOnScreen()) {
  176. status = "Opening bank";
  177. final SceneObject LS = SceneEntities.getNearest(bank);
  178. if (LS != null) {
  179. if (Calculations.distance(Players.getLocal().getLocation(),
  180. LS.getLocation()) > 4) {
  181. Walking.walk(getNextPathTile(LS.getLocation().derive(
  182. Random.nextInt(-3, 3), Random.nextInt(-3, 3))));
  183. } else {
  184. interact(LS, "Bank");
  185. Time.sleep(Random.nextInt(2002, 3000));
  186. if(Widgets.get(762, 1).validate() && Inventory.getCount() >= 28) {
  187. Widgets.get(762, 34).click(true);
  188. Time.sleep(Random.nextInt(1200, 2000));
  189. Widgets.get(762, 45).click(true);
  190. Time.sleep(Random.nextInt(1200, 2000));
  191.  
  192. }
  193. }
  194.  
  195. }
  196. }
  197.  
  198. }
  199.  
  200. @Override
  201. public boolean validate() {
  202. return (Inventory.getCount() >= 28 );
  203.  
  204. }
  205.  
  206. }
  207.  
  208.  
  209. private class walkToMine implements Task, Condition {
  210.  
  211. @Override
  212. public void run() {
  213.  
  214. if(Inventory.getCount(goldOre) == 0 && Players.getLocal().getAnimation() == -1) {
  215. status = "Walking to back to Mine";
  216. walkPath(pathToMine);
  217. }
  218. }
  219.  
  220. @Override
  221. public boolean validate() {
  222. return (Inventory.getCount(goldOre) == 0 && Players.getLocal().getAnimation() == -1);
  223. }
  224.  
  225. }
  226.  
  227. private class Antiban implements Task, Condition {
  228.  
  229. @Override
  230. public void run() {
  231.  
  232.  
  233. switch (Random.nextInt(1, 588)) {
  234.  
  235. case 0:
  236. status = "Antiban";
  237. Camera.setAngle(Random.nextInt(-180, 180));
  238. log.info("Antiban: Rotating Camera");
  239. case 119:
  240. status = "Antiban";
  241. Camera.setAngle(Random.nextInt(1, 150));
  242. log.info("Antiban: Rotating Camera");
  243. case 289:
  244. status = "Antiban";
  245. Mouse.move(Random.nextInt(1, 500), Random.nextInt(1, 500));
  246. log.info("Antiban: Moving Mouse");
  247. case 500:
  248. status = "Antiban";
  249. Mouse.move(Random.nextInt(1, 500), Random.nextInt(1, 500));
  250. log.info("Antiban: Moving Mouse");
  251. case 3:
  252. status = "Antiban";
  253. Camera.setAngle(Random.nextInt(-180, 180));
  254. log.info("Antiban: Rotating Camera");
  255. case 530:
  256. status = "Antiban";
  257. Mouse.move(Random.nextInt(1, 500), Random.nextInt(1, 500));
  258. log.info("Antiban: Moving Mouse");
  259. }
  260. Time.sleep(Random.nextInt(100, 500));
  261. }
  262.  
  263. @Override
  264. public boolean validate() {
  265. return true;
  266. }
  267.  
  268. }
  269.  
  270. public void walkPath(final Tile... path) {
  271. if (Walking.getEnergy() > Random.nextInt(30, 50)) {
  272. Walking.setRun(true);
  273. }
  274. for (int i = path.length - 1; i >= 0; i--) {
  275. if (Calculations.distanceTo(path[i]) >= 15) {
  276. continue;
  277. }
  278. if (Walking.walk(path[i])) {
  279. break;
  280. }
  281. }
  282. }
  283.  
  284. private Tile getNextPathTile(final Tile tile) {
  285. final Tile pos = Players.getLocal().getLocation();
  286. return new Tile((int) (pos.getX() + (tile.getX() - pos.getX())
  287. * Random.nextDouble(.75D, .9D)),
  288. (int) (pos.getY() + (tile.getY() - pos.getY())
  289. * Random.nextDouble(.75D, .9D)), tile.getPlane());
  290. }
  291.  
  292. private boolean interact(final SceneObject l, final String action) {
  293. final java.awt.geom.Area a = new java.awt.geom.Area();
  294. for (final Polygon p : l.getBounds())
  295. a.add(new java.awt.geom.Area(p));
  296. final Rectangle bounds = a.getBounds();
  297. Point p;
  298. do {
  299. p = new Point(Random.nextGaussian(bounds.x,
  300. bounds.x + bounds.width, 20), Random.nextGaussian(bounds.y,
  301. bounds.y + bounds.height, 20));
  302. } while (!a.contains(p));
  303. Mouse.move(p.x, p.y);
  304. final String[] actions = Menu.getActions();
  305. if (actions.length > 0 && actions[0].contains(action)) {
  306. Mouse.click(true);
  307. return true;
  308. } else {
  309. for (final String item : actions) {
  310. if (item.contains(action)) {
  311. Mouse.click(false);
  312. Time.sleep(Random.nextInt(200, 400));
  313. return Menu.select(item);
  314. }
  315. }
  316. }
  317. return false;
  318. }
  319.  
  320. private Image getImage(String url) {
  321. try {
  322. return ImageIO.read(new URL(url));
  323. } catch(IOException e) {
  324. return null;
  325. }
  326. }
  327.  
  328. private final Color color1 = new Color(255, 255, 255);
  329.  
  330. private final Font font1 = new Font("Gnuolane Free", 0, 20);
  331.  
  332. private final Image img1 = getImage("http://i46.tinypic.com/311rng3.png");
  333.  
  334. public void onRepaint(Graphics g1) {
  335. Graphics2D g = (Graphics2D)g1;
  336. millis = System.currentTimeMillis() - startTime;
  337. hours = millis / (1000 * 60 * 60);
  338. millis -= hours * (1000 * 60 * 60);
  339. minutes = millis / (1000 * 60);
  340. millis -= minutes * (1000 * 60);
  341. seconds = millis / 1000;
  342. Point mLoc = Mouse.getLocation();
  343. g.setColor(Color.black);
  344. g.drawLine(mLoc.x, 0, mLoc.x, 502);
  345. g.drawLine(0, mLoc.y, 764, mLoc.y);
  346. expGained = Skills.getExperience(Skills.MINING) - startExp;
  347. expHour = (int) ((expGained) * 3600000D / (System.currentTimeMillis() - startTime));
  348. g.drawImage(img1, 1, 339, null);
  349. g.setFont(font1);
  350. g.setColor(color1);
  351. g.drawString(" "+ hours + ":" + minutes + ":" + seconds, 119, 430);
  352. g.drawString(" "+ expGained, 132, 448);
  353. g.drawString(" "+ expHour, 107, 469);
  354. g.drawString(" "+ mined, 324, 430);
  355. g.drawString(" "+ gems, 327, 450);
  356. g.drawString(" "+status, 282, 469);
  357. }
  358.  
  359. public void messageReceived(MessageEvent e) {
  360. String svrmsg = e.getMessage();
  361. if (svrmsg.contains("You just found") ) {
  362. gems++;
  363. }
  364. if(svrmsg.contains("You ma")) {
  365. mined++;
  366. }
  367. }
  368.  
  369.  
  370. }
Advertisement
Add Comment
Please, Sign In to add comment