Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.io.IOException;
- import java.net.URL;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import java.awt.Point;
- import org.osbot.rs07.api.map.Area;
- import org.osbot.rs07.api.map.Position;
- import org.osbot.rs07.api.model.NPC;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import org.osbot.rs07.utility.ConditionalSleep;
- @ScriptManifest(author = "fishingfff", info = "Buys beer in Port Sarim for profit.", name = "fffBeerBuyer", version = 1.2, logo = "http://i.imgur.com/FuUYcCX.png")
- public class fffBeerBuyer extends Script {
- private final Image bg = getImage("http://orig11.deviantart.net/69e7/f/2012/128/5/f/runescape_plain_paint_template__by_realmgraphics-d4z0e43.png");
- private Image getImage(String url)
- {
- try
- {
- return ImageIO.read(new URL(url));
- }
- catch (IOException e) {}
- return null;
- }
- //PS AREAS
- private final Area BArea = new Area( new Position(3044,3236,0), new Position(3046,3235,0));
- private final Area BARAREA = new Area( new Position(3045,3255,0), new Position(3048,3258,0));
- private final Area dboxArea = new Area(3045, 3235, 3044, 3236);
- //VARROCK AREAS
- private final Area BARAREAV = new Area(3225, 3401, 3227, 3395);
- private final Area BAreaV = new Area(3257, 3419, 3250, 3422); //BARea = BankArea
- long beercount;
- long startTime;
- long coincount1;
- long coincount2;
- String state;
- String varrockstate;
- private JFrame gui;
- private String selectedBeer = "Beer in PSarim";
- private boolean started = false;
- private void createGUI(){
- // Declare two constants for width and height of the GUI
- final int GUI_WIDTH = 350, GUI_HEIGHT = 115;
- // 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("GUI");
- // 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("Select beer & place."); // Create a label
- label.setForeground(Color.white); // Set text colour to white
- panel.add(label); // Add it to the JPanel
- // Create a select box for tree options
- 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"});
- // Add an action listener, to listen for user's selections, assign to a variable called selectedTree on selection.
- beerSelector.addActionListener(e -> selectedBeer = beerSelector.getSelectedItem().toString());
- // Add the select box to the JPanel
- panel.add(beerSelector);
- JButton startButton = new JButton("Start");
- startButton.addActionListener(e -> {
- started = true;
- gui.setVisible(false);
- });
- panel.add(startButton);
- // Make the GUI visible
- gui.setVisible(true);
- }
- @Override
- public void onStart()
- {
- createGUI();
- startTime = System.currentTimeMillis();
- coincount1 = getInventory().getItem("Coins").getAmount();
- }
- private enum State
- {
- BUY,WALK2DEP,DEPOSIT,WALK2BART,LOGOUT
- }
- //BEER IN PS STATES
- private State getState()
- {
- if(inventory.getItem("Coins").getAmount() < 2)
- {
- state = "Logging Out";
- return State.LOGOUT;
- }
- if(!getInventory().isFull() && BARAREA.contains(myPlayer()))
- {
- state = "Buying Beer";
- return State.BUY;
- }
- if(getInventory().isFull() && !BArea.contains(myPlayer()))
- {
- state = "Walking to Depositbox";
- return State.WALK2DEP;
- }
- if(getInventory().isFull() && BArea.contains(myPlayer()))
- {
- state = "Depositing Items";
- return State.DEPOSIT;
- }
- if(!getInventory().isFull() && !BARAREA.contains(myPlayer()))
- {
- state = "Walking to Bartender";
- return State.WALK2BART;
- }
- return State.BUY;
- }
- //BEER IN VARROCK STATES
- private enum VarrockState
- {
- BUYV,WALK2DEPV,DEPOSITV,WALK2BARTV,LOGOUTV
- }
- private VarrockState getVarrockState()
- {
- if(inventory.getItem("Coins").getAmount() < 2)
- {
- varrockstate = "Logging Out";
- return VarrockState.LOGOUTV;
- }
- if(!getInventory().isFull() && BARAREAV.contains(myPlayer()))
- {
- varrockstate = "Buying Beer";
- return VarrockState.BUYV;
- }
- if(getInventory().isFull() && !BAreaV.contains(myPlayer()))
- {
- varrockstate = "Walking to Depositbox";
- return VarrockState.WALK2DEPV;
- }
- if(getInventory().isFull() && BAreaV.contains(myPlayer()))
- {
- varrockstate = "Depositing Items";
- return VarrockState.DEPOSITV;
- }
- if(!getInventory().isFull() && !BARAREAV.contains(myPlayer()))
- {
- varrockstate = "Walking to Bartender";
- return VarrockState.WALK2BARTV;
- }
- return VarrockState.BUYV;
- }
- @Override
- public int onLoop() throws InterruptedException {
- if (started) {
- if (selectedBeer.equals("Beer in PSarim")) {
- switch (getState()) {
- case LOGOUT:
- log("You have ran out of coins!");
- stop();
- case BUY:
- NPC shop = npcs.closest("Bartender");
- if (!getDialogues().inDialogue() && shop != null) {
- shop.interact("Talk-to");
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return !getDialogues().inDialogue();
- }
- }.sleep();
- } else if (getDialogues().selectOption(1)) {
- getDialogues().completeDialogue("Click here to continue");
- coincount2 = getInventory().getItem("Coins").getAmount();
- beercount = (coincount1 - coincount2) / 2;
- }
- break;
- case WALK2DEP:
- if (getWalking().webWalk(dboxArea)) {
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return !myPlayer().isMoving();
- }
- }.sleep();
- }
- break;
- case DEPOSIT:
- if (!getDepositBox().isOpen()) {
- getDepositBox().open();
- sleep(random(250, 500));
- getDepositBox().depositAllExcept("Coins");
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return getInventory().isEmptyExcept(995);
- }
- }.sleep();
- }
- break;
- case WALK2BART:
- if (getWalking().webWalk(BARAREA)) {
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return !myPlayer().isMoving();
- }
- }.sleep();
- }
- break;
- }
- } else if (selectedBeer.equals("Beer in Varrock")) {
- switch (getVarrockState()) {
- case LOGOUTV:
- log("You have ran out of coins!");
- stop();
- case BUYV:
- NPC shopV = npcs.closest("Bartender");
- if (!getDialogues().inDialogue() && shopV != null) {
- shopV.interact("Talk-to");
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return getDialogues().isPendingContinuation();
- }
- }.sleep(); //removed cond sleep cause of bot spamming bartender ?
- } else if (getDialogues().isPendingContinuation()) {
- getDialogues().clickContinue();
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return getDialogues().isPendingContinuation();
- }
- }.sleep();
- if(getDialogues().isPendingContinuation())
- getDialogues().completeDialogue("A glass of your finest ale please.");
- if (getDialogues().isPendingContinuation())
- getDialogues().clickContinue();
- getDialogues().completeDialogue("Click here to continue");
- coincount2 = getInventory().getItem("Coins").getAmount();
- beercount = (coincount1 - coincount2) / 2;
- }
- break;
- case WALK2DEPV:
- if (getWalking().webWalk(BAreaV)) {
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return !myPlayer().isMoving();
- }
- }.sleep();
- }
- break;
- case DEPOSITV:
- if (!getBank().isOpen()) {
- getBank().open();
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return getBank().isOpen();
- }
- }.sleep();
- getBank().depositAllExcept("Coins");
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return getInventory().isEmptyExcept(995);
- }
- }.sleep();
- getBank().close();
- }
- break;
- case WALK2BARTV:
- if (getWalking().webWalk(BARAREAV)) {
- new ConditionalSleep(10000) {
- @Override
- public boolean condition() throws InterruptedException {
- return !myPlayer().isMoving();
- }
- }.sleep();
- }
- break;
- }
- }
- }//else if (selectedBeer.equals("Wizard's MB in Falador")) { do this }
- //else if (selectedBeer.equals("Dwarven Stout in Falador")) { do this } else if (selectedBeer.equals("Asgarnian Ale in Falador")) { do this }
- return 0;
- }
- @Override
- public void onExit() {
- if(gui != null) { // If the JFrame has been created
- gui.setVisible(false); // Hide it
- gui.dispose(); // Dispose
- }
- log("Thanks for using this script!");
- log("I'd be glad if you posted a proggy on my thread, thanks! :)");
- }
- @Override
- public void onPaint(Graphics2D g){
- if(started){ // If the user has started the script
- //g.drawImage(bg, 0, 337, null);
- long ss = (System.currentTimeMillis() - startTime) / 1000;
- long mm = ss / 60;
- long hh = mm / 60;
- Point mP = this.getMouse().getPosition();
- g.setColor(Color.ORANGE);
- g.drawLine(mP.x, 0, mP.x, 500);
- g.drawLine(0, mP.y, 800, mP.y);
- g.drawRect(mP.x - 10, mP.y - 10, 20, 20);
- g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5);
- g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5);
- Font font = new Font("Candara", Font.BOLD, 20);
- g.setColor(Color.BLUE);
- g.setFont(font);
- g.drawString("fishingfff's Beer Buyer", 15, 370);
- g.drawString("Time Ran: " + hh + ":" + mm%60 + ":" + ss%60 , 15, 390);
- g.drawString(state, 300, 370);
- g.drawString("Version 1.2", 300, 390); // Rest of the paint code
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement