Guest User

Untitled

a guest
Oct 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.95 KB | None | 0 0
  1. import com.rsbuddy.event.listeners.PaintListener;
  2. import com.rsbuddy.script.ActiveScript;
  3. import com.rsbuddy.script.Manifest;
  4. import com.rsbuddy.script.methods.*;
  5. import com.rsbuddy.script.util.Filter;
  6. import com.rsbuddy.script.util.Random;
  7. import com.rsbuddy.script.util.Timer;
  8. import com.rsbuddy.script.wrappers.Component;
  9. import com.rsbuddy.script.wrappers.GameObject;
  10. import com.rsbuddy.script.wrappers.Item;
  11. import com.rsbuddy.script.wrappers.Widget;
  12. import org.rsbuddy.tabs.Inventory;
  13. import org.rsbuddy.widgets.Bank;
  14.  
  15. import javax.swing.*;
  16. import java.awt.*;
  17. import java.awt.event.ActionEvent;
  18. import java.awt.event.ActionListener;
  19. import java.awt.event.MouseEvent;
  20. import java.awt.event.MouseListener;
  21.  
  22. @Manifest(name = "ProFletcher", version = 1.2, authors = { "ccman32", "Speed" }, keywords = {
  23. "Fletching", "Stringing" }, description = "My first script, select options in GUI")
  24. public class ProFletcher extends ActiveScript implements PaintListener,
  25. MouseListener {
  26. private static final int KNIFE_ID = 946, CLAY_KNIFE = 14111;
  27. private static final int BOWSTRING_ID = 1777;
  28. private static final String[] TYPE_OPTION = new String[] { "Fletch",
  29. "String" };
  30. private static final String[] SELECT_OPTION = new String[] { "Shortbow",
  31. "Longbow", "Oak shortbow", "Oak longbow", "Willow shortbow",
  32. "Willow longbow", "Maple shortbow", "Maple longbow",
  33. "Yew shortbow", "Yew longbow", "Magic shortbow", "Magic longbow" };
  34. private static final int[] UNSTRUNG_BOWS = new int[] { 50, 48, 54, 56, 60,
  35. 58, 64, 62, 68, 66, 72, 70 };
  36. private static final int[] LOG_IDS = new int[] { 1511, 1511, 1521, 1521,
  37. 1519, 1519, 1517, 1517, 1515, 1515, 1513, 1513 };
  38. private static final Filter<GameObject> FILTER_VISIBLE = new Filter<GameObject>() {
  39. public boolean accept(GameObject obj) {
  40. return obj.isOnScreen();
  41. }
  42. };
  43. private final WaitTerminate waitForBusy = new WaitTerminate() {
  44.  
  45. public boolean end() {
  46. return isBusy(10);
  47. }
  48. };
  49. private static final int WIDGET_FLETCH = 905;
  50. private int mouseSpeed;
  51. private int oldSpeed;
  52. private Type type;
  53. private int logIndex;
  54. private boolean shortbow;
  55. private int startXP, startLevel;
  56. private int item1, item2;
  57. private long startTime;
  58. private long minutes;
  59. private long hours;
  60. private GUI gui;
  61. private boolean paint = true;
  62. private Rectangle chatBoxPoint;
  63. private WaitTerminate waitForInterface;
  64.  
  65. private enum State {
  66. BANK, FLETCH, ANTIBAN, OPENBANK, CLOSEBANK
  67. }
  68.  
  69. private enum Type {
  70. CUT, STRING
  71. }
  72.  
  73. public boolean onStart() {
  74.  
  75. SwingUtilities.invokeLater(new Runnable() {
  76. public void run() {
  77. gui = new GUI();
  78. }
  79. });
  80.  
  81. return true;
  82. }
  83.  
  84. private int child;
  85.  
  86. public void onRepaint(final Graphics g) {
  87. if (startTime == 0) {
  88. return;
  89. }
  90. long runTime = System.currentTimeMillis() - startTime;
  91. long seconds = runTime / 1000;
  92. if (seconds >= 60) {
  93. minutes = seconds / 60;
  94. seconds -= (minutes * 60);
  95. }
  96. if (minutes >= 60) {
  97. hours = minutes / 60;
  98. minutes -= (hours * 60);
  99. }
  100. final int gainedXp = Skills.getCurrentExp(Skills.FLETCHING) - startXP;
  101. final int gainedLevels = Skills.getRealLevel(Skills.FLETCHING)
  102. - startLevel;
  103. g.setColor(Color.BLUE);
  104.  
  105. if (paint) {
  106. g.fill3DRect(6, 345, 508, 129, true);
  107. g.setColor(Color.BLACK);
  108. g.drawString("ProFletcher by ccman32", 15, 362);
  109. g.drawString("Gained XP: " + gainedXp, 20, 390);
  110. g.drawString("Levels gained: " + gainedLevels, 20, 410);
  111. g.drawString("Runtime: " + hours + ":" + minutes + ":" + seconds,
  112. 20, 430);
  113. if ((runTime / 1000) > 0 && gainedXp > 0) {
  114. int xpPerHour = (int) ((3600000.0 / (double) runTime) * gainedXp);
  115. g.drawString("XP/hour: " + xpPerHour, 310, 390);
  116. }
  117. g.drawString("% to "
  118. + (Skills.getCurrentLevel(Skills.FLETCHING) + 1 > 99 ? 99
  119. : Skills.getCurrentLevel(Skills.FLETCHING) + 1)
  120. + " :" + Skills.getPercentToNextLevel(Skills.FLETCHING),
  121. 310, 410);
  122. g.drawString("Click anywhere to hide the paint", 189, 470);
  123. } else {
  124. g.fill3DRect(6, 345, 10, 10, true);
  125. }
  126. }
  127.  
  128. abstract class WaitTerminate {
  129. public abstract boolean end();
  130.  
  131. public boolean wasTerminated(long timeout) {
  132. final Timer time = new Timer(timeout);
  133. while (time.isRunning()) {
  134. if (end()) {
  135. return true;
  136. }
  137. sleep(50);
  138. }
  139. return false;
  140. }
  141. }
  142.  
  143. public int loop() {
  144. if (item1 == 0) {
  145. return 100;
  146. } else if (oldSpeed != mouseSpeed) {
  147. Mouse.setSpeed(mouseSpeed);
  148. oldSpeed = mouseSpeed;
  149. } else if (startTime == 0
  150. && Skills.getRealLevel(Skills.CONSTITUTION) > 1) {
  151. startTime = System.currentTimeMillis();
  152. startXP = Skills.getCurrentExp(Skills.FLETCHING);
  153. startLevel = Skills.getRealLevel(Skills.FLETCHING);
  154. } else if (Inventory.getSelectedItem() != null) {
  155. final int id = Inventory.getSelectedItem().getId();
  156. if (id != item1 && id != item2) {
  157. Inventory.clickSelectedItem();
  158. }
  159. } else if (Widgets.canContinue())
  160. Widgets.clickContinue();
  161. switch (getState()) {
  162. case BANK:
  163. switch (type) {
  164. case CUT:
  165. if (Inventory.getCount() > 1
  166. && Inventory.getCount() != Inventory.getCount(item1,
  167. item2)) {
  168. Bank.depositAllExcept(item1);
  169. } else {
  170. if (Bank.getCount(item2) < 27) {
  171. log("Finished");
  172. Bank.close();
  173. Game.logout(false);
  174. return -1;
  175. } else {
  176. Bank.withdraw(item2, 27);
  177. }
  178. if (!Inventory.contains(item1)) {
  179. if (Bank.getCount(item1) >= 1) {
  180. Bank.withdraw(item1, 1);
  181. return Random.nextInt(500, 700);
  182. } else {
  183. if (item1 == CLAY_KNIFE) {
  184. item1 = KNIFE_ID;
  185. log("Your clay knife finished, using normal knife");
  186. return Random.nextInt(100, 200);
  187. } else {
  188. log("Couldn't find knife.");
  189. return -1;
  190. }
  191. }
  192. }
  193. }
  194. break;
  195. case STRING:
  196. if (Inventory.getCount() > 0
  197. && Inventory.getCount() != Inventory.getCount(item1,
  198. item2)) {
  199. Bank.depositAll();
  200. } else {
  201. if (Bank.getCount(item1) < 14 || Bank.getCount(item2) < 14) {
  202. log("Finished");
  203. return -1;
  204. } else if (Bank.getCount(item1) > 14
  205. && Bank.getCount(item2) > 14) {
  206. if (!Inventory.contains(item1)) {
  207. Bank.withdraw(item1, 14);
  208. sleep(400, 700);
  209. }
  210. if (!Inventory.contains(item2)) {
  211. Bank.withdraw(item2, 14);
  212. sleep(400, 700);
  213. }
  214.  
  215. }
  216. }
  217. break;
  218. default:
  219. break;
  220. }
  221. return Random.nextInt(500, 800);
  222. case FLETCH:
  223. final Widget inf = Widgets.get(ProFletcher.WIDGET_FLETCH);
  224. final Component child = inf.getComponent(this.child);
  225. if (child != null && child.isValid()) {
  226. if (chatBoxPoint == null) {
  227. chatBoxPoint = child.getContentRect();
  228. }
  229. int tries = 0;
  230. do {
  231. if (child.isValid())
  232. child.click();
  233. else
  234. break;
  235. } while (++tries <= 5 && !waitForBusy.wasTerminated(1000));
  236. return Random.nextInt(350, 500);
  237.  
  238. } else if (child != null && !child.isValid()) {
  239. if (Inventory.getSelectedItem() != null) {
  240. int selected = Inventory.getSelectedItem().getId();
  241. if (selected == item1 || selected == item2) {
  242. if (selected == item1) {
  243. Inventory.getItem(item2).interact("Use");
  244. } else {
  245. Inventory.getItem(item1).interact("Use");
  246. }
  247. if (chatBoxPoint != null) {
  248. int x = Random.nextInt(chatBoxPoint.x,
  249. chatBoxPoint.x + chatBoxPoint.width);
  250. int y = Random.nextInt(chatBoxPoint.y,
  251. chatBoxPoint.y + chatBoxPoint.height);
  252. Mouse.move(mouseSpeed, x, y, 4, 4);
  253. }
  254. waitForInterface.wasTerminated(Random.nextInt(1200,
  255. 1500));
  256. return Random.nextInt(200, 400);
  257. } else {
  258. Inventory.clickSelectedItem();
  259. }
  260. } else {
  261. Inventory.getItem(item1, item2).interact("Use");
  262. }
  263. }
  264.  
  265. return Random.nextInt(300, 600);
  266. case OPENBANK:
  267. if (!Bank.isOpen())
  268. Bank.open();
  269. return Random.nextInt(200, 500);
  270. case CLOSEBANK:
  271. if (Bank.isOpen())
  272. Bank.close();
  273. return Random.nextInt(200, 400);
  274. case ANTIBAN:
  275. if (Random.nextInt(0, 20) == 0) {
  276. GameObject[] obj = Objects.getLoaded(FILTER_VISIBLE);
  277. switch (Random.nextInt(1, 5)) {
  278. case 1:
  279. Camera.moveRandomly(Random.nextInt(2000, 4200));
  280. break;
  281. case 2:
  282. if (Random.nextInt(0, 5) == 0)
  283. Camera.setPitch(true);
  284. break;
  285. case 3:
  286. if (Random.nextInt(0, 5) == 0)
  287. Camera.setPitch(false);
  288. break;
  289. case 4:
  290. if (obj.length > 0) {
  291. Camera.turnTo(obj[Random.nextInt(0, obj.length - 1)]
  292. .getLocation());
  293. }
  294. break;
  295. default:
  296. break;
  297. }
  298. }
  299. if (Random.nextInt(0, 20) == 0) {
  300. GameObject[] objs = Objects.getLoaded(FILTER_VISIBLE);
  301. switch (Random.nextInt(1, 7)) {
  302. case 1:
  303. Mouse.move((int) ((Mouse.getLocation().x * 3.5) / 2.5)
  304. + Random.nextInt(10, 30), ((int) ((Mouse
  305. .getLocation().y * 3.5) / 2.5) + Random.nextInt(10,
  306. 30)));
  307. break;
  308. case 2:
  309. Item[] items = Inventory.getItems();
  310. items[Random.nextInt(0, items.length - 1)].getComponent()
  311. .hover();
  312. break;
  313. case 3:
  314. if (objs.length > 0) {
  315. objs[Random.nextInt(0, objs.length - 1)].hover();
  316. }
  317. break;
  318. case 4:
  319. Mouse.move((int) ((Mouse.getLocation().x * 3.5) / 2.5)
  320. + Random.nextInt(5, 30), ((int) ((Mouse
  321. .getLocation().y * 3.5) / 2.5) + Random.nextInt(5,
  322. 30)));
  323. break;
  324. case 5:
  325. Mouse.moveRandomly(Random.nextInt(900, 2000));
  326. default:
  327. break;
  328. }
  329. }
  330. return Random.nextInt(500, 700);
  331. default:
  332. return Random.nextInt(200, 400);
  333. }
  334. }
  335.  
  336. private boolean isBusy() {
  337. return isBusy(25);
  338. }
  339.  
  340. private boolean isBusy(final int interval) {
  341. for (int i = 0; i < 15; i++) {
  342. if (Players.getLocal().isMoving()
  343. || Players.getLocal().getAnimation() != -1) {
  344. return true;
  345. }
  346. sleep(interval);
  347. }
  348. return false;
  349. }
  350.  
  351. public void onFinish() {
  352. if (Bank.isOpen()) {
  353. Bank.close();
  354. }
  355. if (Game.isLoggedIn()) {
  356. Game.logout(false);
  357. }
  358. log(String.format(
  359. "Thanks for using ProFletcher, you gained %d fletching xp.",
  360. Skills.getCurrentExp(Skills.FLETCHING) - startXP));
  361. }
  362.  
  363. private State getState() {
  364. if (!isBusy()) {
  365. if (!Inventory.containsAll(item1, item2) && !Bank.isOpen()) {
  366. return State.OPENBANK;
  367. } else if (Bank.isOpen() && !Inventory.containsAll(item1, item2)) {
  368. return State.BANK;
  369. } else if (Bank.isOpen() && Inventory.containsAll(item1, item2)) {
  370. return State.CLOSEBANK;
  371. } else if (Inventory.containsAll(item1, item2) && !Bank.isOpen()) {
  372. return State.FLETCH;
  373. }
  374. }
  375. return State.ANTIBAN;
  376. }
  377.  
  378. class GUI extends JFrame {
  379. private JComboBox selector, select1;
  380. private JLabel label, label1, label2;
  381. private JButton startButton, cancelButton;
  382. private JCheckBox clayKnife;
  383. private JSlider speed;
  384.  
  385. public GUI() {
  386. createAndShowGUI();
  387. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  388. }
  389.  
  390. private void createAndShowGUI() {
  391. selector = new JComboBox(TYPE_OPTION);
  392. select1 = new JComboBox(SELECT_OPTION);
  393. label = new JLabel("Fletching type:");
  394. label1 = new JLabel("Make:");
  395. label2 = new JLabel("Mouse speed (lower=faster):");
  396. startButton = new JButton("Start");
  397. cancelButton = new JButton("Cancel");
  398. clayKnife = new JCheckBox("Clay knife?");
  399. speed = new JSlider();
  400. speed.setPaintTicks(true);
  401. speed.setPaintLabels(true);
  402. speed.setMaximum(10);
  403. speed.setMinimum(1);
  404. speed.setMajorTickSpacing(1);
  405. speed.setSnapToTicks(true);
  406.  
  407. startButton.addActionListener(new ActionListener() {
  408. public void actionPerformed(ActionEvent e) {
  409. if (selector.getSelectedItem().equals(TYPE_OPTION[0])) {
  410. logIndex = select1.getSelectedIndex();
  411. type = ProFletcher.Type.CUT;
  412. item1 = clayKnife.isSelected() ? CLAY_KNIFE : KNIFE_ID;
  413. item2 = LOG_IDS[select1.getSelectedIndex()];
  414. } else {
  415. logIndex = select1.getSelectedIndex();
  416. type = ProFletcher.Type.STRING;
  417. item2 = BOWSTRING_ID;
  418. item1 = UNSTRUNG_BOWS[select1.getSelectedIndex()];
  419. }
  420. mouseSpeed = gui.speed.getValue();
  421. shortbow = logIndex == 0 || (logIndex % 2) == 0;
  422. if (type == ProFletcher.Type.CUT)
  423. if (shortbow) {
  424. if (logIndex < 2) {
  425. child = 15;
  426. } else {
  427. child = 14;
  428. }
  429. } else {
  430. if (logIndex < 2) {
  431. child = 16;
  432. } else {
  433. child = 15;
  434. }
  435. }
  436. else
  437. child = 14;
  438. waitForInterface = new WaitTerminate() {
  439.  
  440. public boolean end() {
  441. final Component c = Widgets
  442. .getComponent(905, child);
  443. return c != null && c.isValid();
  444. }
  445.  
  446. };
  447. if (startButton.getText().equals("Start")) {
  448. startButton.setText("Update");
  449.  
  450. }
  451. if (cancelButton.getText().equals("Cancel")) {
  452. cancelButton.setText("Stop");
  453. }
  454. }
  455. });
  456. cancelButton.addActionListener(new ActionListener() {
  457. public void actionPerformed(ActionEvent e) {
  458.  
  459. dispose();
  460. stop();
  461. }
  462.  
  463. });
  464.  
  465. setSize(400, 300);
  466. setLayout(new GridLayout(0, 2));
  467. add(label);
  468. add(selector);
  469. add(label1);
  470. add(select1);
  471. add(clayKnife);
  472. add(new JLabel());// empty space
  473. add(label2);
  474. add(speed);
  475. add(startButton);
  476. add(cancelButton);
  477. setVisible(true);
  478. }
  479. }
  480.  
  481. public void mouseEntered(MouseEvent arg0) {
  482.  
  483. }
  484.  
  485. public void mouseExited(MouseEvent arg0) {
  486.  
  487. }
  488.  
  489. public void mousePressed(MouseEvent arg0) {
  490.  
  491. }
  492.  
  493. public void mouseReleased(MouseEvent arg0) {
  494.  
  495. }
  496.  
  497. public void mouseClicked(MouseEvent e) {
  498. final Point p = e.getPoint();
  499. if (paint && p.x >= 0 && p.x <= 764 && p.y >= 0 && p.y <= 527) {
  500. paint = false;
  501. } else if (!paint && p.x >= 0 && p.x <= 764 && p.y >= 0 && p.x <= 527) {
  502. paint = true;
  503. }
  504. }
  505. }
Add Comment
Please, Sign In to add comment