Thondar

Wine Drinker 1.0

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