diff --git a/.gitignore.txt b/.gitignore.txt new file mode 100644 index 0000000..aad7015 --- /dev/null +++ b/.gitignore.txt @@ -0,0 +1,3 @@ +/.idea/ +/out/ +.CowKiller2.iml \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/artifacts/CowKiller2.xml b/.idea/artifacts/CowKiller2.xml new file mode 100644 index 0000000..fca03bd --- /dev/null +++ b/.idea/artifacts/CowKiller2.xml @@ -0,0 +1,8 @@ + + + $USER_HOME$/OSBot/Scripts + + + + + \ No newline at end of file diff --git a/.idea/libraries/OSBot_2_5_80.xml b/.idea/libraries/OSBot_2_5_80.xml new file mode 100644 index 0000000..6bcc02f --- /dev/null +++ b/.idea/libraries/OSBot_2_5_80.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..99e6808 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CowKiller2.iml b/CowKiller2.iml new file mode 100644 index 0000000..f3a85af --- /dev/null +++ b/CowKiller2.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/CowKiller2/CowKiller2Main$1.class b/out/production/CowKiller2/CowKiller2Main$1.class new file mode 100644 index 0000000..75aa56d Binary files /dev/null and b/out/production/CowKiller2/CowKiller2Main$1.class differ diff --git a/out/production/CowKiller2/CowKiller2Main.class b/out/production/CowKiller2/CowKiller2Main.class new file mode 100644 index 0000000..e5acc13 Binary files /dev/null and b/out/production/CowKiller2/CowKiller2Main.class differ diff --git a/out/production/CowKiller2/data/State.class b/out/production/CowKiller2/data/State.class new file mode 100644 index 0000000..c3cd1d2 Binary files /dev/null and b/out/production/CowKiller2/data/State.class differ diff --git a/out/production/CowKiller2/tasks/BankCowhides.class b/out/production/CowKiller2/tasks/BankCowhides.class new file mode 100644 index 0000000..1eda2af Binary files /dev/null and b/out/production/CowKiller2/tasks/BankCowhides.class differ diff --git a/out/production/CowKiller2/tasks/KillCows$1.class b/out/production/CowKiller2/tasks/KillCows$1.class new file mode 100644 index 0000000..c8a84dd Binary files /dev/null and b/out/production/CowKiller2/tasks/KillCows$1.class differ diff --git a/out/production/CowKiller2/tasks/KillCows.class b/out/production/CowKiller2/tasks/KillCows.class new file mode 100644 index 0000000..4d91ddf Binary files /dev/null and b/out/production/CowKiller2/tasks/KillCows.class differ diff --git a/out/production/CowKiller2/tasks/NavCows.class b/out/production/CowKiller2/tasks/NavCows.class new file mode 100644 index 0000000..5fe3509 Binary files /dev/null and b/out/production/CowKiller2/tasks/NavCows.class differ diff --git a/out/production/CowKiller2/util/Sleep.class b/out/production/CowKiller2/util/Sleep.class new file mode 100644 index 0000000..38118cd Binary files /dev/null and b/out/production/CowKiller2/util/Sleep.class differ diff --git a/src/CowKiller2Main.java b/src/CowKiller2Main.java new file mode 100644 index 0000000..85ae6ce --- /dev/null +++ b/src/CowKiller2Main.java @@ -0,0 +1,72 @@ +import data.State; +import org.osbot.rs07.api.map.Area; +import org.osbot.rs07.script.Script; + +import org.osbot.rs07.script.ScriptManifest; +import tasks.BankCowhides; +import tasks.KillCows; +import tasks.NavCows; + +import java.awt.*; + +@ScriptManifest(name = "CowKiller2", author = "Tsb", version = 1.0, info = "", logo = "") +public final class CowKiller2Main extends Script { + + private String status = ""; + private final Area COW_AREA = new Area(3193, 3281, 3211, 3302); + + // Initialize task classes + private final NavCows navCows = new NavCows(); + private final KillCows killCows = new KillCows(); + private final BankCowhides bankCowhides = new BankCowhides(); + + @Override + public void onStart() { + // Exchange context to allow OSBot methods in task classes + navCows.exchangeContext(getBot()); + killCows.exchangeContext(getBot()); + bankCowhides.exchangeContext(getBot()); + + } + + @Override + public void onExit() { + //Code here will execute after the script ends + } + + @Override + public int onLoop() throws InterruptedException { + // Grab current state and convert to string + final State state = getState(); + status = state.toString(); + + // Choose task based on state + switch (state) { + case NAV_COWS: + navCows.NavCows(); + case KILL_COWS: + killCows.KillCows(); + case BANK_COWHIDES: + bankCowhides.BankCowhides(); + } + // end current loop and wait between 250 and 400 miliseconds before next loop + return random(250, 400); + } + + @Override + public void onPaint(Graphics2D g) { + //This is where you will put your code for paint(s) + } + + private State getState() { + + // Return proper state based on inventory and position + if (getInventory().isFull()) { + return State.BANK_COWHIDES; + } else if (!COW_AREA.contains(myPosition())) { + return State.NAV_COWS; + } else { + return State.KILL_COWS; + } + } +} \ No newline at end of file diff --git a/src/data/State.java b/src/data/State.java new file mode 100644 index 0000000..d7b5353 --- /dev/null +++ b/src/data/State.java @@ -0,0 +1,5 @@ +package data; + +public enum State { + NAV_COWS, KILL_COWS, BANK_COWHIDES +} diff --git a/src/tasks/BankCowhides.java b/src/tasks/BankCowhides.java new file mode 100644 index 0000000..4d9600a --- /dev/null +++ b/src/tasks/BankCowhides.java @@ -0,0 +1,29 @@ +package tasks; + +import org.osbot.rs07.api.map.constants.Banks; +import org.osbot.rs07.event.WebWalkEvent; +import org.osbot.rs07.event.webwalk.PathPreferenceProfile; +import org.osbot.rs07.script.MethodProvider; + +public class BankCowhides extends MethodProvider { + + public final void BankCowhides() throws InterruptedException { + // If not at bank and full inventory, got to the bank + if (!Banks.LUMBRIDGE_UPPER.contains(myPosition()) && getInventory().isFull()) { + WebWalkEvent webEvent = new WebWalkEvent(Banks.LUMBRIDGE_UPPER); + webEvent.useSimplePath(); + PathPreferenceProfile ppp = new PathPreferenceProfile(); + ppp.setAllowTeleports(false); + webEvent.setPathPreferenceProfile(ppp); + execute(webEvent); + sleep(300); + } else { + // if at bank, open bank and deposit all + if (!getBank().isOpen()) { + getBank().open(); + sleep(300); + } + getBank().depositAll(); + } + } +} \ No newline at end of file diff --git a/src/tasks/KillCows.java b/src/tasks/KillCows.java new file mode 100644 index 0000000..649f24a --- /dev/null +++ b/src/tasks/KillCows.java @@ -0,0 +1,35 @@ +package tasks; + +import org.osbot.rs07.api.filter.Filter; +import org.osbot.rs07.api.model.GroundItem; +import org.osbot.rs07.api.model.NPC; +import org.osbot.rs07.script.MethodProvider; +import util.Sleep; + +public class KillCows extends MethodProvider { + public final void KillCows() throws InterruptedException { + // Toggle run only if above 40 energy + if (getSettings().getRunEnergy() >40) { + getSettings().setRunning(true); + } + + // Grab cows not in combat and not in dying state + NPC cow = getNpcs().closest(new Filter() { + public boolean match(NPC npc) { + return npc != null && npc.getName().equals("Cow") && !npc.isUnderAttack() && npc.getHealthPercent() > 0; + } + }); + + // Check for cowhides and grab with proper conditional sleep + GroundItem cowhide = getGroundItems().closest("Cowhide"); + if (myPlayer().isUnderAttack()) { + Sleep.sleepUntil(() -> myPlayer().isAnimating() || !myPlayer().isUnderAttack(), 5000); + }else if (cowhide != null && cowhide.interact("take")) { + Sleep.sleepUntil(() -> myPlayer().isAnimating() || !cowhide.exists(), 5000); + } else if (cow != null && cow.interact("Attack")) { + Sleep.sleepUntil(() -> myPlayer().isAnimating() || !cow.exists(), 5000); + } else { + sleep(500); + } + } +} \ No newline at end of file diff --git a/src/tasks/NavCows.java b/src/tasks/NavCows.java new file mode 100644 index 0000000..6e62eb8 --- /dev/null +++ b/src/tasks/NavCows.java @@ -0,0 +1,20 @@ +package tasks; + +import org.osbot.rs07.api.map.Position; +import org.osbot.rs07.event.WebWalkEvent; +import org.osbot.rs07.event.webwalk.PathPreferenceProfile; +import org.osbot.rs07.script.MethodProvider; + +public class NavCows extends MethodProvider { + // Nav to cow position + + final Position COW_POSITION = new Position(3200, 3290, 0); + + public final void NavCows() throws InterruptedException { + WebWalkEvent webEvent = new WebWalkEvent(COW_POSITION); + webEvent.useSimplePath(); + PathPreferenceProfile ppp = new PathPreferenceProfile(); + webEvent.setPathPreferenceProfile(ppp); + execute(webEvent); + } +} diff --git a/src/util/Sleep.java b/src/util/Sleep.java new file mode 100644 index 0000000..291d521 --- /dev/null +++ b/src/util/Sleep.java @@ -0,0 +1,24 @@ +package util; + +import org.osbot.rs07.utility.ConditionalSleep; + +import java.util.function.BooleanSupplier; + +public final class Sleep extends ConditionalSleep { + + private final BooleanSupplier condition; + + public Sleep(final BooleanSupplier condition, final int timeout) { + super(timeout); + this.condition = condition; + } + + @Override + public final boolean condition() throws InterruptedException { + return condition.getAsBoolean(); + } + + public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) { + return new Sleep(condition, timeout).sleep(); + } +} \ No newline at end of file