BrownBirdScripts

BBoakLarder v0.25

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