Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sorcGardenMinigame;
- import org.osbot.rs07.api.model.NPC;
- import org.osbot.rs07.api.map.Position;
- import org.osbot.rs07.api.model.RS2Object;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import org.osbot.rs07.api.map.Area;
- import org.osbot.rs07.input.mouse.MiniMapTileDestination;
- import java.awt.*;
- import java.util.Arrays;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- @ScriptManifest(name = "SorcGardenSolver", author = "Zappa2010", version = 1.1, info = "Solves the sorc garden minigame for fruitz", logo = "")
- public class main extends Script {
- private JFrame jFrame;
- private long timeBegan;
- private long timeRan;
- private String selectedGarden = "Winter";
- private boolean started = false;
- private void createJFrame() {
- final int frameWidth = 500, frameHeight = 200;
- final int halfFWidth = (frameWidth / 2), halfFHeight = (frameHeight / 2);
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- final int jFrameX = (int) (screenSize.getWidth() / 2) - halfFWidth;
- final int jFrameY = (int) (screenSize.getHeight() / 2) - halfFHeight;
- jFrame = new JFrame("SorcGarden");
- jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- jFrame.setBounds(jFrameX, jFrameY, halfFWidth, halfFHeight);
- JPanel jPanel = new JPanel();
- jFrame.add(jPanel);
- JLabel label = new JLabel("Select garden:");
- label.setForeground(Color.white);
- jPanel.add(label);
- label.setBounds(10,10, label.getWidth(), label.getHeight());
- JComboBox<String> gardenSelector = new JComboBox<>(new String[] { "winter", "spring" });
- gardenSelector.addActionListener( e-> selectedGarden = (String) gardenSelector.getSelectedItem());
- jPanel.add(gardenSelector);
- JButton startButton = new JButton("Start");
- startButton.addActionListener(e -> {
- started = true;
- jFrame.setVisible(false);
- });
- jPanel.add(startButton);
- jFrame.setVisible(true);
- }
- //end building gui
- //Many thanks to Explv and Lambos Bruh for helping with the gui
- private void setGarden(){
- switch (selectedGarden){
- case "winter":
- garden = 0;
- break;
- case "spring":
- garden = 1;
- break;
- }
- }
- private static final Area GARDEN_AREA = new Area(2903, 5480, 2920, 5463);
- private static final Area BANK_AREA = new Area(3309, 3119, 3301, 3126);
- private static final Area ENTER_AREA = new Area(3316,3143,3324,3137);
- public boolean doorIsClosed(RS2Object door) {
- return Arrays.asList(door.getDefinition().getActions()).contains("Open");
- }
- public enum State{
- WALK_TO_BANK, BANK, WALK_TO_GARDEN, SOLVE, EXIT, ENTER, BREATHE
- };
- private State getState() {
- if (inventory.isFull() && GARDEN_AREA.contains(myPlayer()))
- return State.EXIT;
- if (inventory.isFull() && BANK_AREA.contains(myPlayer()))
- return State.BANK;
- if (!inventory.isFull() && BANK_AREA.contains(myPlayer()))
- return State.WALK_TO_GARDEN;
- if (inventory.isFull())
- return State.WALK_TO_BANK;
- if(!inventory.isFull() &&ENTER_AREA.contains(myPlayer()))
- return State.ENTER;
- return State.SOLVE;
- }
- //Code to find + pick the fruit from the tree
- private boolean pickFruit() throws InterruptedException{
- RS2Object tree = objects.closest("Sq'irk tree");
- if(tree != null){
- tree.interact("Pick-Fruit");
- sleep(random(4000,5000));
- fruitPicked++;
- return true;
- }
- return false;
- }
- //All garden areas
- //0 - winter
- private Area[] treeZones={
- new Area (2888,5479,2895,5472),
- new Area(2933,5467,2930,5465)
- };
- //If the user is in the garden's tree zone, pick the fruit
- private boolean inTreeZone(int i)throws InterruptedException{
- return (treeZones[i].contains(myPlayer()))? pickFruit(): false;
- }
- //Area check for garden solver loop
- private boolean inArea(int i){
- log("here");
- return (playerArea[garden][i].contains(myPlayer())) ? true : false ;
- }
- @Override
- public void onStart() {
- timeBegan = System.currentTimeMillis();
- createJFrame();
- }
- @Override
- public void onExit() {
- if (jFrame != null) {
- jFrame.setVisible(false);
- jFrame.dispose();
- }
- log("Thanks for using my script! Please leave feedback");
- }
- private Position[][] walkPath = {
- { //winter path
- new Position(2903,5470,0),
- new Position(2900,5476,0),
- new Position(2898,5481,0),
- new Position(2893,5481,0),
- new Position(2892,5484,0),
- new Position(2891,5478,0)
- },
- {
- new Position(2920,5473,0),
- new Position(2923,5471,0),
- new Position(2923,5466,0),
- new Position(2923,5465,0),
- new Position(2923,5459,0),
- new Position(2924,5468,0),
- new Position(2928,5470,0),
- new Position(2931,5466,0)
- }
- };
- private Area[][] NpcArea ={
- {//winter NpcArea
- new Area(2899,5476,2897,5475),
- new Area(2897, 5478, 2897, 5472),
- new Area(2899,5480,2896,5483),
- new Area(2893,5481,2892,5483),
- new Area(2896,5482,2900,5483),
- new Area(2893, 5485, 2897, 5485),
- new Area(2896,5482,2891,5481)
- },
- {
- new Area(2922,5469,2922,5462),
- new Area(2922,5465,2922,5471),
- new Area(2925,5461,2926,5459),
- new Area(2925,5463,2928,5462),
- new Area(2925,5466,2925,5472),
- new Area(2925,5469,2925,5473),
- new Area(2931,5470,2931,5477),
- new Area(2931,5469,2933,5469)
- }
- };
- private Area[][] playerArea ={
- { //Winter garden = 0
- GARDEN_AREA,
- new Area(2902,5470,2901,5470),
- new Area(2901,5475,2899,5477),
- new Area(2898,5481,2897,5481),
- new Area(2892,5485,2891,5483)
- },
- {//spring garden = 1
- GARDEN_AREA,
- new Area(2923,5473,2923,5471),
- new Area(2923,5466,2923,5465),
- new Area(2923,5459,2923,5458),
- new Area(2924,5468,2926,5468),
- new Area(2926,5470,2928,5470)
- }
- };
- private void startRun() throws InterruptedException{
- do {
- sleep(random(1000,4000));
- }while(settings.getRunEnergy() < 5);
- settings.setRunning(true);
- }
- //Custom walk script to walk exact tile.. Hope this works :/
- public boolean pWalk(Position p) throws InterruptedException {
- startRun();
- do{
- mouse.click(new MiniMapTileDestination(bot, p), false);
- int fail = 0;
- while (myPosition().distance(p) > 2 && fail < 10) {
- if (!myPlayer().isMoving())
- fail++;
- }
- if (map.distance(p) <= 5)
- p.interact(bot,"Walk here");
- return fail != 10;
- }while(!myPlayer().isMoving());
- }
- private void gardenSolver(int i, NPC[] npc)throws InterruptedException{
- switch (garden){
- case 0:
- winterGarden(i,npc);
- break;
- case 1:
- springGarden(i,npc);
- break;
- }
- }
- private int springGarden(int step, NPC[] sNpc) throws InterruptedException{
- switch (step){
- case 0:
- log("Walking to spring garden door");
- pWalk(walkPath[garden][0]);
- sleep(random(700,1000));
- log("Opening the gate");
- objects.closest(12719).interact("Open");
- log("here2");
- sleep(random(800,900));
- pWalk(walkPath[garden][1]);
- code = 1;
- break;
- case 1:
- if (NpcArea[garden][0].contains(sNpc[0])&& sNpc[0].getRotation() == south){
- log("Walking to step 2");
- pWalk(walkPath[garden][2]);
- sleep(random(200,700));
- pWalk(walkPath[garden][3]);
- }
- break;
- case 2:
- if (NpcArea[garden][1].contains(sNpc[0])){
- log("walking to step 3");
- pWalk(walkPath[garden][4]);
- sleep(random(700,1000));
- }
- break;
- case 3:
- Area bugFix = new Area(2925,5467,2925,5465);
- if (bugFix.contains(myPlayer())){
- pWalk(walkPath[garden][4]);
- }
- if (NpcArea[garden][2].contains(sNpc[1]) && NpcArea[garden][3].contains(sNpc[2]) && NpcArea[garden][4].contains(sNpc[3]) && sNpc[3].getRotation() == north){
- log("Walking to step 4");
- pWalk(walkPath[garden][5]);
- sleep(random(700,1000));
- }
- break;
- case 4:
- if (NpcArea[garden][5].contains(sNpc[3]) && sNpc[3].getRotation()== north){
- log("walking to step 5");
- pWalk(walkPath[garden][6]);
- sleep(random(700,1000));
- }
- break;
- case 5:
- if (NpcArea[garden][6].contains(sNpc[4]) && sNpc[4].getRotation() == north && NpcArea[garden][7].contains(sNpc[5]) && sNpc[5].getRotation()==east){
- log("Walking to tree");
- pWalk(walkPath[garden][7]);
- }
- break;
- }
- return code;
- }
- //Following solves the winter garden
- private int winterGarden(int step, NPC[] wNpc) throws InterruptedException{
- switch (step){
- case 0:
- log("Walking to winter garden door");
- pWalk(walkPath[garden][0]);
- sleep(random(700,1000));
- log("Opening the gate");
- objects.closest(12617).interact("Open");
- log("here2");
- sleep(random(800,900));
- code = 1;
- break;
- case 1: //navigate around the first NPC
- if (NpcArea[garden][0].contains(wNpc[0])){
- log("Navigate first obsticle");
- pWalk(walkPath[garden][1]);
- log("here3");
- sleep(random(150, 450));
- code = 1;
- }else code = 0;
- break;
- case 2: //Navigate around the second NPC
- if (NpcArea[garden][1].contains(wNpc[0]) && NpcArea[garden][2].contains(wNpc[1])){
- log("Navigate second obsticle");
- pWalk(walkPath[garden][2]);
- sleep(random(150, 450));
- code = 1;
- }else code =0;
- break;
- //for some reason it won't do this
- //work it out tomorrow morning
- case 3: //navigate around the 3rd NPC
- if (NpcArea[garden][3].contains(wNpc[2]) && NpcArea[garden][4].contains(wNpc[1])){
- log("Navigate 3rd obsticle path 1");
- localWalker.walk(walkPath[garden][3]); //we are running a walk right after this, and don't want to wait the preset wait
- sleep(random(300,500));
- pWalk(walkPath[garden][4]);
- code = 1;
- /* }else if (NpcArea[garden][6].contains(wNpc[1]) && NpcArea[garden][4].contains(wNpc[1])){
- log("Navigate 3rd obsitcle path 2");
- pWalk(walkPath[garden][4]);*/
- }else code =0;
- break;
- case 4: //final stretch
- if (myPlayer().getPosition().equals(new Position(2891,5483,0))){
- walkPath[garden][4].interact(bot,"Walk here");
- sleep(random(400,700));
- }
- if (NpcArea[garden][5].contains(wNpc[3]) && wNpc[3].getRotation() == east){
- log("Navigate 4th obsticle");
- pWalk(walkPath[garden][5]);
- code = 1;
- }else code = 0;
- break;
- }
- return code;
- }
- private Position[] stuckLocation={
- new Position(2905,5478,0),
- new Position(2905,5477,0),
- new Position(2905,5476,0)
- };
- private Position[] walkBank = {
- new Position(3307,3144,0),
- new Position(3308,3120,0)
- };
- private Position[] walkGarden = {
- new Position(3304,3136,0),
- new Position(3321,3142,0)
- };
- private boolean stuck() {
- for (int i =0; i<stuckLocation.length; i++){
- if (myPlayer().getPosition().equals(stuckLocation[i])){
- log("The bot was detected in a stuck location");
- log("Now attempting to restart");
- return true;
- }
- }
- return false;
- }
- //keeping these cause it's nice to have them, they will be used in the next gardens
- private int north = 1024;
- private int east = 1536;
- private int south = 0;
- private int west = 512;
- //Get our global vars for the loop
- private int code = 0; //not used atm
- private int fruitPicked = 0;
- private int garden;
- @Override
- public int onLoop() throws InterruptedException{
- if (started) {
- setGarden();
- switch (getState()){
- case BREATHE:
- log("wait a min, I need to catch my breathe! (no run speed)");
- sleep(random(1000,7000));
- break;
- case WALK_TO_GARDEN:
- log("walk to garden");
- localWalker.walk(walkGarden[1]);
- localWalker.walk(3321,3139);
- RS2Object doorE = objects.closest("door");
- if(doorE != null){
- if (doorIsClosed(doorE)){
- doorE.interact("Open");
- sleep(random(100,250));
- }
- }
- break;
- case ENTER:
- log("entering the garden");
- NPC apprentice = npcs.closest("Apprentice");
- apprentice.interact("Teleport");
- sleep(random(4000,5000));
- break;
- case BANK:
- log("Attempting to deposit at the bank");
- RS2Object bankBooth = objects.closest("Bank chest");
- if (bankBooth != null) {
- if (bankBooth.interact("Use")) {
- while (!bank.isOpen()){
- sleep(random(250,500));
- bank.depositAll();
- }
- }
- }
- break;
- case WALK_TO_BANK:
- log("Walking to the bank");
- RS2Object exitDoor = objects.closest("door");
- if (doorIsClosed(exitDoor)){
- exitDoor.interact("open");
- sleep(random(450,650));
- }
- //localWalker.walk(walkBank[0]);
- sleep(random(150,250));
- localWalker.walk(walkBank[1]);
- sleep(random(150,250));
- break;
- case EXIT:
- log("Leaving the garden");
- RS2Object fountain = objects.closest("Fountain");
- if (fountain != null)
- fountain.interact("Drink-from");
- sleep(random(2000,3000));
- break;
- case SOLVE:
- NPC[][] gardenNpc= {
- {//winter Npc's
- npcs.closest(5798),
- npcs.closest(5799),
- npcs.closest(5800),
- npcs.closest(5801)
- },
- {//autumn Npc's
- npcs.closest(2956),
- npcs.closest(2958),
- npcs.closest(2957),
- npcs.closest(2962),
- npcs.closest(2963),
- npcs.closest(2961)
- }
- };
- if (!inTreeZone(garden)){
- for (int i = 0; i < playerArea[garden].length; i++){
- //log("here : "+i);
- if (inArea(i)){
- log("area : " + i);
- i = (stuck()) ? 0 : i;
- gardenSolver(i,gardenNpc[garden]);
- }
- }
- }
- break;
- }
- }
- return random(150,350); //The amount of time in milliseconds before the loop starts over
- }
- //stole the graphics off Lambos Bruh so, thanks bro. :)
- @Override
- public void onPaint(Graphics2D g) {
- if(started){
- /*if(tempFish < (skills.getExperience(Skill.FISHING) - startExp) && timeRan % 1000 == 0){
- log("Got One!");
- fishCounter++;
- }*/
- //tempFish = skills.getExperience(Skill.FISHING) - startExp;
- timeRan = System.currentTimeMillis() - this.timeBegan;
- g.drawString("Fruits picked: "+fruitPicked,4, 315);
- g.drawString("Time Ran: " + ft(timeRan), 4, 330);
- }
- }
- private String ft(long duration) {
- long s = duration / 1000, m = s / 60, h = m / 60;
- s %= 60; m %= 60; h %= 24;
- return String.format("%02d:%02d:%02d", h, m, s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment