Thondar

ChokoGrinder 1.0

Jul 26th, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. import java.awt.*;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.net.URL;
  6. import java.net.URLConnection;
  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.Tabs;
  14. import org.powerbot.game.api.methods.Widgets;
  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.tab.Inventory;
  19. import org.powerbot.game.api.methods.widget.Camera;
  20. import org.powerbot.game.api.util.Random;
  21. import org.powerbot.game.api.util.Time;
  22. import org.powerbot.game.api.wrappers.widget.WidgetChild;
  23. import org.powerbot.game.bot.event.listener.PaintListener;
  24.  
  25.  
  26. @Manifest(name = "Choko Grinder", description = "Grinds Chokolate Bars to dust for profit", version = 1.0, authors = {"Thondar"})
  27. public class ChokoGrinder extends ActiveScript implements PaintListener {
  28.  
  29. int ChokoBar = 1973;
  30. int ChokoDust = 1975;
  31. int DustCount;
  32. int DustInv;
  33. int Profit;
  34. int ProfitHour;
  35. int DustPrice;
  36. int BarPrice;
  37. int Banker[] = {3418, 553, 496, 497, 9710, 42192, 2718, 3416, 3293, 4456, 4457, 4458, 4459, 6200, 2759};
  38. long startTime;
  39. long runTime, xpTime;
  40. long hr, min, sec, xphr, xpmin, xpsec;
  41. long xpGain;
  42.  
  43. String time;
  44. String status;
  45.  
  46. boolean start = true;
  47.  
  48. private static WidgetChild Powder;
  49.  
  50. private int getPrice(int id) throws IOException {
  51. URL url = new URL("http://open.tip.it/json/ge_single_item?item=" + id);
  52. URLConnection con = url.openConnection();
  53. BufferedReader in = new BufferedReader(new InputStreamReader(
  54. con.getInputStream()));
  55. String line = "";
  56. String inputLine;
  57. while ((inputLine = in.readLine()) != null) {
  58. line += inputLine;
  59. }
  60. in.close();
  61. if (!line.contains("mark_price"))
  62. return -1;
  63. line = line.substring(line.indexOf("mark_price\":\"")
  64. + "mark_price\":\"".length());
  65. line = line.substring(0, line.indexOf("\""));
  66. return Integer.parseInt(line.replaceAll(",", ""));
  67. }
  68.  
  69.  
  70. @Override
  71. protected void setup() {
  72. startTime = System.currentTimeMillis();
  73.  
  74. DustCount = 0;
  75. try {
  76. DustPrice = getPrice(1975);
  77. BarPrice = getPrice(1973);
  78. } catch (IOException e) {
  79. e.printStackTrace();
  80. }
  81.  
  82. BankOpen bankopen = new BankOpen();
  83. Strategy bankopenStrategy = new Strategy(bankopen, bankopen);
  84. provide(bankopenStrategy);
  85.  
  86. Bank bank = new Bank();
  87. Strategy bankStrategy = new Strategy(bank, bank);
  88. provide(bankStrategy);
  89.  
  90. Grind grind = new Grind();
  91. Strategy grindStrategy = new Strategy(grind, grind);
  92. provide(grindStrategy);
  93.  
  94. AntiBan ab = new AntiBan();
  95. Strategy abStrategy = new Strategy(ab, ab);
  96. provide(abStrategy);
  97.  
  98. Tabs.INVENTORY.open(false);
  99.  
  100. }
  101.  
  102.  
  103. private class BankOpen implements Task, Condition {
  104.  
  105. @Override
  106. public void run() {
  107. status = ("Banking");
  108. NPCs.getNearest(Banker).interact("Bank");
  109. Time.sleep(Random.nextInt(700, 1100));
  110. }
  111.  
  112. @Override
  113. public boolean validate() {
  114. return (Inventory.getCount(ChokoBar) == 0) && NPCs.getNearest(Banker).isOnScreen() && !org.powerbot.game.api.methods.widget.Bank.isOpen();
  115. }
  116.  
  117. }
  118.  
  119.  
  120. private class Bank implements Task, Condition {
  121.  
  122. @Override
  123. public void run() {
  124. status = ("Banking");
  125. DustInv = Inventory.getCount(ChokoDust);
  126. DustCount += DustInv;
  127. org.powerbot.game.api.methods.widget.Bank.depositInventory();
  128. Time.sleep(Random.nextInt(300, 500));
  129. org.powerbot.game.api.methods.widget.Bank.withdraw(ChokoBar, 28);
  130. Time.sleep(Random.nextInt(300, 500));
  131. org.powerbot.game.api.methods.widget.Bank.close();
  132. }
  133.  
  134. @Override
  135. public boolean validate() {
  136. return Inventory.getCount(ChokoBar) < 1 && org.powerbot.game.api.methods.widget.Bank.isOpen();
  137. }
  138.  
  139. }
  140.  
  141. private class Grind implements Task, Condition {
  142.  
  143. @Override
  144. public void run() {
  145. status = ("Making Dust");
  146. Powder = Widgets.get(905, 14);
  147. Tabs.INVENTORY.open(false);
  148. if(org.powerbot.game.api.methods.widget.Bank.isOpen()){
  149. org.powerbot.game.api.methods.widget.Bank.close();
  150. }
  151. if(!Powder.isOnScreen()){
  152. Inventory.getItem(ChokoBar).getWidgetChild().interact("Powder");
  153. Time.sleep(Random.nextInt(300, 500));
  154. }
  155. if(Powder.isOnScreen()) {
  156. Powder.click(true);
  157. Time.sleep(Random.nextInt(300, 500));
  158. }
  159. }
  160. @Override
  161. public boolean validate() {
  162. return (Inventory.getCount(ChokoBar) > 0) && (Players.getLocal().getAnimation() == -1);
  163. }
  164.  
  165. }
  166.  
  167.  
  168. private class AntiBan implements Task, Condition {
  169.  
  170. @Override
  171. public void run() {
  172. switch(Random.nextInt(1, 100)){
  173. case 3:
  174. Camera.setAngle(Random.nextInt(1, 150));
  175. case 33:
  176. Camera.setAngle(Random.nextInt(1, 310));
  177. case 75:
  178. Camera.setAngle(Random.nextInt(1, 210));
  179. default:
  180. }
  181. Time.sleep(Random.nextInt(500, 1000));
  182. }
  183.  
  184. @Override
  185. public boolean validate() {
  186. return start;
  187. }
  188.  
  189. }
  190.  
  191.  
  192.  
  193.  
  194. private AlphaComposite makeComposite(float alpha) {
  195. int type = AlphaComposite.SRC_OVER;
  196.  
  197. return(AlphaComposite.getInstance(type, alpha));
  198. }
  199.  
  200.  
  201. private final Font font1 = new Font("Verdana", 0, 16);
  202. private final Font font2 = new Font("Verdana", 0, 12);
  203. private final Font font3 = new Font("Verdana", 0, 13);
  204. private final Font font4 = new Font("Verdana", 0, 9);
  205.  
  206.  
  207. @Override
  208. public void onRepaint(Graphics g) {
  209. Graphics2D g2d = (Graphics2D) g;
  210.  
  211. g2d.setColor(Color.BLUE);
  212. g2d.drawLine((Mouse.getX() -3), Mouse.getY(), (Mouse.getX() +3), Mouse.getY());
  213. g2d.drawLine(Mouse.getX(), (Mouse.getY() - 3), Mouse.getX(), (Mouse.getY() + 3));
  214. g2d.drawLine((Mouse.getX() - 1), (Mouse.getY() - 1), (Mouse.getX() + 1), (Mouse.getY() + 1));
  215. g2d.drawLine((Mouse.getX() + 1), (Mouse.getY() - 1), (Mouse.getX() - 1), (Mouse.getY() + 1));
  216.  
  217.  
  218. int DustHour = (int) ((DustCount) * 3600000D / (System
  219. .currentTimeMillis() - startTime));
  220.  
  221. int DustPrice1 = DustPrice - BarPrice;
  222.  
  223. Profit = DustCount * DustPrice1;
  224. ProfitHour = DustHour * DustPrice1;
  225.  
  226. Rectangle bg = new Rectangle(0, 0, 800, 50);
  227. g2d.setComposite(makeComposite(1f));
  228. g2d.setColor(Color.BLACK);
  229. g2d.fill(bg);
  230.  
  231. g2d.setFont(font1);
  232. g2d.setComposite(makeComposite(1f));
  233. g2d.setColor(Color.BLUE);
  234. g2d.drawString("ChokoGrinder", 15, 20);
  235. g2d.setFont(font3);
  236. g2d.drawString("by Thondar", 27, 35);
  237. g2d.setFont(font4);
  238. g2d.drawString("Version 1.0", 33, 45);
  239.  
  240. g2d.setFont(font2);
  241. g2d.setComposite(makeComposite(.8f));
  242. g2d.setColor(Color.WHITE);
  243. g2d.drawString("Time Run: " + timeRun(), 150, 20);
  244.  
  245. g2d.setComposite(makeComposite(.8f));
  246. g2d.setColor(Color.WHITE);
  247. g2d.drawString("Status: " + status, 150, 40);
  248.  
  249. g2d.setComposite(makeComposite(.8f));
  250. g2d.setColor(Color.WHITE);
  251. g2d.drawString("Dusts Banked: " + DustCount, 350, 20);
  252.  
  253. g2d.setComposite(makeComposite(.8f));
  254. g2d.setColor(Color.WHITE);
  255. g2d.drawString("Dusts Banked/H: " + DustHour, 350, 40);
  256.  
  257. g2d.setComposite(makeComposite(.8f));
  258. g2d.setColor(Color.WHITE);
  259. g2d.drawString("Profit: " + Profit, 550, 20);
  260.  
  261. g2d.setComposite(makeComposite(.8f));
  262. g2d.setColor(Color.WHITE);
  263. g2d.drawString("Profit/H: " + ProfitHour, 550, 40);
  264.  
  265.  
  266. }
  267.  
  268. public String timeRun() {
  269. runTime = System.currentTimeMillis() - startTime;
  270. time = "";
  271. hr = runTime / (1000 * 60 * 60);
  272. min = (runTime % (1000 * 60 * 60)) / (1000 * 60);
  273. sec = ((runTime % (1000 * 60 * 60)) % (1000 * 60)) / 1000;
  274.  
  275. if (hr < 10)
  276. time += "0" + hr + ":";
  277. else
  278. time += hr + ":";
  279.  
  280. if (min < 10)
  281. time += "0" + min + ":";
  282. else
  283. time += min + ":";
  284. if (sec < 10)
  285. time += "0" + sec;
  286. else
  287. time += sec;
  288. return time;
  289. }
  290.  
  291.  
  292.  
  293. }
Advertisement
Add Comment
Please, Sign In to add comment