Thondar

Cowhide Tanner 1.0

Jul 28th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.24 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.io.BufferedReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.net.URL;
  8. import java.net.URLConnection;
  9.  
  10. import javax.swing.DefaultComboBoxModel;
  11. import javax.swing.JButton;
  12. import javax.swing.JComboBox;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.SwingConstants;
  16.  
  17. import org.powerbot.concurrent.Task;
  18. import org.powerbot.concurrent.strategy.Condition;
  19. import org.powerbot.concurrent.strategy.Strategy;
  20. import org.powerbot.game.api.ActiveScript;
  21. import org.powerbot.game.api.Manifest;
  22. import org.powerbot.game.api.methods.Walking;
  23. import org.powerbot.game.api.methods.Widgets;
  24. import org.powerbot.game.api.methods.input.Mouse;
  25. import org.powerbot.game.api.methods.interactive.NPCs;
  26. import org.powerbot.game.api.methods.interactive.Players;
  27. import org.powerbot.game.api.methods.tab.Inventory;
  28. import org.powerbot.game.api.methods.widget.Camera;
  29. import org.powerbot.game.api.util.Random;
  30. import org.powerbot.game.api.util.Time;
  31. import org.powerbot.game.api.wrappers.Area;
  32. import org.powerbot.game.api.wrappers.Tile;
  33. import org.powerbot.game.api.wrappers.widget.WidgetChild;
  34. import org.powerbot.game.bot.event.listener.PaintListener;
  35.  
  36. @Manifest(name = "Cowhide Tanner", description = "Tans Cowhides in Al Kharid", version = 1.0, authors = {"Thondar"})
  37. public class CowhideTanner extends ActiveScript implements PaintListener {
  38.  
  39. private static WidgetChild Tan;
  40. private static WidgetChild SoftTan;
  41. private static WidgetChild HardTan;
  42.  
  43.  
  44. int CowHide = 1739;
  45. int SoftLeather = 1741;
  46. int HardLeather = 1743;
  47. int Leather;
  48. int LeatherCount;
  49. int LeatherInv;
  50. int HideProfit;
  51. int LeatherProfit;
  52. int Profit;
  53. int ProfitHour;
  54. int HidePrice;
  55. int HourPrice;
  56. int SoftLeatherPrice;
  57. int HardLeatherPrice;
  58. int LeatherPrice;
  59. int Banker[] = {496, 497};
  60. int Tanner = 2824;
  61. int TanChoice = 1;
  62. long startTime;
  63. long runTime, xpTime;
  64. long hr, min, sec, xphr, xpmin, xpsec;
  65. long xpGain;
  66.  
  67. String time;
  68. String status;
  69.  
  70. Tile TannerTile = new Tile(3274, 3191, 0);
  71. Tile Bankile = new Tile(3270, 3167, 0);
  72.  
  73. Tile[] TilesToTanner = new Tile[] {
  74. new Tile(3274, 3169, 0), new Tile(3276, 3176, 0),
  75. new Tile(3280, 3182, 0), new Tile(3281, 3188, 0),
  76. new Tile(3275, 3191, 0)
  77. };
  78.  
  79. Tile[] TilesToBank = new Tile[] {
  80. new Tile(3281, 3188, 0), new Tile(3280, 3182, 0),
  81. new Tile(3276, 3176, 0), new Tile(3274, 3169, 0),
  82. new Tile(3270, 3166, 0)
  83. };
  84.  
  85. Area TannerArea = new Area(new Tile(3270, 3189, 0), new Tile(3278, 3194, 0));
  86.  
  87. Area BankArea = new Area(new Tile(3268, 3161, 0), new Tile(3272, 3173, 0));
  88.  
  89. GUI g;
  90. private boolean guiWait = true;
  91.  
  92. boolean start = true;
  93.  
  94. private int getPrice(int id) throws IOException {
  95. URL url = new URL("http://open.tip.it/json/ge_single_item?item=" + id);
  96. URLConnection con = url.openConnection();
  97. BufferedReader in = new BufferedReader(new InputStreamReader(
  98. con.getInputStream()));
  99. String line = "";
  100. String inputLine;
  101. while ((inputLine = in.readLine()) != null) {
  102. line += inputLine;
  103. }
  104. in.close();
  105. if (!line.contains("mark_price"))
  106. return -1;
  107. line = line.substring(line.indexOf("mark_price\":\"")
  108. + "mark_price\":\"".length());
  109. line = line.substring(0, line.indexOf("\""));
  110. return Integer.parseInt(line.replaceAll(",", ""));
  111. }
  112.  
  113.  
  114. @Override
  115. protected void setup() {
  116. startTime = System.currentTimeMillis();
  117.  
  118. g = new GUI();
  119. g.setVisible(true);
  120.  
  121. final WaitGui guiTask = new WaitGui();
  122. provide(new Strategy(guiTask, guiTask));
  123. provide(new Strategy(new WaitGui(), new WaitGui()));
  124.  
  125. LeatherCount = 0;
  126. try {
  127. HidePrice = getPrice(CowHide);
  128. SoftLeatherPrice = getPrice(SoftLeather);
  129. HardLeatherPrice = getPrice(HardLeather);
  130. } catch (IOException e) {
  131. e.printStackTrace();
  132. }
  133.  
  134. BankOpen bankopen = new BankOpen();
  135. Strategy bankopenStrategy = new Strategy(bankopen, bankopen);
  136. provide(bankopenStrategy);
  137.  
  138. Bank bank = new Bank();
  139. Strategy bankStrategy = new Strategy(bank, bank);
  140. provide(bankStrategy);
  141.  
  142. Tan tan = new Tan();
  143. Strategy tanStrategy = new Strategy(tan, tan);
  144. provide(tanStrategy);
  145.  
  146. BankWalk bankwalk = new BankWalk();
  147. Strategy bankwalkStrategy = new Strategy(bankwalk, bankwalk);
  148. provide(bankwalkStrategy);
  149.  
  150. TannerWalk tannerwalk = new TannerWalk();
  151. Strategy tannerwalkStrategy = new Strategy(tannerwalk, tannerwalk);
  152. provide(tannerwalkStrategy);
  153.  
  154. Rest rest = new Rest();
  155. Strategy restStrategy = new Strategy(rest, rest);
  156. provide(restStrategy);
  157.  
  158. AntiBan ab = new AntiBan();
  159. Strategy abStrategy = new Strategy(ab, ab);
  160. provide(abStrategy);
  161. }
  162.  
  163. private class WaitGui implements Task, Condition {
  164.  
  165. @Override
  166. public void run() {
  167. while (guiWait) {
  168. Time.sleep(500);
  169. }
  170. }
  171.  
  172. public boolean validate() {
  173. return guiWait;
  174. }
  175.  
  176. }
  177.  
  178.  
  179. private class BankOpen implements Task, Condition {
  180.  
  181. @Override
  182. public void run() {
  183. status = ("Banking");
  184. NPCs.getNearest(Banker).interact("Bank");
  185. Time.sleep(Random.nextInt(600, 1100));
  186. }
  187.  
  188. @Override
  189. public boolean validate() {
  190. return Inventory.getCount(CowHide) < 1 && BankArea.contains(Players.getLocal()) && !org.powerbot.game.api.methods.widget.Bank.isOpen();
  191. }
  192.  
  193. }
  194.  
  195.  
  196. private class Bank implements Task, Condition {
  197.  
  198. @Override
  199. public void run() {
  200. status = ("Banking");
  201. LeatherInv = Inventory.getCount(Leather);
  202. LeatherCount += LeatherInv;
  203. org.powerbot.game.api.methods.widget.Bank.depositInventory();
  204. Time.sleep(Random.nextInt(300, 500));
  205. org.powerbot.game.api.methods.widget.Bank.withdraw(CowHide, 28);
  206. Time.sleep(Random.nextInt(300, 500));
  207. org.powerbot.game.api.methods.widget.Bank.close();
  208. }
  209.  
  210. @Override
  211. public boolean validate() {
  212. return Inventory.getCount(CowHide) < 1 && BankArea.contains(Players.getLocal()) && org.powerbot.game.api.methods.widget.Bank.isOpen();
  213. }
  214.  
  215. }
  216.  
  217. private class Tan implements Task, Condition {
  218.  
  219. @Override
  220. public void run() {
  221. status = ("Tanning");
  222. Tan = Widgets.get(905, 0);
  223. SoftTan = Widgets.get(905, 14);
  224. HardTan = Widgets.get(905, 15);
  225. if(!Tan.isOnScreen()){
  226. NPCs.getNearest(Tanner).interact("Tan hides");
  227. Time.sleep(Random.nextInt(300, 500));
  228. }
  229. if(Tan.isOnScreen() && TanChoice == 1){
  230. SoftTan.click(true);
  231. Time.sleep(Random.nextInt(300, 500));
  232. }
  233. if(Tan.isOnScreen() && TanChoice == 2){
  234. HardTan.click(true);
  235. Time.sleep(Random.nextInt(300, 500));
  236. }
  237.  
  238. }
  239. @Override
  240. public boolean validate() {
  241. return TannerArea.contains(Players.getLocal()) && Inventory.getCount(CowHide) > 1;
  242. }
  243.  
  244. }
  245.  
  246.  
  247. private class BankWalk implements Task, Condition {
  248.  
  249. @Override
  250. public void run() {
  251. status = ("Running to Bank");
  252. Walking.newTilePath(TilesToBank).traverse();
  253. Time.sleep(Random.nextInt(200, 300));
  254. }
  255. @Override
  256. public boolean validate() {
  257. return Inventory.getCount(CowHide) < 10 && !BankArea.contains(Players.getLocal());
  258. }
  259.  
  260. }
  261.  
  262. private class TannerWalk implements Task, Condition {
  263.  
  264. @Override
  265. public void run() {
  266. status = ("Running to Tanner");
  267. Walking.newTilePath(TilesToTanner).traverse();
  268. Time.sleep(Random.nextInt(200, 300));
  269. }
  270. @Override
  271. public boolean validate() {
  272. return Inventory.getCount(Leather) < 10 && Inventory.getCount(CowHide) > 1 && !TannerArea.contains(Players.getLocal());
  273. }
  274.  
  275. }
  276.  
  277. private class Rest implements Task, Condition {
  278.  
  279. @Override
  280. public void run() {
  281. status = ("Resting");
  282. Walking.setRun(true);
  283. Widgets.get(750, 0).interact("Rest");
  284. Time.sleep(Random.nextInt(16000, 22000));
  285.  
  286. }
  287. @Override
  288. public boolean validate() {
  289. return Walking.getEnergy() < 20;
  290. }
  291.  
  292. }
  293.  
  294.  
  295. private class AntiBan implements Task, Condition {
  296.  
  297. @Override
  298. public void run() {
  299. switch(Random.nextInt(1, 100)){
  300. case 3:
  301. Camera.setAngle(Random.nextInt(1, 150));
  302. case 33:
  303. Camera.setAngle(Random.nextInt(1, 310));
  304. case 75:
  305. Camera.setAngle(Random.nextInt(1, 210));
  306. default:
  307. }
  308. Time.sleep(Random.nextInt(500, 1000));
  309. }
  310.  
  311. @Override
  312. public boolean validate() {
  313. return start;
  314. }
  315.  
  316. }
  317.  
  318.  
  319.  
  320.  
  321. private AlphaComposite makeComposite(float alpha) {
  322. int type = AlphaComposite.SRC_OVER;
  323.  
  324. return(AlphaComposite.getInstance(type, alpha));
  325. }
  326.  
  327.  
  328. private final Font font1 = new Font("Verdana", 0, 16);
  329. private final Font font2 = new Font("Verdana", 0, 12);
  330. private final Font font3 = new Font("Verdana", 0, 13);
  331. private final Font font4 = new Font("Verdana", 0, 9);
  332.  
  333.  
  334. @Override
  335. public void onRepaint(Graphics g) {
  336. Graphics2D g2d = (Graphics2D) g;
  337.  
  338. g2d.setColor(Color.ORANGE);
  339. g2d.drawLine((Mouse.getX() -3), Mouse.getY(), (Mouse.getX() +3), Mouse.getY());
  340. g2d.drawLine(Mouse.getX(), (Mouse.getY() - 3), Mouse.getX(), (Mouse.getY() + 3));
  341. g2d.drawLine((Mouse.getX() - 1), (Mouse.getY() - 1), (Mouse.getX() + 1), (Mouse.getY() + 1));
  342. g2d.drawLine((Mouse.getX() + 1), (Mouse.getY() - 1), (Mouse.getX() - 1), (Mouse.getY() + 1));
  343.  
  344.  
  345. int LeatherHour = (int) ((LeatherCount) * 3600000D / (System
  346. .currentTimeMillis() - startTime));
  347.  
  348. HideProfit = LeatherCount * HidePrice;
  349. LeatherProfit = LeatherCount * LeatherPrice;
  350. Profit = LeatherProfit - HideProfit;
  351. HourPrice = LeatherPrice - HidePrice;
  352. ProfitHour = LeatherHour * HourPrice;
  353.  
  354. Rectangle bg = new Rectangle(0, 0, 800, 50);
  355. g2d.setComposite(makeComposite(1f));
  356. g2d.setColor(Color.BLACK);
  357. g2d.fill(bg);
  358.  
  359. g2d.setFont(font1);
  360. g2d.setComposite(makeComposite(1f));
  361. g2d.setColor(Color.ORANGE);
  362. g2d.drawString("Cowhide Tanner", 10, 20);
  363. g2d.setFont(font3);
  364. g2d.drawString("by Thondar", 30, 35);
  365. g2d.setFont(font4);
  366. g2d.drawString("Version 1.0", 36, 45);
  367.  
  368. g2d.setFont(font2);
  369. g2d.setComposite(makeComposite(.8f));
  370. g2d.setColor(Color.LIGHT_GRAY);
  371. g2d.drawString("Time Run: " + timeRun(), 550, 20);
  372.  
  373. g2d.setComposite(makeComposite(.8f));
  374. g2d.setColor(Color.LIGHT_GRAY);
  375. g2d.drawString("Status: " + status, 550, 40);
  376.  
  377. g2d.setComposite(makeComposite(.8f));
  378. g2d.setColor(Color.LIGHT_GRAY);
  379. g2d.drawString("Leathers Banked: " + LeatherCount, 350, 20);
  380.  
  381. g2d.setComposite(makeComposite(.8f));
  382. g2d.setColor(Color.LIGHT_GRAY);
  383. g2d.drawString("Leathers Banked/H: " + LeatherHour, 350, 40);
  384.  
  385. g2d.setComposite(makeComposite(.8f));
  386. g2d.setColor(Color.LIGHT_GRAY);
  387. g2d.drawString("Profit: " + Profit, 170, 20);
  388.  
  389. g2d.setComposite(makeComposite(.8f));
  390. g2d.setColor(Color.LIGHT_GRAY);
  391. g2d.drawString("Profit/H: " + ProfitHour, 170, 40);
  392.  
  393.  
  394. }
  395.  
  396. public String timeRun() {
  397. runTime = System.currentTimeMillis() - startTime;
  398. time = "";
  399. hr = runTime / (1000 * 60 * 60);
  400. min = (runTime % (1000 * 60 * 60)) / (1000 * 60);
  401. sec = ((runTime % (1000 * 60 * 60)) % (1000 * 60)) / 1000;
  402.  
  403. if (hr < 10)
  404. time += "0" + hr + ":";
  405. else
  406. time += hr + ":";
  407.  
  408. if (min < 10)
  409. time += "0" + min + ":";
  410. else
  411. time += min + ":";
  412. if (sec < 10)
  413. time += "0" + sec;
  414. else
  415. time += sec;
  416. return time;
  417. }
  418.  
  419.  
  420. class GUI extends JFrame {
  421. public GUI() {
  422. initComponents();
  423. }
  424.  
  425. private void button1ActionPerformed(ActionEvent e) {
  426. String u = comboBox1.getSelectedItem().toString(); {
  427. if (u.equals("Leather")) {
  428. Leather = SoftLeather;
  429. LeatherPrice = SoftLeatherPrice;
  430. TanChoice = 1;
  431. }else if (u.equals("Hard Leather")) {
  432. Leather = HardLeather;
  433. LeatherPrice = HardLeatherPrice -3;
  434. TanChoice = 2;
  435. }
  436.  
  437. }
  438. guiWait = false;
  439. g.dispose();
  440. }
  441.  
  442. private void initComponents() {
  443. // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
  444. // Generated using JFormDesigner Evaluation license - Jonas Bill Jensen
  445. label1 = new JLabel();
  446. button1 = new JButton();
  447. label2 = new JLabel();
  448. comboBox1 = new JComboBox();
  449.  
  450. //======== this ========
  451. Container contentPane = getContentPane();
  452. contentPane.setLayout(null);
  453.  
  454. //---- label1 ----
  455. label1.setText("Cowhide Tanner");
  456. label1.setHorizontalAlignment(SwingConstants.CENTER);
  457. label1.setFont(new Font("Segoe Print", Font.BOLD, 28));
  458. contentPane.add(label1);
  459. label1.setBounds(0, 0, 295, 65);
  460.  
  461. //---- button1 ----
  462. button1.setText("Start");
  463. button1.setFont(new Font("Verdana", Font.PLAIN, 12));
  464. button1.addActionListener(new ActionListener() {
  465. @Override
  466. public void actionPerformed(ActionEvent e) {
  467. button1ActionPerformed(e);
  468. }
  469. });
  470. contentPane.add(button1);
  471. button1.setBounds(0, 205, 295, 50);
  472.  
  473. //---- label2 ----
  474. label2.setText("What to Tan?");
  475. label2.setHorizontalAlignment(SwingConstants.CENTER);
  476. label2.setFont(new Font("Verdana", Font.PLAIN, 12));
  477. contentPane.add(label2);
  478. label2.setBounds(0, 95, 295, label2.getPreferredSize().height);
  479.  
  480. //---- comboBox1 ----
  481. comboBox1.setModel(new DefaultComboBoxModel(new String[] {
  482. "Leather",
  483. "Hard Leather"
  484. }));
  485. contentPane.add(comboBox1);
  486. comboBox1.setBounds(85, 115, 125, 30);
  487.  
  488. { // compute preferred size
  489. Dimension preferredSize = new Dimension();
  490. for(int i = 0; i < contentPane.getComponentCount(); i++) {
  491. Rectangle bounds = contentPane.getComponent(i).getBounds();
  492. preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
  493. preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
  494. }
  495. Insets insets = contentPane.getInsets();
  496. preferredSize.width += insets.right;
  497. preferredSize.height += insets.bottom;
  498. contentPane.setMinimumSize(preferredSize);
  499. contentPane.setPreferredSize(preferredSize);
  500. }
  501. pack();
  502. setLocationRelativeTo(getOwner());
  503. // JFormDesigner - End of component initialization //GEN-END:initComponents
  504. }
  505.  
  506. // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
  507. // Generated using JFormDesigner Evaluation license - Jonas Bill Jensen
  508. private JLabel label1;
  509. private JButton button1;
  510. private JLabel label2;
  511. private JComboBox comboBox1;
  512. // JFormDesigner - End of variables declaration //GEN-END:variables
  513. }
  514.  
  515.  
  516.  
  517. }
Advertisement
Add Comment
Please, Sign In to add comment