BrownBirdScripts

BBoakLarder v0.29

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