Add base script

This commit is contained in:
tsb1995 2020-05-03 12:21:09 -07:00
parent 33818b88c9
commit 4b81c9d19f
21 changed files with 239 additions and 0 deletions

3
.gitignore.txt Normal file
View File

@ -0,0 +1,3 @@
/.idea/
/out/
.CowKiller2.iml

8
.idea/.gitignore vendored Normal file
View File

@ -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/

View File

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="CowKiller2">
<output-path>$USER_HOME$/OSBot/Scripts</output-path>
<root id="archive" name="CowKiller2.jar">
<element id="module-output" name="CowKiller2" />
</root>
</artifact>
</component>

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="OSBot 2.5.80">
<CLASSES>
<root url="jar://$USER_HOME$/Desktop/OSBot 2.5.80.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/CowKiller2.iml" filepath="$PROJECT_DIR$/CowKiller2.iml" />
</modules>
</component>
</project>

12
CowKiller2.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="OSBot 2.5.80" level="project" />
</component>
</module>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

72
src/CowKiller2Main.java Normal file
View File

@ -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;
}
}
}

5
src/data/State.java Normal file
View File

@ -0,0 +1,5 @@
package data;
public enum State {
NAV_COWS, KILL_COWS, BANK_COWHIDES
}

View File

@ -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();
}
}
}

35
src/tasks/KillCows.java Normal file
View File

@ -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<NPC>() {
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);
}
}
}

20
src/tasks/NavCows.java Normal file
View File

@ -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);
}
}

24
src/util/Sleep.java Normal file
View File

@ -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();
}
}