Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.79 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hanfisher;
  7.  
  8. import java.awt.Color;
  9. import java.awt.Dimension;
  10. import java.awt.Graphics2D;
  11. import java.awt.Image;
  12. import java.awt.Point;
  13. import java.awt.Rectangle;
  14. import java.awt.Toolkit;
  15. import java.awt.event.ActionEvent;
  16. import java.awt.event.ActionListener;
  17. import java.awt.event.KeyEvent;
  18. import java.awt.event.MouseEvent;
  19. import java.awt.event.MouseListener;
  20. import java.awt.image.BufferedImage;
  21. import java.io.IOException;
  22. import java.net.MalformedURLException;
  23. import java.net.URL;
  24. import javax.imageio.ImageIO;
  25. import javax.swing.JButton;
  26. import javax.swing.JComboBox;
  27. import javax.swing.JFrame;
  28. import javax.swing.JLabel;
  29. import javax.swing.JPanel;
  30. import org.osbot.rs07.api.map.Area;
  31. import org.osbot.rs07.api.model.NPC;
  32. import org.osbot.rs07.api.ui.Message;
  33. import org.osbot.rs07.api.ui.Skill;
  34. import org.osbot.rs07.api.ui.Tab;
  35. import org.osbot.rs07.script.Script;
  36. import org.osbot.rs07.script.ScriptManifest;
  37. import org.osbot.rs07.utility.ConditionalSleep;
  38. import org.osbot.rs07.input.mouse.InventorySlotDestination;
  39. import static org.osbot.rs07.script.MethodProvider.random;
  40. import static org.osbot.rs07.script.MethodProvider.sleep;
  41.  
  42. /**
  43. *
  44. * @author runescapebot
  45. */
  46. @ScriptManifest(author = "Container", name = "Han's Powerfisher", info = "Powerfishes at Barbarian Village og Barbarian Assault. Made for Han", version = 1.0, logo = "http://i.imgur.com/NMhWsQf.png")
  47. public final class HanFisher extends Script implements MouseListener{
  48.  
  49. private String status = "Stopped";
  50. private Image paint;
  51. private Image closePaint;
  52. private boolean hide = false;
  53. Area fishingArea;
  54. public static final int[] ZIGZAG_DROP = new int[]{0,1,4,5,8,9,12,13,16,17,20,21,24,25,2,3,6,7,10,11,14,15,18,19,22,23,26,27};
  55. private String fishType;
  56. private String fishingStyle;
  57. //GUI
  58. private JFrame gui;
  59. private FishType currentFishingType;
  60. private JComboBox<FishType> fishingType = new JComboBox<>(new FishType[]{FishType.NORMAL_LURE});;
  61. private long startTime;
  62. private long runTime = 0;
  63. private Thread thread;
  64. private boolean started = false;
  65. private boolean isRunning = true;
  66.  
  67. private enum FishType{
  68. BARBARIAN_LURE, NORMAL_LURE;
  69. }
  70.  
  71. private enum State{
  72. LOG, FISH, DROP, WALK;
  73. }
  74.  
  75. @Override
  76. public int onLoop() throws InterruptedException {
  77.  
  78. if(!started){
  79. new ConditionalSleep(60*30*1000, 500){
  80. @Override
  81. public boolean condition() throws InterruptedException{
  82. return started;
  83. }
  84. }.sleep();
  85. } else{
  86. switch(getState()){
  87. case LOG:
  88. this.stop();
  89. log("No feathers in inventory.");
  90. break;
  91. case FISH:
  92. fish();
  93. break;
  94. case DROP:
  95. drop();
  96. break;
  97. case WALK:
  98. walk();
  99. break;
  100. default:
  101. break;
  102. }
  103. }
  104. return random(400, 700);
  105. }
  106.  
  107. private State getState(){
  108. if(!fishingArea.contains(this.myPosition())){
  109. return State.WALK;
  110. }else if(this.client.isLoggedIn() && !this.inventory.contains("Feather")){
  111. return State.LOG;
  112. }else if(!this.inventory.isFull()){
  113. return State.FISH;
  114. } else{
  115. return State.DROP;
  116. }
  117. }
  118.  
  119. public void walk(){
  120. if(!this.myPlayer().isMoving() && getWalking().webWalk(fishingArea)){
  121. new ConditionalSleep((int)(Math.random() * 1000 + 2000)){
  122. @Override
  123. public boolean condition() throws InterruptedException{
  124. return fishingArea.contains(myPosition());
  125. }
  126. }.sleep();
  127. }
  128. }
  129.  
  130. public void fish(){
  131. if(!this.myPlayer().isAnimating() && !this.myPlayer().isMoving()){
  132. NPC lureFishingSpot = this.getNpcs().closest("Fishing spot");
  133. status = "Fishing";
  134. if(lureFishingSpot != null && lureFishingSpot.exists() && lureFishingSpot.interact(fishingStyle)){
  135. new ConditionalSleep((int)(Math.random() * 1000 + 3000)){
  136. @Override
  137. public boolean condition() throws InterruptedException{
  138. return myPlayer().isAnimating();
  139. }
  140. }.sleep();
  141. }
  142. }
  143. }
  144.  
  145. public void drop() throws InterruptedException{
  146. status = "Dropping";
  147. if(this.tabs.getOpen() != Tab.INVENTORY){
  148. this.tabs.open(Tab.INVENTORY);
  149. }
  150. this.keyboard.pressKey(KeyEvent.VK_SHIFT);
  151. for(int i: ZIGZAG_DROP){
  152. if(this.inventory.getItemInSlot(i) != null && this.inventory.getItemInSlot(i).hasAction("Drop") && this.inventory.getItemInSlot(i).getName().startsWith(fishType)){
  153. InventorySlotDestination destination = new InventorySlotDestination(this.bot, i);
  154. int x = (int) Math.round(destination.getBoundingBox().getCenterX());
  155. int y = (int) Math.round(destination.getBoundingBox().getCenterY());
  156. this.bot.getMouseEventHandler().generateBotMouseEvent(java.awt.event.MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, x, y, 0 ,false, 0, true);
  157. this.mouse.click(false);
  158. sleep(50);
  159. }
  160. }
  161. this.keyboard.releaseKey(KeyEvent.VK_SHIFT);
  162. }
  163.  
  164. private void gui(){
  165. fishingType = new JComboBox<>(new FishType[]{FishType.NORMAL_LURE, FishType.BARBARIAN_LURE});
  166.  
  167. // Declare two constants for width and height of the GUI
  168. final int GUI_WIDTH = 300, GUI_HEIGHT = 80;
  169.  
  170. // Get the size of the screen
  171. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  172.  
  173. // Calculating x and y coordinates
  174. final int gX = (int) (screenSize.getWidth() / 2) - (GUI_WIDTH / 2);
  175. final int gY = (int) (screenSize.getHeight() / 2) - (GUI_HEIGHT / 2);
  176.  
  177. // Create a new JFrame with the title "GUI"
  178. gui = new JFrame("HanFisher");
  179.  
  180. // Set the x coordinate, y coordinate, width and height of the GUI
  181. gui.setBounds(gX, gY, GUI_WIDTH, GUI_HEIGHT);
  182.  
  183. gui.setResizable(false); // Disable resizing
  184.  
  185. // Create a sub container JPanel
  186. JPanel panel = new JPanel();
  187.  
  188. // Add it to the GUI
  189. gui.add(panel);
  190.  
  191. JLabel label = new JLabel("Fishing: "); // Create a label
  192. label.setForeground(Color.white); // Set text colour to white
  193. panel.add(label); // Add it to the JPanel
  194.  
  195. // Add an action listener, to listen for user's selections, assign to a variable called selectedTree on selection.
  196. fishingType.addActionListener(new ActionListener() {//add actionlistner to listen for change
  197. @Override
  198. public void actionPerformed(ActionEvent e) {
  199. currentFishingType = ((FishType)fishingType.getSelectedItem());
  200.  
  201. }
  202. });
  203. // Add the select box to the JPanel
  204. panel.add(fishingType);
  205.  
  206. JButton startButton = new JButton("Start");
  207. startButton.addActionListener(e -> {
  208. //do some startup procedure
  209. gui.setVisible(false);
  210. setRelevantArea();
  211. startTime = System.currentTimeMillis();
  212. getExperienceTracker().start(Skill.FISHING);
  213. thread = new Thread(){
  214. public synchronized void run(){
  215. for(;;){
  216. if(isRunning){
  217. try {
  218. runTime = System.currentTimeMillis() - startTime;
  219. this.wait(50);
  220. } catch (InterruptedException ex) {
  221. log(ex);
  222. }
  223. }else{
  224. break;
  225. }
  226. }
  227. }
  228. };
  229. thread.start();
  230. status = "Running";
  231. started = true;
  232.  
  233. });
  234. panel.add(startButton);
  235.  
  236. // Make the GUI visible
  237. gui.setVisible(true);
  238. }
  239.  
  240. public void setRelevantArea(){
  241. switch(currentFishingType){
  242. case NORMAL_LURE:
  243. fishType = "Raw";
  244. fishingStyle = "Lure";
  245. fishingArea = new Area(new int[][]{{ 3106, 3422 },{ 3101, 3422 },{ 3100, 3439 },{ 3110, 3438 },{ 3110, 3429 }});
  246. break;
  247. case BARBARIAN_LURE:
  248. fishType = "Leaping";
  249. fishingStyle = "Use-rod";
  250. fishingArea = new Area(new int[][]{{ 2509, 3491 },{ 2503, 3491 },{ 2496, 3508 },{ 2500, 3520 },{ 2510, 3519 }});
  251. break;
  252. default:
  253. break;
  254. }
  255. }
  256.  
  257. @Override
  258. public final void onStart(){
  259. gui();
  260. getBot().addMouseListener(this);
  261. try {
  262. BufferedImage img = ImageIO.read(new URL("http://i.imgur.com/U1aEEuQ.png"));
  263. paint = img;
  264. BufferedImage img2 = ImageIO.read(new URL("http://i.imgur.com/BmpCgKb.png"));
  265. closePaint = img2;
  266. } catch (MalformedURLException ex) {
  267. log(ex);
  268. } catch (IOException ex) {
  269. log(ex);
  270. }
  271. }
  272.  
  273. @Override
  274. public final void onExit(){
  275. isRunning = false;
  276. status = "Stopped";
  277. getBot().removeMouseListener(this);
  278. log("CLFisher stopped.");
  279. }
  280.  
  281. @Override
  282. public final void onMessage(final Message message){
  283.  
  284. }
  285.  
  286.  
  287. @Override
  288. public void onPaint(final Graphics2D g) {
  289. g.setColor(Color.DARK_GRAY);
  290. if(!hide){
  291. g.drawImage(paint, 1, 338, null);
  292. g.drawString(status, 121, 406); // status
  293. g.drawString(getSkills().getStatic(Skill.FISHING) + " (" + getExperienceTracker().getGainedLevels(Skill.FISHING) + ")", 121, 437); //current fishing level
  294. g.drawString("" + getExperienceTracker().getGainedXP(Skill.FISHING), 121, 467); // exp gained
  295. g.drawString(formatTime(runTime), 293, 406); // run time
  296. g.drawString("" + formatTime(getExperienceTracker().getTimeToLevel(Skill.FISHING)), 293, 437); //TTL
  297. g.drawString("" + getExperienceTracker().getGainedXPPerHour(Skill.FISHING), 293, 467); //exp per hour
  298. }
  299. g.drawImage(closePaint, 490, 348, null);
  300. }
  301.  
  302. public final String formatTime(final long ms){
  303. long s = ms / 1000, m = s / 60, h = m / 60;
  304. s %= 60;
  305. m %= 60;
  306. h %= 24;
  307. return String.format("%02d:%02d:%02d", h, m, s);
  308. }
  309.  
  310. @Override
  311. public void mouseClicked(MouseEvent me) {
  312. Point p = me.getPoint();
  313. Rectangle hideRect = new Rectangle(490, 348, 20, 12);
  314. if (hideRect.contains(p) && !hide) {
  315. hide = true;
  316. } else if (hideRect.contains(p) && hide) {
  317. hide = false;
  318. }
  319. }
  320.  
  321. @Override
  322. public void mousePressed(MouseEvent me) {
  323. }
  324.  
  325. @Override
  326. public void mouseReleased(MouseEvent me) {
  327. }
  328.  
  329. @Override
  330. public void mouseEntered(MouseEvent me) {
  331. }
  332.  
  333. @Override
  334. public void mouseExited(MouseEvent me) {
  335. }
  336. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement