Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.41 KB | None | 0 0
  1. package com;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics2D;
  5. import java.awt.Point;
  6. import java.awt.image.BufferedImage;
  7. import java.lang.reflect.InvocationTargetException;
  8. import java.util.Arrays;
  9. import java.util.List;
  10. import java.util.stream.Collectors;
  11.  
  12. import javax.swing.SwingUtilities;
  13.  
  14. import org.osbot.rs07.api.def.ItemDefinition;
  15. import org.osbot.rs07.api.map.Area;
  16. import org.osbot.rs07.api.map.constants.Banks;
  17. import org.osbot.rs07.api.model.Entity;
  18. import org.osbot.rs07.api.model.GroundItem;
  19. import org.osbot.rs07.script.Script;
  20. import org.osbot.rs07.script.ScriptManifest;
  21. import org.osbot.rs07.utility.ConditionalSleep;
  22.  
  23. import com.gui.Gui;
  24. import com.gui.Paint;
  25.  
  26.  
  27. @ScriptManifest(name = "Nando's fucking looter v2", author = "Nando", info = "loots", version = 0.1, logo = "")
  28. public class Main extends Script {
  29.  
  30.     Gui ui;
  31.     Paint paint;
  32.     private long startTime;
  33.     private long GpGained;
  34.     Area wildy;
  35.     long arrowsCollected;
  36.     long lobstersCollected;
  37.     long swordfishCollected;
  38.     long anchoviesCollected;
  39.     private Walker myWalker;
  40.     BufferedImage background;
  41.     int anchovyPrice;
  42.     int swordfishPrice;
  43.     int addyArrowsPrice;
  44.     int lobsterPrice;
  45.     long inventorycashlimit;
  46.     private Area Lumbridge;
  47.     private Gui gui;
  48.     GroundItem item;
  49.    
  50.     public Main() {
  51.        
  52.         wildy = new Area(3239, 10158, 3268, 10137);
  53.         GpGained = 0L;
  54.         arrowsCollected = 0L;
  55.         lobstersCollected = 0L;
  56.         swordfishCollected = 0L;
  57.         anchoviesCollected = 0L;
  58.         inventorycashlimit = 250000;
  59.     }
  60.    
  61.     public void onStart() throws InterruptedException {
  62.        // Lumbridge = new Area(3200, 3210, 3230, 3230);
  63.         gui = new Gui();
  64.         myWalker = new Walker();
  65.            this.Lumbridge = new Area(3200, 3210, 3230, 3230);
  66.             this.log("HI");
  67.             this.startTime = System.currentTimeMillis();
  68.             this.myWalker.exchangeContext(this.getBot());
  69.             try {
  70.                 SwingUtilities.invokeAndWait(() -> {
  71.                     this.gui = new Gui();
  72.                     this.gui.open();
  73.                 });
  74.             }
  75.             catch (InterruptedException | InvocationTargetException e) {
  76.                 e.printStackTrace();
  77.                 this.stop();
  78.                 return;
  79.             }
  80.             if (!this.gui.isStarted()) {
  81.                 this.stop();
  82.                 return;
  83.             }
  84.             this.inventorycashlimit = this.gui.returnValue();
  85.  
  86.         }
  87.        
  88.     public final int onLoop() throws InterruptedException {
  89.         try {
  90.             if (Lumbridge.contains((Entity)myPlayer())) {
  91.                 log("WaLKING");
  92.                 getWalking().webWalk(new Area[] { Banks.EDGEVILLE });
  93.             }
  94.             else if (isUnderAttack()) {                
  95.                 bank();
  96.           ///  log("getting lured but I'm smart --> Walking to Lower wilderness Level to tele");
  97.             //getWalking().webWalk(new Area[] { wildy });
  98.                 getEquipment().interactWithNameThatContains("Edgeville", "Amulet of glory");
  99.             }
  100.             else if (getMap().getWildernessLevel() > 34) {
  101.                 log("getting lured but I'm smart --> Walking to Lower wilderness Level");
  102.                 getWalking().webWalk(new Area[] { wildy });
  103.                 getEquipment().interactWithNameThatContains("Edgeville", "Amulet of glory");
  104.             }
  105.             else if (getSettings().getRunEnergy() > 30 && !getSettings().isRunning()) {
  106.                 getSettings().setRunning(true);
  107.                 Sleep.sleepUntil(getSettings().isRunning(), 3000);
  108.             }
  109.             else if (finishedLootingRun() || !doneBanking()) {
  110.                 bank();
  111.             }
  112.             else if (canCollect()) {
  113.                 lootItems();
  114.                
  115.                
  116.             }
  117.             else {
  118.                 myWalker.moveToWild();
  119.             }
  120.         }
  121.         catch (Exception e) {
  122.             log(e.toString()+ "<- Error");
  123.         }
  124.         return random(200, 500);
  125.     }
  126.    
  127.     private void bank() throws InterruptedException {
  128.         log("trying to bank");
  129.         if (!Banks.EDGEVILLE.contains(myPosition())) {
  130.             log("Walker walking to bank");
  131.             getEquipment().interactWithNameThatContains("Edgeville", "Amulet of glory");
  132.             myWalker.moveToBank();
  133.         }
  134.         else if (!getBank().isOpen()) {
  135.             log("Successfull walked to bank");
  136.             final boolean success = getBank().open();
  137.             Sleep.sleepUntil(success, 3000);
  138.         }
  139.         else {
  140.             log("Deposit all in bank");
  141.             arrowsCollected += getInventory().getAmount(new String[] { "Adamant arrow" });
  142.             lobstersCollected += getInventory().getAmount(new String[] { "Lobster" });
  143.             swordfishCollected += getInventory().getAmount(new String[] { "Swordfish" });
  144.             anchoviesCollected += getInventory().getAmount(new String[] { "Anchovy pizza" });
  145.             final long currtotal = CalculateInventoryPrice();
  146.             GpGained += currtotal;
  147.             final boolean success2 = getBank().depositAll();
  148.             Sleep.sleepUntil(success2, 3000);
  149.         }
  150.     }
  151.    
  152.     private final String[] lootList = { "Coins" };
  153.     private final int MINIMUM_VALUE = 800;
  154.  
  155.     private boolean loot(List<GroundItem> loot) {
  156.         for (GroundItem item : loot) {
  157.             if (!takeItem(item)) {
  158.                 return false;
  159.             }
  160.         }
  161.         return true;
  162.     }
  163.  
  164.     private boolean takeItem(GroundItem item) {
  165.         if (item != null && item.exists()) {
  166.             if (item.interact("Take")) {
  167.                 //SLEEP
  168.             }
  169.             return false;
  170.         }
  171.         return true;
  172.     }
  173.  
  174.  
  175.     private List<GroundItem> getLoot() {
  176.         List<GroundItem> items = getGroundItems().getAll();
  177.         return items.stream().filter(this::isLoot).collect(Collectors.toList());
  178.     }
  179.  
  180.     private boolean isLoot(GroundItem item) {
  181.         String name = item.getName();
  182.         if (Arrays.asList(lootList).stream().anyMatch(name::equals)) {
  183.             System.out.print(name);
  184.             int price = getPrice(item);
  185.             if (price >= MINIMUM_VALUE) {
  186.                 System.out.print(price);
  187.                 return true;
  188.             }
  189.         }
  190.         return false;
  191.     }
  192.    
  193.     private void lootItems() {
  194.     List<GroundItem> items = getLoot();
  195.     if (items.size() > 0) {
  196.         if (loot(items)) {
  197.             //SLEEP
  198.             }
  199.         }
  200.     }
  201.    
  202.     private int getPrice(GroundItem item) {
  203.         if (item != null) {
  204.             ItemDefinition definition = item.getDefinition();
  205.             int id = definition.isNoted() ? definition.getUnnotedId() : item.getId();
  206.             int quantity = item.getAmount();
  207.             int price = getGrandExchange().getOverallPrice(id);
  208.             log(price);
  209.             return price == 1 ? 1 : quantity * price;
  210.  
  211.         }
  212.         return 1;
  213.     }
  214.    
  215.  
  216.     private void lootItem(final GroundItem item, final String itemName) {
  217.         try {
  218.  
  219.             //int val = PriceLookup.lookupValue(item.getDefinition().getUnnotedId(), item.getAmount());
  220.             int val = getGrandExchange().getOverallPrice(item.getId() * item.getAmount());
  221.             if (item != null && val >= 800 &&  item.interact(new String[] { "Take" }) ) {
  222.                 log("Item looted: " + item.getName() + "(" + item.getAmount() + ")" + " Price: " + val);
  223.                 //SLEEP
  224.                 new ConditionalSleep(350, 1100) {
  225.                    
  226.                     @Override
  227.                     public boolean condition() {
  228.                         return !item.exists();
  229.                     }
  230.                 }.sleep(); 
  231.             }
  232.                /// if (item != null && item.exists( ) && val >= 5000 && item.hasAction(new String[] { "Take" }) ) {
  233.              ///    log("after taking over 5k" + item.getAmount()+ "" ) ;
  234.              ///    
  235.  
  236.           ///  }                  
  237.         }
  238.             catch (Exception e) {
  239.                 this.log("Exception " + item.getName() + " e : "+ e);
  240.             }
  241.     }
  242.    
  243.    
  244.     private void lootItems2() {
  245.         try {
  246.         final GroundItem RuneScimitar = (GroundItem)getGroundItems().closest(new String[] { "Rune scimitar" });
  247.         final GroundItem Rune2h = (GroundItem)getGroundItems().closest(new String[] { "Rune 2h sword" });
  248.         final GroundItem RuneBattleaxe = (GroundItem)getGroundItems().closest(new String[] { "Rune battleaxe" });
  249.         final GroundItem adamantArrow = (GroundItem)getGroundItems().closest(new String[] { "Adamant arrow" });
  250.         final GroundItem anchovy = (GroundItem)getGroundItems().closest(new String[] { "Anchovy pizza" });
  251.         final GroundItem swordfish = (GroundItem)getGroundItems().closest(new String[] { "Swordfish" });
  252.         final GroundItem lobster = (GroundItem)getGroundItems().closest(new String[] { "Lobster" });
  253.  
  254.         final GroundItem loot = getGroundItems().closest(groundItems.getAll());
  255.        
  256.          
  257.         if (loot != null) {
  258.          lootItem(loot, "loot");  
  259.         }
  260.  
  261.         if (Rune2h != null) {
  262.             log("Gonna grab Rune 2h");
  263.             lootItem(Rune2h, "Adamant arrow");
  264.         }
  265.         else if (RuneScimitar != null) {
  266.             log("Gonna Rune battleaxe");
  267.             lootItem(RuneBattleaxe, "Rune battleaxe");
  268.         }
  269.         else if (adamantArrow != null) {
  270.             lootItem(adamantArrow, "Adamant arrow");
  271.         }
  272.         else if (RuneBattleaxe != null) {
  273.             log("Gonna Rune battleaxe");
  274.             lootItem(RuneBattleaxe, "Rune battleaxe");
  275.         }
  276.         else if (lobster != null) {
  277.             lootItem(lobster, "Lobster");
  278.         }
  279.         else if (swordfish != null) {
  280.             lootItem(swordfish, "Swordfish");
  281.         }
  282.         else if (anchovy != null) {
  283.             log("Gonna grab anchovies");
  284.             lootItem(anchovy, "Swordfish");
  285.         }  
  286.         }
  287.         catch (Exception e) {
  288.             log("Exception t "+ e);
  289.         }
  290.        
  291.     }
  292.    
  293.     private boolean doneBanking() {
  294.         return getInventory().isEmpty() || myPlayer().getPosition().getY() > 3520;
  295.     }
  296.    
  297.    
  298.     private boolean canCollect() {
  299.         return getMap().getWildernessLevel() >= 1;
  300.     }
  301.    
  302.     private boolean isUnderAttack() {
  303.         return myPlayer().isUnderAttack();
  304.     }
  305.    
  306.     private boolean finishedLootingRun() {
  307.         return getInventory().isFull();
  308.     }
  309.    
  310.     private long CalculateInventoryPrice() {
  311.         final long totalAddy = addyArrowsPrice * getInventory().getAmount(new String[] { "Adamant arrow" });
  312.         final long totalLobster = lobsterPrice * getInventory().getAmount(new String[] { "Lobster" });
  313.         final long totalSwordies = swordfishPrice * getInventory().getAmount(new String[] { "Swordfish" });
  314.         final long totalAnchovy = anchovyPrice * getInventory().getAmount(new String[] { "Anchovy pizza" });
  315.         final long totalPrice = totalAnchovy + totalSwordies + totalAddy + totalLobster;
  316.         return totalPrice;
  317.     }
  318.    
  319.     public void onPaint(final Graphics2D g) {
  320.         final long timeElapsed = System.currentTimeMillis() - this.startTime;
  321.     //    final long ProfitPerHour = Math.round(this.GpGained * 1.0 / timeElapsed * 1.0 * 3600000.0);
  322.         final Point mP = this.getMouse().getPosition();
  323.         g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5);
  324.         g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5);
  325.         g.setColor(new Color(0, 0, 0, 150));
  326.         g.fillRect(0, 230, 516, 118);
  327.         g.setColor(new Color(244, 249, 184, 250));
  328.         g.drawString("Runtime: " + this.formatTime(timeElapsed), 40, 250);
  329.         g.drawString("Total Profit" + GpGained, 40, 270);
  330.      //   g.drawString("Gp/H: " + ProfitPerHour, 40, 290);
  331.        // g.drawString("Adamant Arrows: " + this.arrowsCollected, 260, 250);
  332.         //g.drawString("Lobsters: " + this.lobstersCollected, 260, 270);
  333.         //g.drawString("Swordfish: " + this.swordfishCollected, 260, 290);
  334.        // g.drawString("Anchovy Pizzas: " + this.anchoviesCollected, 260, 310);
  335.     }
  336.    
  337.     public final String formatTime(final long ms) {
  338.         long s = ms / 1000L;
  339.         long m = s / 60L;
  340.         long h = m / 60L;
  341.         final long d = h / 24L;
  342.         s %= 60L;
  343.         m %= 60L;
  344.         h %= 24L;
  345.         return (d > 0L) ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) : ((h > 0L) ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", m, s));
  346.     }
  347.    
  348.     public void onExit() {
  349.         log("exit");
  350.     }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement