BrownBirdScripts

BBoakLarder

Apr 16th, 2012
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.02 KB | None | 0 0
  1. import java.awt.*;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5.  
  6. import org.powerbot.concurrent.Task;
  7. import org.powerbot.concurrent.strategy.Condition;
  8. import org.powerbot.concurrent.strategy.Strategy;
  9. import org.powerbot.game.api.ActiveScript;
  10. import org.powerbot.game.api.Manifest;
  11. import org.powerbot.game.api.methods.Calculations;
  12. import org.powerbot.game.api.methods.Walking;
  13. import org.powerbot.game.api.methods.Widgets;
  14. import org.powerbot.game.api.methods.input.Keyboard;
  15. import org.powerbot.game.api.methods.input.Mouse;
  16. import org.powerbot.game.api.methods.interactive.NPCs;
  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.util.Random;
  23. import org.powerbot.game.api.util.Time;
  24. import org.powerbot.game.api.wrappers.Tile;
  25. import org.powerbot.game.api.wrappers.node.SceneObject;
  26. import org.powerbot.game.bot.event.MessageEvent;
  27. import org.powerbot.game.bot.event.listener.MessageListener;
  28. import org.powerbot.game.bot.event.listener.PaintListener;
  29.  
  30.  
  31.  
  32. /**
  33. * @author BrownBirdScripts
  34. * @version 0.17
  35. * Copyright 2011 - 2012
  36. * All Rights Reserved
  37. * ONLY BrownBird may edit this script, no exception.
  38. *
  39. */
  40.  
  41. @Manifest(authors = { "BrownBirdScripts" }, name = "BBOakLarder", description = "Builds & Destorys Oak Larders for EXP.", version = 0.01, website = "", premium = false)
  42. public class BBOakLarder extends ActiveScript implements MessageListener, PaintListener{
  43.  
  44. final static private int oakPlank = 8778;
  45. static private int servantId;
  46. final static private int removedLarder = 15403;
  47. final static private int Larder = 13566;
  48.  
  49. private int startExp = 0;
  50. private int expGained;
  51. public int banked;
  52. String status = "";
  53. public long startTime = 0;
  54. public long millis = 0;
  55. public long hours = 0;
  56. public long minutes = 0;
  57. public long seconds = 0;
  58. public long last = 0;
  59.  
  60.  
  61. @Override
  62. protected void setup() {
  63. ServantID sid = new ServantID();
  64. submit(sid);
  65.  
  66. log.info("Script is now running.");
  67.  
  68. startTime = System.currentTimeMillis();
  69. startExp = Skills.getExperience(Skills.CONSTRUCTION);
  70.  
  71. Build build = new Build();
  72. Strategy buildStrategy = new Strategy(build, build);
  73. provide(buildStrategy);
  74.  
  75. Remove remove = new Remove();
  76. Strategy removeStrategy = new Strategy(remove, remove);
  77. provide(removeStrategy);
  78.  
  79. sendServant servant = new sendServant();
  80. Strategy servantStrategy = new Strategy(servant, servant);
  81. provide(servantStrategy);
  82.  
  83.  
  84. }
  85.  
  86.  
  87.  
  88.  
  89. private class ServantID implements Task, Condition {
  90.  
  91. @Override
  92. public void run() {
  93. try {
  94. servantId = Integer.parseInt(JOptionPane.showInputDialog("Enter your servant ID here:"));
  95.  
  96. } catch (Exception e) {
  97. stop();
  98. }
  99. }
  100.  
  101. @Override
  102. public boolean validate() {
  103. return true;
  104. }
  105.  
  106. }
  107.  
  108. private class Build implements Task, Condition {
  109.  
  110. @Override
  111. public void run() {
  112.  
  113. if(Inventory.getCount(oakPlank) >= 8) {
  114. status = "Building Oak Larder";
  115. }
  116. final SceneObject LS = SceneEntities.getNearest(15403);
  117. if (LS != null) {
  118. if (Calculations.distance(Players.getLocal().getLocation(), LS.getLocation()) > 4) {
  119. Walking.walk(getNextPathTile(LS.getLocation().derive(Random
  120. .nextInt(-3, 3), Random.nextInt(-3, 3))));
  121. } else {
  122. interact(LS, "Build");
  123. Time.sleep(Random.nextInt(400, 800));
  124. if (Widgets.get(394, 11).isOnScreen()) {
  125. Widgets.get(394, 11).getChildren()[1].click(true);
  126. Time.sleep(Random.nextInt(400, 800));
  127. Widgets.get(93, 121).click(true);
  128. Time.sleep(Random.nextInt(500, 800));
  129.  
  130. }
  131.  
  132. }
  133.  
  134.  
  135. }
  136.  
  137. }
  138.  
  139.  
  140. @Override
  141. public boolean validate() {
  142. for (SceneObject loc : SceneEntities.getLoaded()) {
  143. if (loc.getId() == removedLarder)
  144. return (Inventory.getCount(oakPlank) >= 8);
  145. }
  146. return false;
  147.  
  148. }
  149. }
  150.  
  151.  
  152. private class Remove implements Task, Condition {
  153.  
  154. @Override
  155. public void run() {
  156. status = "Removing Oak Larder";
  157.  
  158. final SceneObject LS = SceneEntities.getNearest(13566);
  159. if (LS != null) {
  160. if (Calculations.distance(Players.getLocal().getLocation(), LS.getLocation()) > 4) {
  161. Walking.walk(getNextPathTile(LS.getLocation().derive(Random
  162. .nextInt(-3, 3), Random.nextInt(-3, 3))));
  163. } else {
  164. Time.sleep(Random.nextInt(300, 500));
  165. interact(LS, "Remove");
  166. Time.sleep(Random.nextInt(1000, 1200));
  167. Keyboard.sendKey('1');
  168. Time.sleep(Random.nextInt(1000, 1200));
  169.  
  170. }
  171. }
  172. }
  173.  
  174.  
  175. @Override
  176. public boolean validate() {
  177. for (SceneObject loc : SceneEntities.getLoaded()) {
  178. if (loc.getId() == Larder);
  179.  
  180.  
  181. }
  182. return true;
  183.  
  184. }
  185. }
  186.  
  187. private class sendServant implements Task, Condition {
  188.  
  189. @Override
  190. public void run() {
  191. status = "Sending Servant to Bank";
  192.  
  193. NPCs.getNearest(servantId).interact("Fetch");
  194. Time.sleep(Random.nextInt(800, 1000));
  195. if (Widgets.get(1188, 36).isOnScreen()) {
  196. Time.sleep(Random.nextInt(1200, 1600));
  197. Keyboard.sendKey('1');
  198. Time.sleep(Random.nextInt(800, 1000));
  199. } else {
  200. Time.sleep(Random.nextInt(300, 500));
  201. if (Widgets.get(1184, 18).isOnScreen()) {
  202. Widgets.getContinue().click(true);
  203. Time.sleep(Random.nextInt(1200, 1600));
  204. Keyboard.sendKey('2');
  205. Time.sleep(Random.nextInt(1200, 1600));
  206. NPCs.getNearest(servantId).interact("Fetch");
  207. Time.sleep(Random.nextInt(800, 1000));
  208. Keyboard.sendKey('1');
  209. Time.sleep(Random.nextInt(800, 1000));
  210. }
  211.  
  212. }
  213. }
  214.  
  215.  
  216.  
  217. @Override
  218. public boolean validate() {
  219. for (SceneObject loc : SceneEntities.getLoaded()) {
  220. if (loc.getId() == removedLarder)
  221. return (Inventory.getCount(oakPlank) < 8 && !Widgets.get(1184, 19).isOnScreen());
  222. }
  223. return false;
  224. }
  225.  
  226. }
  227.  
  228.  
  229. public void onRepaint(Graphics graphics) {
  230. Graphics2D g = (Graphics2D) graphics;
  231. millis = System.currentTimeMillis() - startTime;
  232. hours = millis / (1000 * 60 * 60);
  233. millis -= hours * (1000 * 60 * 60);
  234. minutes = millis / (1000 * 60);
  235. millis -= minutes * (1000 * 60);
  236. seconds = millis / 1000;
  237. Point mLoc = Mouse.getLocation();
  238. g.setColor(Color.black);
  239. g.drawLine(mLoc.x, 0, mLoc.x, 502);
  240. g.drawLine(0, mLoc.y, 764, mLoc.y);
  241. expGained = Skills.getExperience(Skills.CONSTRUCTION) - startExp;
  242. g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF));
  243. g.setColor(new Color(246, 194, 65, 163));
  244. g.fillRect(15, 21, 193, 105);
  245. g.setStroke(new BasicStroke(1));
  246. g.setColor(new Color(0, 0, 0));
  247. g.drawRect(15, 21, 193, 105);
  248. g.setColor(new Color(8, 7, 5));
  249. g.setFont(new Font("Arial", 0, 15));
  250. g.drawString("BBoakLarder", 67, 39);
  251. g.setColor(new Color(8, 7, 5));
  252. g.setFont(new Font("Arial", 0, 10));
  253. g.drawString("Run Time: "+ hours + ":" + minutes + ":" + seconds, 24, 60);
  254. g.setColor(new Color(8, 7, 5));
  255. g.setFont(new Font("Arial", 0, 10));
  256. g.drawString("Sent Servant to Bank: "+banked, 24, 75);
  257. g.setColor(new Color(9, 7, 3));
  258. g.setFont(new Font("Arial", 0, 10));
  259. g.drawString("EXP Gained: "+expGained, 24, 90);
  260. g.setColor(new Color(9, 7, 3));
  261. g.setFont(new Font("Arial", 0, 10));
  262. g.drawString("Status: "+status, 24, 105);
  263. }
  264.  
  265. public void messageReceived(MessageEvent e) {
  266. String svrmsg = e.getMessage();
  267. if (svrmsg.contains("The servant")) {
  268. banked++;
  269. }
  270. }
  271.  
  272. private Tile getNextPathTile(final Tile tile) {
  273. final Tile pos = Players.getLocal().getLocation();
  274. return new Tile((int) (pos.getX() + (tile.getX() - pos.getX()) * Random.nextDouble(.75D, .9D)),
  275. (int) (pos.getY() + (tile.getY() - pos.getY()) * Random.nextDouble(.75D, .9D)), tile.getPlane());
  276. }
  277.  
  278. private boolean interact(final SceneObject l, final String action) {
  279. final java.awt.geom.Area a = new java.awt.geom.Area();
  280. for (final Polygon p : l.getBounds())
  281. a.add(new java.awt.geom.Area(p));
  282. final Rectangle bounds = a.getBounds();
  283. Point p;
  284. do {
  285. p = new Point(Random.nextGaussian(bounds.x, bounds.x + bounds.width, 20),
  286. Random.nextGaussian(bounds.y, bounds.y + bounds.height, 20));
  287. } while (!a.contains(p));
  288. Mouse.move(p.x, p.y);
  289. final String[] actions = Menu.getActions();
  290. if (actions.length > 0 && actions[0].contains(action)) {
  291. Mouse.click(true);
  292. return true;
  293. } else {
  294. for (final String item : actions) {
  295. if (item.contains(action)) {
  296. Mouse.click(false);
  297. Time.sleep(Random.nextInt(200, 400));
  298. return Menu.select(item);
  299. }
  300. }
  301. }
  302. return false;
  303. }
  304. }
Advertisement
Add Comment
Please, Sign In to add comment