BrownBirdScripts

BBoakLarder v0.27

Apr 21st, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.69 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.imageio.ImageIO;
  3. import java.io.IOException;
  4. import java.net.URL;
  5.  
  6. import javax.swing.JOptionPane;
  7.  
  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.Calculations;
  15. import org.powerbot.game.api.methods.Walking;
  16. import org.powerbot.game.api.methods.Widgets;
  17. import org.powerbot.game.api.methods.input.Keyboard;
  18. import org.powerbot.game.api.methods.input.Mouse;
  19. import org.powerbot.game.api.methods.interactive.NPCs;
  20. import org.powerbot.game.api.methods.interactive.Players;
  21. import org.powerbot.game.api.methods.node.Menu;
  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.Random;
  27. import org.powerbot.game.api.util.Time;
  28. import org.powerbot.game.api.wrappers.Tile;
  29. import org.powerbot.game.api.wrappers.node.Item;
  30. import org.powerbot.game.api.wrappers.node.SceneObject;
  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.  
  36.  
  37. /**
  38. * @author BrownBirdScripts
  39. * @version 0.27
  40. * Copyright 2011 - 2012
  41. * All Rights Reserved
  42. * ONLY BrownBird may edit this script, no exception.
  43. *
  44. */
  45.  
  46. @Manifest(authors = { "BrownBirdScripts" }, name = "BBOakLarder", description = "Builds & Destorys Oak Larders for EXP.", version = 0.27, website = "", premium = false)
  47. public class BBoakLarder extends ActiveScript implements MessageListener, PaintListener{
  48.  
  49. final static private int oakPlank = 8778;
  50. final static private int notedOakPlank = 8779;
  51. static private int servantId;
  52. final static private int removedLarder = 15403;
  53. final static private int Larder = 13566;
  54.  
  55. private int startExp = 0;
  56. private int expGained;
  57. public int banked;
  58. String status = "";
  59. public long startTime = 0;
  60. public long millis = 0;
  61. public long hours = 0;
  62. public long minutes = 0;
  63. public long seconds = 0;
  64. public long last = 0;
  65. public int expHour = 0;
  66.  
  67.  
  68. @Override
  69. protected void setup() {
  70. ServantID sid = new ServantID();
  71. submit(sid);
  72.  
  73. log.info("Script is now running.");
  74.  
  75. startTime = System.currentTimeMillis();
  76. startExp = Skills.getExperience(Skills.CONSTRUCTION);
  77.  
  78. Build build = new Build();
  79. Strategy buildStrategy = new Strategy(build, build);
  80. provide(buildStrategy);
  81.  
  82. Remove remove = new Remove();
  83. Strategy removeStrategy = new Strategy(remove, remove);
  84. provide(removeStrategy);
  85.  
  86. useServant servant = new useServant();
  87. Strategy servantStrategy = new Strategy(servant, servant);
  88. provide(servantStrategy);
  89.  
  90. Pay pay = new Pay();
  91. Strategy payStrategy = new Strategy(pay, pay);
  92. provide(payStrategy);
  93.  
  94. Antiban ab = new Antiban();
  95. Strategy abStrategy = new Strategy(ab, ab);
  96. provide(abStrategy);
  97.  
  98. }
  99.  
  100.  
  101.  
  102.  
  103. private class ServantID implements Task, Condition {
  104.  
  105. @Override
  106. public void run() {
  107. try {
  108. servantId = Integer.parseInt(JOptionPane.showInputDialog("Enter your servant ID here:"));
  109.  
  110. } catch (Exception e) {
  111. stop();
  112. }
  113. }
  114.  
  115. @Override
  116. public boolean validate() {
  117. return true;
  118. }
  119.  
  120. }
  121.  
  122. private class Build implements Task, Condition {
  123.  
  124. @Override
  125. public void run() {
  126.  
  127. if(Inventory.getCount(oakPlank) >= 8) {
  128. status = "Building Oak Larder";
  129. }
  130. final SceneObject LS = SceneEntities.getNearest(15403);
  131. if (LS != null) {
  132. if (Calculations.distance(Players.getLocal().getLocation(), LS.getLocation()) > 4) {
  133. Walking.walk(getNextPathTile(LS.getLocation().derive(Random
  134. .nextInt(-3, 3), Random.nextInt(-3, 3))));
  135. } else {
  136. interact(LS, "Build");
  137. Time.sleep(Random.nextInt(400, 800));
  138. if (Widgets.get(394, 11).isOnScreen()) {
  139. Widgets.get(394, 11).getChildren()[1].click(true);
  140. Time.sleep(Random.nextInt(400, 800));
  141. Widgets.get(93, 121).click(true);
  142. Time.sleep(Random.nextInt(500, 800));
  143.  
  144. }
  145.  
  146. }
  147.  
  148.  
  149. }
  150.  
  151. }
  152.  
  153.  
  154. @Override
  155. public boolean validate() {
  156. for (SceneObject loc : SceneEntities.getLoaded()) {
  157. if (loc.getId() == removedLarder)
  158. return (Inventory.getCount(oakPlank) >= 8);
  159. }
  160. return false;
  161.  
  162. }
  163. }
  164.  
  165.  
  166. private class Remove implements Task, Condition {
  167.  
  168. @Override
  169. public void run() {
  170. status = "Removing Oak Larder";
  171.  
  172. final SceneObject LS = SceneEntities.getNearest(13566);
  173. if (LS != null) {
  174. if (Calculations.distance(Players.getLocal().getLocation(), LS.getLocation()) > 4) {
  175. Walking.walk(getNextPathTile(LS.getLocation().derive(Random
  176. .nextInt(-3, 3), Random.nextInt(-3, 3))));
  177. } else {
  178. Time.sleep(Random.nextInt(300, 500));
  179. interact(LS, "Remove");
  180. Time.sleep(Random.nextInt(800, 1000));
  181. Keyboard.sendKey('1');
  182. Time.sleep(Random.nextInt(1000, 1200));
  183.  
  184. }
  185. }
  186. }
  187.  
  188.  
  189. @Override
  190. public boolean validate() {
  191. for (SceneObject loc : SceneEntities.getLoaded()) {
  192. if (loc.getId() == Larder);
  193.  
  194.  
  195. }
  196. return true;
  197.  
  198. }
  199. }
  200.  
  201. private class useServant implements Task, Condition {
  202.  
  203. @Override
  204. public void run() {
  205. status = "Talking to Servant";
  206.  
  207. Time.sleep(Random.nextInt(1000, 3000));
  208. for (Item i : Inventory.getItems()) {
  209. if (i.getId() == notedOakPlank) {
  210. i.getWidgetChild().interact("Use");
  211. Time.sleep(Random.nextInt(1000, 1500));
  212. NPCs.getNearest(servantId).interact("Use");
  213. Time.sleep(Random.nextInt(1000, 1500));
  214.  
  215. if(Widgets.get(1188, 31).isOnScreen()) {
  216. status = "Sending servant...";
  217. Keyboard.sendKey('1');
  218. Time.sleep(Random.nextInt(1500, 2000));
  219. }
  220.  
  221. if (Widgets.get(1188, 3).isOnScreen()) {
  222. status = "Entering amount";
  223. Keyboard.sendKey('1');
  224. Time.sleep(Random.nextInt(1200, 1500));
  225. Keyboard.sendText("27", true);
  226. Time.sleep(Random.nextInt(1000, 1200));
  227. Widgets.getContinue().click(true);
  228. Time.sleep(Random.nextInt(800, 1500));
  229. }
  230.  
  231. /*if(Inventory.getCount(notedOakPlank) >= 0) {
  232. status = "Stopping Script, out of Planks";
  233. log.info("Stopping script, out of Planks");
  234. stop();
  235. }*/
  236. }
  237. }
  238.  
  239. }
  240.  
  241. @Override
  242. public boolean validate() {
  243. for (SceneObject loc : SceneEntities.getLoaded()) {
  244. if (loc.getId() == removedLarder)
  245. return (Inventory.getCount(oakPlank) < 8 && !Widgets.get(1184, 19).isOnScreen());// && Integer.parseInt(Widgets.get(748, 8).getText()) <= 25 + (Random.nextInt(-3, 3));
  246. }
  247. return false;
  248. }
  249. }
  250.  
  251.  
  252.  
  253. private class Pay implements Task, Condition {
  254.  
  255. @Override
  256. public void run() {
  257. status = "Paying Servant";
  258. if (Widgets.get(1184, 18).isOnScreen()) {
  259. Widgets.get(1184, 18).click(true);
  260. Time.sleep(Random.nextInt(500, 1000));
  261. Keyboard.sendKey('1');
  262. Time.sleep(Random.nextInt(800, 1500));
  263. }
  264. }
  265.  
  266. @Override
  267. public boolean validate() {
  268. if (Widgets.get(1184, 18).isOnScreen() && Inventory.getCount(oakPlank) < 8) {
  269. return true;
  270. }
  271. return false;
  272. }
  273.  
  274. }
  275.  
  276.  
  277. private class Antiban implements Task, Condition {
  278.  
  279. @Override
  280. public void run() {
  281. switch(Random.nextInt(1, 569)){
  282. case 0:
  283. Camera.setAngle(Random.nextInt(-180, 180));
  284. log.info("Antiban: Rotating Camera");
  285. case 119:
  286. Camera.setAngle(Random.nextInt(1, 150));
  287. log.info("Antiban: Rotating Camera");
  288. case 289:
  289. Camera.setAngle(Random.nextInt(1, 360));
  290. log.info("Antiban: Rotating Camera");
  291. case 500:
  292. Mouse.move(Random.nextInt(1,500), Random.nextInt(1,500));
  293. log.info("Antiban: Moving Mouse");
  294. }
  295. Time.sleep(Random.nextInt(100, 500));
  296. }
  297.  
  298. @Override
  299. public boolean validate() {
  300. return true;
  301. }
  302.  
  303. }
  304.  
  305.  
  306.  
  307. private Image getImage(String url) {
  308. try {
  309. return ImageIO.read(new URL(url));
  310. } catch(IOException e) {
  311. return null;
  312. }
  313. }
  314.  
  315. private final Color color1 = new Color(255, 255, 255);
  316.  
  317. private final Font font1 = new Font("Gnuolane Free", 0, 20);
  318.  
  319. private final Image img1 = getImage("http://i43.tinypic.com/35dc2h0.png");
  320.  
  321. public void onRepaint(Graphics g1) {
  322. Graphics2D g = (Graphics2D)g1;
  323. millis = System.currentTimeMillis() - startTime;
  324. hours = millis / (1000 * 60 * 60);
  325. millis -= hours * (1000 * 60 * 60);
  326. minutes = millis / (1000 * 60);
  327. millis -= minutes * (1000 * 60);
  328. seconds = millis / 1000;
  329. Point mLoc = Mouse.getLocation();
  330. g.setColor(Color.black);
  331. g.drawLine(mLoc.x, 0, mLoc.x, 502);
  332. g.drawLine(0, mLoc.y, 764, mLoc.y);
  333. expGained = Skills.getExperience(Skills.CONSTRUCTION) - startExp;
  334. expHour = (int) ((expGained) * 3600000D / (System.currentTimeMillis() - startTime));
  335. g.drawImage(img1, 1, 337, null);
  336. g.setFont(font1);
  337. g.setColor(color1);
  338. g.drawString(" "+expGained, 116, 424);
  339. g.drawString(" "+expHour, 87, 450);
  340. g.drawString(" "+status, 77, 472);
  341. g.drawString(" "+ hours + ":" + minutes + ":" + seconds, 282, 425);
  342. g.drawString(" "+banked, 377, 450);
  343. }
  344.  
  345. public void messageReceived(MessageEvent e) {
  346. String svrmsg = e.getMessage();
  347. if (svrmsg.contains("The servant")) {
  348. banked++;
  349. }
  350. }
  351.  
  352. private Tile getNextPathTile(final Tile tile) {
  353. final Tile pos = Players.getLocal().getLocation();
  354. return new Tile((int) (pos.getX() + (tile.getX() - pos.getX()) * Random.nextDouble(.75D, .9D)),
  355. (int) (pos.getY() + (tile.getY() - pos.getY()) * Random.nextDouble(.75D, .9D)), tile.getPlane());
  356. }
  357.  
  358. private boolean interact(final SceneObject l, final String action) {
  359. final java.awt.geom.Area a = new java.awt.geom.Area();
  360. for (final Polygon p : l.getBounds())
  361. a.add(new java.awt.geom.Area(p));
  362. final Rectangle bounds = a.getBounds();
  363. Point p;
  364. do {
  365. p = new Point(Random.nextGaussian(bounds.x, bounds.x + bounds.width, 20),
  366. Random.nextGaussian(bounds.y, bounds.y + bounds.height, 20));
  367. } while (!a.contains(p));
  368. Mouse.move(p.x, p.y);
  369. final String[] actions = Menu.getActions();
  370. if (actions.length > 0 && actions[0].contains(action)) {
  371. Mouse.click(true);
  372. return true;
  373. } else {
  374. for (final String item : actions) {
  375. if (item.contains(action)) {
  376. Mouse.click(false);
  377. Time.sleep(Random.nextInt(200, 400));
  378. return Menu.select(item);
  379. }
  380. }
  381. }
  382. return false;
  383. }
  384.  
  385.  
  386. }
Advertisement
Add Comment
Please, Sign In to add comment