Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package hanfisher;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import javax.imageio.ImageIO;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import org.osbot.rs07.api.map.Area;
- import org.osbot.rs07.api.model.NPC;
- import org.osbot.rs07.api.ui.Message;
- import org.osbot.rs07.api.ui.Skill;
- import org.osbot.rs07.api.ui.Tab;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import org.osbot.rs07.utility.ConditionalSleep;
- import org.osbot.rs07.input.mouse.InventorySlotDestination;
- import static org.osbot.rs07.script.MethodProvider.random;
- import static org.osbot.rs07.script.MethodProvider.sleep;
- /**
- *
- * @author runescapebot
- */
- @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")
- public final class HanFisher extends Script implements MouseListener{
- private String status = "Stopped";
- private Image paint;
- private Image closePaint;
- private boolean hide = false;
- Area fishingArea;
- 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};
- private String fishType;
- private String fishingStyle;
- //GUI
- private JFrame gui;
- private FishType currentFishingType;
- private JComboBox<FishType> fishingType = new JComboBox<>(new FishType[]{FishType.NORMAL_LURE});;
- private long startTime;
- private long runTime = 0;
- private Thread thread;
- private boolean started = false;
- private boolean isRunning = true;
- private enum FishType{
- BARBARIAN_LURE, NORMAL_LURE;
- }
- private enum State{
- LOG, FISH, DROP, WALK;
- }
- @Override
- public int onLoop() throws InterruptedException {
- if(!started){
- new ConditionalSleep(60*30*1000, 500){
- @Override
- public boolean condition() throws InterruptedException{
- return started;
- }
- }.sleep();
- } else{
- switch(getState()){
- case LOG:
- this.stop();
- log("No feathers in inventory.");
- break;
- case FISH:
- fish();
- break;
- case DROP:
- drop();
- break;
- case WALK:
- walk();
- break;
- default:
- break;
- }
- }
- return random(400, 700);
- }
- private State getState(){
- if(!fishingArea.contains(this.myPosition())){
- return State.WALK;
- }else if(this.client.isLoggedIn() && !this.inventory.contains("Feather")){
- return State.LOG;
- }else if(!this.inventory.isFull()){
- return State.FISH;
- } else{
- return State.DROP;
- }
- }
- public void walk(){
- if(!this.myPlayer().isMoving() && getWalking().webWalk(fishingArea)){
- new ConditionalSleep((int)(Math.random() * 1000 + 2000)){
- @Override
- public boolean condition() throws InterruptedException{
- return fishingArea.contains(myPosition());
- }
- }.sleep();
- }
- }
- public void fish(){
- if(!this.myPlayer().isAnimating() && !this.myPlayer().isMoving()){
- NPC lureFishingSpot = this.getNpcs().closest("Fishing spot");
- status = "Fishing";
- if(lureFishingSpot != null && lureFishingSpot.exists() && lureFishingSpot.interact(fishingStyle)){
- new ConditionalSleep((int)(Math.random() * 1000 + 3000)){
- @Override
- public boolean condition() throws InterruptedException{
- return myPlayer().isAnimating();
- }
- }.sleep();
- }
- }
- }
- public void drop() throws InterruptedException{
- status = "Dropping";
- if(this.tabs.getOpen() != Tab.INVENTORY){
- this.tabs.open(Tab.INVENTORY);
- }
- this.keyboard.pressKey(KeyEvent.VK_SHIFT);
- for(int i: ZIGZAG_DROP){
- if(this.inventory.getItemInSlot(i) != null && this.inventory.getItemInSlot(i).hasAction("Drop") && this.inventory.getItemInSlot(i).getName().startsWith(fishType)){
- InventorySlotDestination destination = new InventorySlotDestination(this.bot, i);
- int x = (int) Math.round(destination.getBoundingBox().getCenterX());
- int y = (int) Math.round(destination.getBoundingBox().getCenterY());
- this.bot.getMouseEventHandler().generateBotMouseEvent(java.awt.event.MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, x, y, 0 ,false, 0, true);
- this.mouse.click(false);
- sleep(50);
- }
- }
- this.keyboard.releaseKey(KeyEvent.VK_SHIFT);
- }
- private void gui(){
- fishingType = new JComboBox<>(new FishType[]{FishType.NORMAL_LURE, FishType.BARBARIAN_LURE});
- // Declare two constants for width and height of the GUI
- final int GUI_WIDTH = 300, GUI_HEIGHT = 80;
- // Get the size of the screen
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- // Calculating x and y coordinates
- final int gX = (int) (screenSize.getWidth() / 2) - (GUI_WIDTH / 2);
- final int gY = (int) (screenSize.getHeight() / 2) - (GUI_HEIGHT / 2);
- // Create a new JFrame with the title "GUI"
- gui = new JFrame("HanFisher");
- // Set the x coordinate, y coordinate, width and height of the GUI
- gui.setBounds(gX, gY, GUI_WIDTH, GUI_HEIGHT);
- gui.setResizable(false); // Disable resizing
- // Create a sub container JPanel
- JPanel panel = new JPanel();
- // Add it to the GUI
- gui.add(panel);
- JLabel label = new JLabel("Fishing: "); // Create a label
- label.setForeground(Color.white); // Set text colour to white
- panel.add(label); // Add it to the JPanel
- // Add an action listener, to listen for user's selections, assign to a variable called selectedTree on selection.
- fishingType.addActionListener(new ActionListener() {//add actionlistner to listen for change
- @Override
- public void actionPerformed(ActionEvent e) {
- currentFishingType = ((FishType)fishingType.getSelectedItem());
- }
- });
- // Add the select box to the JPanel
- panel.add(fishingType);
- JButton startButton = new JButton("Start");
- startButton.addActionListener(e -> {
- //do some startup procedure
- gui.setVisible(false);
- setRelevantArea();
- startTime = System.currentTimeMillis();
- getExperienceTracker().start(Skill.FISHING);
- thread = new Thread(){
- public synchronized void run(){
- for(;;){
- if(isRunning){
- try {
- runTime = System.currentTimeMillis() - startTime;
- this.wait(50);
- } catch (InterruptedException ex) {
- log(ex);
- }
- }else{
- break;
- }
- }
- }
- };
- thread.start();
- status = "Running";
- started = true;
- });
- panel.add(startButton);
- // Make the GUI visible
- gui.setVisible(true);
- }
- public void setRelevantArea(){
- switch(currentFishingType){
- case NORMAL_LURE:
- fishType = "Raw";
- fishingStyle = "Lure";
- fishingArea = new Area(new int[][]{{ 3106, 3422 },{ 3101, 3422 },{ 3100, 3439 },{ 3110, 3438 },{ 3110, 3429 }});
- break;
- case BARBARIAN_LURE:
- fishType = "Leaping";
- fishingStyle = "Use-rod";
- fishingArea = new Area(new int[][]{{ 2509, 3491 },{ 2503, 3491 },{ 2496, 3508 },{ 2500, 3520 },{ 2510, 3519 }});
- break;
- default:
- break;
- }
- }
- @Override
- public final void onStart(){
- gui();
- getBot().addMouseListener(this);
- try {
- BufferedImage img = ImageIO.read(new URL("http://i.imgur.com/U1aEEuQ.png"));
- paint = img;
- BufferedImage img2 = ImageIO.read(new URL("http://i.imgur.com/BmpCgKb.png"));
- closePaint = img2;
- } catch (MalformedURLException ex) {
- log(ex);
- } catch (IOException ex) {
- log(ex);
- }
- }
- @Override
- public final void onExit(){
- isRunning = false;
- status = "Stopped";
- getBot().removeMouseListener(this);
- log("CLFisher stopped.");
- }
- @Override
- public final void onMessage(final Message message){
- }
- @Override
- public void onPaint(final Graphics2D g) {
- g.setColor(Color.DARK_GRAY);
- if(!hide){
- g.drawImage(paint, 1, 338, null);
- g.drawString(status, 121, 406); // status
- g.drawString(getSkills().getStatic(Skill.FISHING) + " (" + getExperienceTracker().getGainedLevels(Skill.FISHING) + ")", 121, 437); //current fishing level
- g.drawString("" + getExperienceTracker().getGainedXP(Skill.FISHING), 121, 467); // exp gained
- g.drawString(formatTime(runTime), 293, 406); // run time
- g.drawString("" + formatTime(getExperienceTracker().getTimeToLevel(Skill.FISHING)), 293, 437); //TTL
- g.drawString("" + getExperienceTracker().getGainedXPPerHour(Skill.FISHING), 293, 467); //exp per hour
- }
- g.drawImage(closePaint, 490, 348, null);
- }
- public final String formatTime(final long ms){
- long s = ms / 1000, m = s / 60, h = m / 60;
- s %= 60;
- m %= 60;
- h %= 24;
- return String.format("%02d:%02d:%02d", h, m, s);
- }
- @Override
- public void mouseClicked(MouseEvent me) {
- Point p = me.getPoint();
- Rectangle hideRect = new Rectangle(490, 348, 20, 12);
- if (hideRect.contains(p) && !hide) {
- hide = true;
- } else if (hideRect.contains(p) && hide) {
- hide = false;
- }
- }
- @Override
- public void mousePressed(MouseEvent me) {
- }
- @Override
- public void mouseReleased(MouseEvent me) {
- }
- @Override
- public void mouseEntered(MouseEvent me) {
- }
- @Override
- public void mouseExited(MouseEvent me) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement