Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.25 KB | None | 0 0
  1. import java.awt.*;
  2. import java.io.IOException;
  3. import java.net.URL;
  4. import javax.imageio.ImageIO;
  5. import javax.swing.*;
  6. import java.awt.Point;
  7. import org.osbot.rs07.api.map.Area;
  8. import org.osbot.rs07.api.map.Position;
  9. import org.osbot.rs07.api.model.NPC;
  10. import org.osbot.rs07.script.Script;
  11. import org.osbot.rs07.script.ScriptManifest;
  12. import org.osbot.rs07.utility.ConditionalSleep;
  13.  
  14. @ScriptManifest(author = "fishingfff", info = "Buys beer in Port Sarim for profit.", name = "fffBeerBuyer", version = 1.2, logo = "http://i.imgur.com/FuUYcCX.png")
  15. public class fffBeerBuyer extends Script {
  16.  
  17. private final Image bg = getImage("http://orig11.deviantart.net/69e7/f/2012/128/5/f/runescape_plain_paint_template__by_realmgraphics-d4z0e43.png");
  18.  
  19. private Image getImage(String url)
  20. {
  21. try
  22. {
  23. return ImageIO.read(new URL(url));
  24. }
  25. catch (IOException e) {}
  26. return null;
  27. }
  28. //PS AREAS
  29. private final Area BArea = new Area( new Position(3044,3236,0), new Position(3046,3235,0));
  30. private final Area BARAREA = new Area( new Position(3045,3255,0), new Position(3048,3258,0));
  31. private final Area dboxArea = new Area(3045, 3235, 3044, 3236);
  32. //VARROCK AREAS
  33. private final Area BARAREAV = new Area(3225, 3401, 3227, 3395);
  34. private final Area BAreaV = new Area(3257, 3419, 3250, 3422); //BARea = BankArea
  35.  
  36. long beercount;
  37. long startTime;
  38. long coincount1;
  39. long coincount2;
  40. String state;
  41. String varrockstate;
  42. private JFrame gui;
  43. private String selectedBeer = "Beer in PSarim";
  44. private boolean started = false;
  45.  
  46. private void createGUI(){
  47.  
  48. // Declare two constants for width and height of the GUI
  49. final int GUI_WIDTH = 350, GUI_HEIGHT = 115;
  50.  
  51. // Get the size of the screen
  52. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  53.  
  54. // Calculating x and y coordinates
  55. final int gX = (int) (screenSize.getWidth() / 2) - (GUI_WIDTH / 2);
  56. final int gY = (int) (screenSize.getHeight() / 2) - (GUI_HEIGHT / 2);
  57.  
  58. // Create a new JFrame with the title "GUI"
  59. gui = new JFrame("GUI");
  60.  
  61. // Set the x coordinate, y coordinate, width and height of the GUI
  62. gui.setBounds(gX, gY, GUI_WIDTH, GUI_HEIGHT);
  63.  
  64. gui.setResizable(false); // Disable resizing
  65.  
  66. // Create a sub container JPanel
  67. JPanel panel = new JPanel();
  68.  
  69. // Add it to the GUI
  70. gui.add(panel);
  71.  
  72. JLabel label = new JLabel("Select beer & place."); // Create a label
  73. label.setForeground(Color.white); // Set text colour to white
  74. panel.add(label); // Add it to the JPanel
  75.  
  76. // Create a select box for tree options
  77. JComboBox<String> beerSelector = new JComboBox<>(new String[]{"Beer in PSarim", "Beer in Varrock", "Wizard's MB in Falador", "Dwarven Stout in Falador", "Asgarnian Ale in Falador"});
  78.  
  79. // Add an action listener, to listen for user's selections, assign to a variable called selectedTree on selection.
  80. beerSelector.addActionListener(e -> selectedBeer = beerSelector.getSelectedItem().toString());
  81.  
  82. // Add the select box to the JPanel
  83. panel.add(beerSelector);
  84.  
  85. JButton startButton = new JButton("Start");
  86. startButton.addActionListener(e -> {
  87. started = true;
  88. gui.setVisible(false);
  89. });
  90. panel.add(startButton);
  91.  
  92. // Make the GUI visible
  93. gui.setVisible(true);
  94. }
  95.  
  96. @Override
  97. public void onStart()
  98. {
  99. createGUI();
  100. startTime = System.currentTimeMillis();
  101. coincount1 = getInventory().getItem("Coins").getAmount();
  102. }
  103.  
  104. private enum State
  105. {
  106. BUY,WALK2DEP,DEPOSIT,WALK2BART,LOGOUT
  107. }
  108. //BEER IN PS STATES
  109. private State getState()
  110. {
  111. if(inventory.getItem("Coins").getAmount() < 2)
  112. {
  113. state = "Logging Out";
  114. return State.LOGOUT;
  115. }
  116.  
  117. if(!getInventory().isFull() && BARAREA.contains(myPlayer()))
  118. {
  119. state = "Buying Beer";
  120. return State.BUY;
  121. }
  122.  
  123. if(getInventory().isFull() && !BArea.contains(myPlayer()))
  124. {
  125. state = "Walking to Depositbox";
  126. return State.WALK2DEP;
  127. }
  128.  
  129. if(getInventory().isFull() && BArea.contains(myPlayer()))
  130. {
  131. state = "Depositing Items";
  132. return State.DEPOSIT;
  133. }
  134.  
  135. if(!getInventory().isFull() && !BARAREA.contains(myPlayer()))
  136. {
  137. state = "Walking to Bartender";
  138. return State.WALK2BART;
  139. }
  140. return State.BUY;
  141. }
  142. //BEER IN VARROCK STATES
  143. private enum VarrockState
  144. {
  145. BUYV,WALK2DEPV,DEPOSITV,WALK2BARTV,LOGOUTV
  146. }
  147.  
  148. private VarrockState getVarrockState()
  149. {
  150. if(inventory.getItem("Coins").getAmount() < 2)
  151. {
  152. varrockstate = "Logging Out";
  153. return VarrockState.LOGOUTV;
  154. }
  155.  
  156. if(!getInventory().isFull() && BARAREAV.contains(myPlayer()))
  157. {
  158. varrockstate = "Buying Beer";
  159. return VarrockState.BUYV;
  160. }
  161.  
  162. if(getInventory().isFull() && !BAreaV.contains(myPlayer()))
  163. {
  164. varrockstate = "Walking to Depositbox";
  165. return VarrockState.WALK2DEPV;
  166. }
  167.  
  168. if(getInventory().isFull() && BAreaV.contains(myPlayer()))
  169. {
  170. varrockstate = "Depositing Items";
  171. return VarrockState.DEPOSITV;
  172. }
  173.  
  174. if(!getInventory().isFull() && !BARAREAV.contains(myPlayer()))
  175. {
  176. varrockstate = "Walking to Bartender";
  177. return VarrockState.WALK2BARTV;
  178. }
  179. return VarrockState.BUYV;
  180. }
  181.  
  182. @Override
  183. public int onLoop() throws InterruptedException {
  184. if (started) {
  185. if (selectedBeer.equals("Beer in PSarim")) {
  186. switch (getState()) {
  187. case LOGOUT:
  188. log("You have ran out of coins!");
  189. stop();
  190.  
  191.  
  192. case BUY:
  193. NPC shop = npcs.closest("Bartender");
  194. if (!getDialogues().inDialogue() && shop != null) {
  195. shop.interact("Talk-to");
  196. new ConditionalSleep(10000) {
  197. @Override
  198. public boolean condition() throws InterruptedException {
  199. return !getDialogues().inDialogue();
  200. }
  201. }.sleep();
  202. } else if (getDialogues().selectOption(1)) {
  203. getDialogues().completeDialogue("Click here to continue");
  204. coincount2 = getInventory().getItem("Coins").getAmount();
  205. beercount = (coincount1 - coincount2) / 2;
  206. }
  207.  
  208. break;
  209.  
  210. case WALK2DEP:
  211. if (getWalking().webWalk(dboxArea)) {
  212. new ConditionalSleep(10000) {
  213. @Override
  214. public boolean condition() throws InterruptedException {
  215. return !myPlayer().isMoving();
  216. }
  217. }.sleep();
  218. }
  219. break;
  220.  
  221. case DEPOSIT:
  222. if (!getDepositBox().isOpen()) {
  223. getDepositBox().open();
  224. sleep(random(250, 500));
  225. getDepositBox().depositAllExcept("Coins");
  226. new ConditionalSleep(10000) {
  227. @Override
  228. public boolean condition() throws InterruptedException {
  229. return getInventory().isEmptyExcept(995);
  230. }
  231. }.sleep();
  232. }
  233. break;
  234.  
  235. case WALK2BART:
  236. if (getWalking().webWalk(BARAREA)) {
  237. new ConditionalSleep(10000) {
  238. @Override
  239. public boolean condition() throws InterruptedException {
  240. return !myPlayer().isMoving();
  241. }
  242. }.sleep();
  243. }
  244. break;
  245. }
  246. } else if (selectedBeer.equals("Beer in Varrock")) {
  247. switch (getVarrockState()) {
  248.  
  249. case LOGOUTV:
  250. log("You have ran out of coins!");
  251. stop();
  252.  
  253.  
  254. case BUYV:
  255. NPC shopV = npcs.closest("Bartender");
  256. if (!getDialogues().inDialogue() && shopV != null) {
  257. shopV.interact("Talk-to");
  258. new ConditionalSleep(10000) {
  259. @Override
  260. public boolean condition() throws InterruptedException {
  261. return getDialogues().isPendingContinuation();
  262. }
  263. }.sleep(); //removed cond sleep cause of bot spamming bartender ?
  264. } else if (getDialogues().isPendingContinuation()) {
  265. getDialogues().clickContinue();
  266. new ConditionalSleep(10000) {
  267. @Override
  268. public boolean condition() throws InterruptedException {
  269. return getDialogues().isPendingContinuation();
  270. }
  271. }.sleep();
  272. if(getDialogues().isPendingContinuation())
  273. getDialogues().completeDialogue("A glass of your finest ale please.");
  274. if (getDialogues().isPendingContinuation())
  275. getDialogues().clickContinue();
  276. getDialogues().completeDialogue("Click here to continue");
  277. coincount2 = getInventory().getItem("Coins").getAmount();
  278. beercount = (coincount1 - coincount2) / 2;
  279. }
  280. break;
  281.  
  282. case WALK2DEPV:
  283. if (getWalking().webWalk(BAreaV)) {
  284. new ConditionalSleep(10000) {
  285. @Override
  286. public boolean condition() throws InterruptedException {
  287. return !myPlayer().isMoving();
  288. }
  289. }.sleep();
  290. }
  291. break;
  292.  
  293. case DEPOSITV:
  294. if (!getBank().isOpen()) {
  295. getBank().open();
  296. new ConditionalSleep(10000) {
  297. @Override
  298. public boolean condition() throws InterruptedException {
  299. return getBank().isOpen();
  300. }
  301. }.sleep();
  302. getBank().depositAllExcept("Coins");
  303. new ConditionalSleep(10000) {
  304. @Override
  305. public boolean condition() throws InterruptedException {
  306. return getInventory().isEmptyExcept(995);
  307. }
  308. }.sleep();
  309. getBank().close();
  310. }
  311. break;
  312.  
  313. case WALK2BARTV:
  314. if (getWalking().webWalk(BARAREAV)) {
  315. new ConditionalSleep(10000) {
  316. @Override
  317. public boolean condition() throws InterruptedException {
  318. return !myPlayer().isMoving();
  319. }
  320. }.sleep();
  321. }
  322. break;
  323. }
  324. }
  325. }//else if (selectedBeer.equals("Wizard's MB in Falador")) { do this }
  326. //else if (selectedBeer.equals("Dwarven Stout in Falador")) { do this } else if (selectedBeer.equals("Asgarnian Ale in Falador")) { do this }
  327.  
  328. return 0;
  329. }
  330.  
  331. @Override
  332. public void onExit() {
  333. if(gui != null) { // If the JFrame has been created
  334.  
  335. gui.setVisible(false); // Hide it
  336. gui.dispose(); // Dispose
  337. }
  338.  
  339. log("Thanks for using this script!");
  340. log("I'd be glad if you posted a proggy on my thread, thanks! :)");
  341. }
  342.  
  343.  
  344. @Override
  345. public void onPaint(Graphics2D g){
  346. if(started){ // If the user has started the script
  347.  
  348. //g.drawImage(bg, 0, 337, null);
  349. long ss = (System.currentTimeMillis() - startTime) / 1000;
  350. long mm = ss / 60;
  351. long hh = mm / 60;
  352. Point mP = this.getMouse().getPosition();
  353. g.setColor(Color.ORANGE);
  354. g.drawLine(mP.x, 0, mP.x, 500);
  355. g.drawLine(0, mP.y, 800, mP.y);
  356. g.drawRect(mP.x - 10, mP.y - 10, 20, 20);
  357. g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5);
  358. g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5);
  359. Font font = new Font("Candara", Font.BOLD, 20);
  360. g.setColor(Color.BLUE);
  361. g.setFont(font);
  362. g.drawString("fishingfff's Beer Buyer", 15, 370);
  363. g.drawString("Time Ran: " + hh + ":" + mm%60 + ":" + ss%60 , 15, 390);
  364. g.drawString(state, 300, 370);
  365. g.drawString("Version 1.2", 300, 390); // Rest of the paint code
  366. }
  367.  
  368. }
  369.  
  370. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement