Advertisement
Guest User

LumbyCookAndFishSlakan

a guest
Sep 22nd, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.osbot.rs07.api.filter.Filter;
  2. import org.osbot.rs07.api.map.Area;
  3. import org.osbot.rs07.api.map.Position;
  4. import org.osbot.rs07.api.model.NPC;
  5. import org.osbot.rs07.api.model.RS2Object;
  6. import org.osbot.rs07.api.ui.RS2Widget;
  7. import org.osbot.rs07.api.ui.Skill;
  8. import org.osbot.rs07.script.Script;
  9. import org.osbot.rs07.script.ScriptManifest;
  10. import org.osbot.rs07.utility.ConditionalSleep;
  11.  
  12. import java.awt.*;
  13. import java.util.concurrent.TimeUnit;
  14.  
  15. @ScriptManifest(author = "Slakan", name = "LumbyFisher", info = "Will fish as stated.", version = 1.00, logo = "")
  16. public final class LumbyFisher extends Script {
  17.  
  18.     // PAINT VARIABLE DECLARATIONS
  19.     private long timeBegan;
  20.     private int FishbeginningLevel;
  21.     private int CookbeginningLevel;
  22.  
  23.     // ONSTART() METHOD
  24.     public final void onStart() {
  25.         timeBegan = System.currentTimeMillis();
  26.         FishbeginningLevel = skills.getStatic(Skill.FISHING);
  27.         CookbeginningLevel = skills.getStatic(Skill.COOKING);
  28.     }
  29.  
  30.     private RS2Widget getMyWidget() {
  31.         //Replace ids with your ids
  32.         RS2Widget storedWidget = getWidgets().get(270, 14);
  33.         return storedWidget;
  34.     }
  35.  
  36.     private RS2Object range() {
  37.         RS2Object range = getObjects().closest("Range");
  38.         return range;
  39.     }
  40.  
  41.     @Override
  42.     public final int onLoop() throws InterruptedException {
  43.         Area fishingArea = new Area(3250, 3143, 3239, 3157);
  44.         Area rangeArea = new Area(3233, 3195, 3230, 3198);
  45.         Area outsideBuilding = new Area(3237, 3202, 3233, 3199);
  46.         Position doorPosition = new Position(3235, 3198, 0);
  47.         NPC fishingSpot = getNpcs().closest("Fishing spot");
  48.  
  49.         if (dialogues.isPendingContinuation()) {
  50.             dialogues.clickContinue();
  51.         } else {
  52.             if (!inventory.isFull()) {
  53.                 // inventory is not full
  54.                 log("Inventory not full");
  55.                 if (fishingArea.contains(myPlayer().getPosition())) {
  56.                     // We are at fishing area
  57.                     log("We are at fishing area!");
  58.                     if (myPlayer().isAnimating()) {
  59.                         log("We are animating for fishing!!");
  60.                         new ConditionalSleep(5000) {
  61.                             @Override
  62.                             public boolean condition() {
  63.                                 return inventory.isFull();
  64.                             }
  65.                         }.sleep();
  66.                     } else {
  67.                         if (fishingSpot.interact("Net")) {
  68.                             mouse.moveOutsideScreen();
  69.                             log("Interact with spot!");
  70.                             new ConditionalSleep(1000) {
  71.                                 @Override
  72.                                 public boolean condition() {
  73.                                     return myPlayer().isAnimating() || dialogues.clickContinue();
  74.                                 }
  75.                             }.sleep();
  76.                         }
  77.                     }
  78.                 } else {
  79.                     // We arent at fishing area
  80.                     log("We aint at fishing area!");
  81.                     // can we see the fishing spot? - We should click it, then we are in area.
  82.                     walking.webWalk(fishingArea);
  83.                 }
  84.  
  85.             } else {
  86.                 //inventory full
  87.                 if (inventory.contains("Raw anchovies", "Raw shrimps")) {
  88.                     if (rangeArea.contains(myPlayer())) {
  89.                         log("We are in range area");
  90.                         // We are at range area!
  91.                         if (myPlayer().isAnimating()) {
  92.                             log("We are animating cooking!");
  93.                             new ConditionalSleep(1000) {
  94.                                 @Override
  95.                                 public boolean condition() {
  96.                                     return !myPlayer().isAnimating() || !inventory.contains("Raw anchovies", "Raw shrimps");
  97.                                 }
  98.                             }.sleep();
  99.                         } else {
  100.                             log("We are in range area, not animating and ready to cook!");
  101.                             // We are inside the range area, we are not animating! We should click range and start cook!
  102.                             if (getMyWidget() == null) {
  103.                                 // We see menu
  104.                                 log("We can't see menu!");
  105.                                 if (range().isVisible() && range() != null) {
  106.                                     if (range().interact()) {
  107.                                         sleep(random(2000, 3000));
  108.                                         log("We can click range!");
  109.                                         new ConditionalSleep(5000) {
  110.                                             @Override
  111.                                             public boolean condition() {
  112.                                                 return getMyWidget().isVisible();
  113.                                             }
  114.                                         }.sleep();
  115.                                     }
  116.  
  117.                                 }
  118.  
  119.                             } else {
  120.                                 log("menu open!");
  121.                                 if (getMyWidget().interact("Cook")) {
  122.                                     sleep(random(500, 1000));
  123.                                     new ConditionalSleep(5000) {
  124.                                         @Override
  125.                                         public boolean condition() {
  126.                                             return !myPlayer().isAnimating();
  127.                                         }
  128.                                     }.sleep();
  129.                                 }
  130.                             }
  131.  
  132.                         }
  133.                     } else {
  134.                         // We aint at range area!
  135.                         log("We are not in range area!");
  136.                         if (inventory.isFull() && inventory.contains("Raw shrimps", "Raw anchovies")) {
  137.                             // We are not outside building & We can walk.
  138.                             log("inventory is full and its either shrimps, anchovies or both.");
  139.                             if (!outsideBuilding.contains(myPlayer()) && walking.walk(outsideBuilding)) {
  140.                                 log("Walking to outside area!");
  141.                                 new ConditionalSleep(5000) {
  142.                                     @Override
  143.                                     public boolean condition() {
  144.                                         return outsideBuilding.contains(myPlayer());
  145.                                     }
  146.                                 }.sleep();
  147.                             } else {
  148.                                 RS2Object isDoorOpen1 = getObjects().closest(new Filter<RS2Object>() {
  149.                                     @Override
  150.                                     public boolean match(RS2Object o) {
  151.                                         if (o != null && o.hasAction("Open") && o.getPosition().equals(doorPosition))
  152.                                             return true;
  153.                                         return false;
  154.                                     }
  155.                                 });
  156.                                 if (isDoorOpen1 == null) {
  157.                                     log("Door open!");
  158.                                     if (!rangeArea.contains(myPlayer())) {
  159.                                         walking.walk(rangeArea);
  160.                                     }
  161.                                 }
  162.                                 log("We are outside. Now how about the door?");
  163.                                 if (getDoorHandler().canReachOrOpen(doorPosition)) {
  164.                                     // We can handle door!
  165.                                     log("We can handle the door??");
  166.                                     // Get the door in position
  167.                                     RS2Object doorAtPosition = getObjects().closest(new Filter<RS2Object>() {
  168.                                         @Override
  169.                                         public boolean match(RS2Object o) {
  170.                                             if (o != null && o.getName().equals("Door") && o.getPosition().equals(doorPosition))
  171.                                                 return true;
  172.                                             return false;
  173.                                         }
  174.                                     });
  175.                                     if (doorAtPosition != null && doorAtPosition.isVisible()) {
  176.                                         RS2Object isDoorOpen = getObjects().closest(new Filter<RS2Object>() {
  177.                                             @Override
  178.                                             public boolean match(RS2Object o) {
  179.                                                 if (o != null && o.hasAction("Open") && o.getPosition().equals(doorPosition))
  180.                                                     return true;
  181.                                                 return false;
  182.                                             }
  183.                                         });
  184.                                         if (isDoorOpen != null && outsideBuilding.contains(myPlayer())) {
  185.                                             log("We need to open door");
  186.                                             // This really needs to be checked again, works for now..
  187.                                             isDoorOpen.interact("Open");
  188.                                         } else {
  189.                                             log("Door is opened!");
  190.                                         }
  191.                                     } else {
  192.                                         log("Door is most probably opened. Need failsafes!");
  193.  
  194.                                     }
  195.                                 } else {
  196.                                     // Cant handle door.
  197.                                 }
  198.                             }
  199.  
  200.                         } else {
  201.                             // We have full inv, but nothing in there is fishes.
  202.                         }
  203.                     }
  204.                 } else {
  205.                     inventory.dropAllExcept("Small fishing net");
  206.                 }
  207.  
  208.             }
  209.         }
  210.         return 300;
  211.     }
  212.  
  213.     // ONPAINT() METHOD
  214.     public void onPaint(Graphics2D g) {
  215.         //Levels
  216.         int FishcurrentLevel = skills.getStatic(Skill.FISHING);
  217.         int CookcurrentLevel = skills.getStatic(Skill.COOKING);
  218.         int FishlevelsGained = FishcurrentLevel - FishbeginningLevel;
  219.         int CooklevelsGained = CookcurrentLevel - CookbeginningLevel;
  220.         long timeRan = System.currentTimeMillis() - this.timeBegan;
  221.  
  222.         g.drawString("Version: 1.00", 6, 185);
  223.         g.drawString("Runtime: " + ft(timeRan), 6, 200);
  224.         g.drawString("Fishing start lvl: " + FishbeginningLevel + " + " + FishlevelsGained, 6, 215);
  225.         g.drawString("Cooking start lvl: " + CookbeginningLevel + " + " + CooklevelsGained, 6, 230);
  226.         //Color rscolor = new Color(200, 180, 150);
  227.         //g.setColor(rscolor);
  228.         //g.fillRect(6,344, 506, 130);
  229.     }
  230.  
  231.     // FORMAT TIME METHOD
  232.     private String ft(long duration) {
  233.         String res = "";
  234.         long days = TimeUnit.MILLISECONDS.toDays(duration);
  235.         long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
  236.         long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration));
  237.         long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration));
  238.         if (days == 0) {
  239.             res = ("Hours: " + hours + " Minutes: " + minutes + " Seconds: " + seconds);
  240.         } else {
  241.             res = ("Days: " + days + "Hours: " + hours + "Minutes: " + minutes + "Seconds: " + seconds);
  242.         }
  243.         return res;
  244.     }
  245.  
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement