Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com;
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.Point;
- import java.awt.image.BufferedImage;
- import java.lang.reflect.InvocationTargetException;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- import javax.swing.SwingUtilities;
- import org.osbot.rs07.api.def.ItemDefinition;
- import org.osbot.rs07.api.map.Area;
- import org.osbot.rs07.api.map.constants.Banks;
- import org.osbot.rs07.api.model.Entity;
- import org.osbot.rs07.api.model.GroundItem;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import org.osbot.rs07.utility.ConditionalSleep;
- import com.gui.Gui;
- import com.gui.Paint;
- @ScriptManifest(name = "Nando's fucking looter v2", author = "Nando", info = "loots", version = 0.1, logo = "")
- public class Main extends Script {
- Gui ui;
- Paint paint;
- private long startTime;
- private long GpGained;
- Area wildy;
- long arrowsCollected;
- long lobstersCollected;
- long swordfishCollected;
- long anchoviesCollected;
- private Walker myWalker;
- BufferedImage background;
- int anchovyPrice;
- int swordfishPrice;
- int addyArrowsPrice;
- int lobsterPrice;
- long inventorycashlimit;
- private Area Lumbridge;
- private Gui gui;
- GroundItem item;
- public Main() {
- wildy = new Area(3239, 10158, 3268, 10137);
- GpGained = 0L;
- arrowsCollected = 0L;
- lobstersCollected = 0L;
- swordfishCollected = 0L;
- anchoviesCollected = 0L;
- inventorycashlimit = 250000;
- }
- public void onStart() throws InterruptedException {
- // Lumbridge = new Area(3200, 3210, 3230, 3230);
- gui = new Gui();
- myWalker = new Walker();
- this.Lumbridge = new Area(3200, 3210, 3230, 3230);
- this.log("HI");
- this.startTime = System.currentTimeMillis();
- this.myWalker.exchangeContext(this.getBot());
- try {
- SwingUtilities.invokeAndWait(() -> {
- this.gui = new Gui();
- this.gui.open();
- });
- }
- catch (InterruptedException | InvocationTargetException e) {
- e.printStackTrace();
- this.stop();
- return;
- }
- if (!this.gui.isStarted()) {
- this.stop();
- return;
- }
- this.inventorycashlimit = this.gui.returnValue();
- }
- public final int onLoop() throws InterruptedException {
- try {
- if (Lumbridge.contains((Entity)myPlayer())) {
- log("WaLKING");
- getWalking().webWalk(new Area[] { Banks.EDGEVILLE });
- }
- else if (isUnderAttack()) {
- bank();
- /// log("getting lured but I'm smart --> Walking to Lower wilderness Level to tele");
- //getWalking().webWalk(new Area[] { wildy });
- getEquipment().interactWithNameThatContains("Edgeville", "Amulet of glory");
- }
- else if (getMap().getWildernessLevel() > 34) {
- log("getting lured but I'm smart --> Walking to Lower wilderness Level");
- getWalking().webWalk(new Area[] { wildy });
- getEquipment().interactWithNameThatContains("Edgeville", "Amulet of glory");
- }
- else if (getSettings().getRunEnergy() > 30 && !getSettings().isRunning()) {
- getSettings().setRunning(true);
- Sleep.sleepUntil(getSettings().isRunning(), 3000);
- }
- else if (finishedLootingRun() || !doneBanking()) {
- bank();
- }
- else if (canCollect()) {
- lootItems();
- }
- else {
- myWalker.moveToWild();
- }
- }
- catch (Exception e) {
- log(e.toString()+ "<- Error");
- }
- return random(200, 500);
- }
- private void bank() throws InterruptedException {
- log("trying to bank");
- if (!Banks.EDGEVILLE.contains(myPosition())) {
- log("Walker walking to bank");
- getEquipment().interactWithNameThatContains("Edgeville", "Amulet of glory");
- myWalker.moveToBank();
- }
- else if (!getBank().isOpen()) {
- log("Successfull walked to bank");
- final boolean success = getBank().open();
- Sleep.sleepUntil(success, 3000);
- }
- else {
- log("Deposit all in bank");
- arrowsCollected += getInventory().getAmount(new String[] { "Adamant arrow" });
- lobstersCollected += getInventory().getAmount(new String[] { "Lobster" });
- swordfishCollected += getInventory().getAmount(new String[] { "Swordfish" });
- anchoviesCollected += getInventory().getAmount(new String[] { "Anchovy pizza" });
- final long currtotal = CalculateInventoryPrice();
- GpGained += currtotal;
- final boolean success2 = getBank().depositAll();
- Sleep.sleepUntil(success2, 3000);
- }
- }
- private final String[] lootList = { "Coins" };
- private final int MINIMUM_VALUE = 800;
- private boolean loot(List<GroundItem> loot) {
- for (GroundItem item : loot) {
- if (!takeItem(item)) {
- return false;
- }
- }
- return true;
- }
- private boolean takeItem(GroundItem item) {
- if (item != null && item.exists()) {
- if (item.interact("Take")) {
- //SLEEP
- }
- return false;
- }
- return true;
- }
- private List<GroundItem> getLoot() {
- List<GroundItem> items = getGroundItems().getAll();
- return items.stream().filter(this::isLoot).collect(Collectors.toList());
- }
- private boolean isLoot(GroundItem item) {
- String name = item.getName();
- if (Arrays.asList(lootList).stream().anyMatch(name::equals)) {
- System.out.print(name);
- int price = getPrice(item);
- if (price >= MINIMUM_VALUE) {
- System.out.print(price);
- return true;
- }
- }
- return false;
- }
- private void lootItems() {
- List<GroundItem> items = getLoot();
- if (items.size() > 0) {
- if (loot(items)) {
- //SLEEP
- }
- }
- }
- private int getPrice(GroundItem item) {
- if (item != null) {
- ItemDefinition definition = item.getDefinition();
- int id = definition.isNoted() ? definition.getUnnotedId() : item.getId();
- int quantity = item.getAmount();
- int price = getGrandExchange().getOverallPrice(id);
- log(price);
- return price == 1 ? 1 : quantity * price;
- }
- return 1;
- }
- private void lootItem(final GroundItem item, final String itemName) {
- try {
- //int val = PriceLookup.lookupValue(item.getDefinition().getUnnotedId(), item.getAmount());
- int val = getGrandExchange().getOverallPrice(item.getId() * item.getAmount());
- if (item != null && val >= 800 && item.interact(new String[] { "Take" }) ) {
- log("Item looted: " + item.getName() + "(" + item.getAmount() + ")" + " Price: " + val);
- //SLEEP
- new ConditionalSleep(350, 1100) {
- @Override
- public boolean condition() {
- return !item.exists();
- }
- }.sleep();
- }
- /// if (item != null && item.exists( ) && val >= 5000 && item.hasAction(new String[] { "Take" }) ) {
- /// log("after taking over 5k" + item.getAmount()+ "" ) ;
- ///
- /// }
- }
- catch (Exception e) {
- this.log("Exception " + item.getName() + " e : "+ e);
- }
- }
- private void lootItems2() {
- try {
- final GroundItem RuneScimitar = (GroundItem)getGroundItems().closest(new String[] { "Rune scimitar" });
- final GroundItem Rune2h = (GroundItem)getGroundItems().closest(new String[] { "Rune 2h sword" });
- final GroundItem RuneBattleaxe = (GroundItem)getGroundItems().closest(new String[] { "Rune battleaxe" });
- final GroundItem adamantArrow = (GroundItem)getGroundItems().closest(new String[] { "Adamant arrow" });
- final GroundItem anchovy = (GroundItem)getGroundItems().closest(new String[] { "Anchovy pizza" });
- final GroundItem swordfish = (GroundItem)getGroundItems().closest(new String[] { "Swordfish" });
- final GroundItem lobster = (GroundItem)getGroundItems().closest(new String[] { "Lobster" });
- final GroundItem loot = getGroundItems().closest(groundItems.getAll());
- if (loot != null) {
- lootItem(loot, "loot");
- }
- if (Rune2h != null) {
- log("Gonna grab Rune 2h");
- lootItem(Rune2h, "Adamant arrow");
- }
- else if (RuneScimitar != null) {
- log("Gonna Rune battleaxe");
- lootItem(RuneBattleaxe, "Rune battleaxe");
- }
- else if (adamantArrow != null) {
- lootItem(adamantArrow, "Adamant arrow");
- }
- else if (RuneBattleaxe != null) {
- log("Gonna Rune battleaxe");
- lootItem(RuneBattleaxe, "Rune battleaxe");
- }
- else if (lobster != null) {
- lootItem(lobster, "Lobster");
- }
- else if (swordfish != null) {
- lootItem(swordfish, "Swordfish");
- }
- else if (anchovy != null) {
- log("Gonna grab anchovies");
- lootItem(anchovy, "Swordfish");
- }
- }
- catch (Exception e) {
- log("Exception t "+ e);
- }
- }
- private boolean doneBanking() {
- return getInventory().isEmpty() || myPlayer().getPosition().getY() > 3520;
- }
- private boolean canCollect() {
- return getMap().getWildernessLevel() >= 1;
- }
- private boolean isUnderAttack() {
- return myPlayer().isUnderAttack();
- }
- private boolean finishedLootingRun() {
- return getInventory().isFull();
- }
- private long CalculateInventoryPrice() {
- final long totalAddy = addyArrowsPrice * getInventory().getAmount(new String[] { "Adamant arrow" });
- final long totalLobster = lobsterPrice * getInventory().getAmount(new String[] { "Lobster" });
- final long totalSwordies = swordfishPrice * getInventory().getAmount(new String[] { "Swordfish" });
- final long totalAnchovy = anchovyPrice * getInventory().getAmount(new String[] { "Anchovy pizza" });
- final long totalPrice = totalAnchovy + totalSwordies + totalAddy + totalLobster;
- return totalPrice;
- }
- public void onPaint(final Graphics2D g) {
- final long timeElapsed = System.currentTimeMillis() - this.startTime;
- // final long ProfitPerHour = Math.round(this.GpGained * 1.0 / timeElapsed * 1.0 * 3600000.0);
- final Point mP = this.getMouse().getPosition();
- 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);
- g.setColor(new Color(0, 0, 0, 150));
- g.fillRect(0, 230, 516, 118);
- g.setColor(new Color(244, 249, 184, 250));
- g.drawString("Runtime: " + this.formatTime(timeElapsed), 40, 250);
- g.drawString("Total Profit" + GpGained, 40, 270);
- // g.drawString("Gp/H: " + ProfitPerHour, 40, 290);
- // g.drawString("Adamant Arrows: " + this.arrowsCollected, 260, 250);
- //g.drawString("Lobsters: " + this.lobstersCollected, 260, 270);
- //g.drawString("Swordfish: " + this.swordfishCollected, 260, 290);
- // g.drawString("Anchovy Pizzas: " + this.anchoviesCollected, 260, 310);
- }
- public final String formatTime(final long ms) {
- long s = ms / 1000L;
- long m = s / 60L;
- long h = m / 60L;
- final long d = h / 24L;
- s %= 60L;
- m %= 60L;
- h %= 24L;
- 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));
- }
- public void onExit() {
- log("exit");
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement