Think I got it working, Implemented use of Stamina potions into Explvs' agility script if anyone wants it. Just have them in your inventory and you're all good to go.
Still also trying to figure out how to get them to be withdrawn from the bank and depositing vials after a certain amount
package activities.skills.agility;
import activities.activity.Activity;
import activities.activity.ActivityType;
import activities.banking.Banking;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.event.WalkingEvent;
import org.osbot.rs07.event.WebWalkEvent;
import org.osbot.rs07.utility.Condition;
import util.Executable;
import util.Sleep;
import java.util.Arrays;
import java.util.LinkedList;
public class AgilityActivity extends Activity {
private final AgilityCourse agilityCourse;
private Executable bankNode;
private LinkedList<CoursePart> course;
private int enableRunEnergyAmount;
private static final String[] ENERGY = {
"Stamina potion(4)",
"Stamina potion(3)",
"Stamina potion(2)",
"Stamina potion(1)",};
private static final String[] BANK = {
"Vial",
"Mark of grace",
"Stamina potion(4)",
"Stamina potion(3)",
"Stamina potion(2)",
"Stamina potion(1)",};
public AgilityActivity(final AgilityCourse agilityCourse) {
super(ActivityType.AGILITY);
this.agilityCourse = agilityCourse;
}
@Override
public void onStart() {
if (getInventory().contains(ENERGY) && !isStaminaPotionActive() && getSettings().getRunEnergy() < random(40, 60)) {
getInventory().interact("Drink", ENERGY);
}
bankNode = new AgilityBank();
bankNode.exchangeContext(getBot());
getSettings().setRunning(true);
enableRunEnergyAmount = random(20, 50);
}
@Override
public boolean canExit() {
return course == null || course.peek() == agilityCourse.COURSE_PARTS[0];
}
public boolean isStaminaPotionActive() {
return getConfigs().get(1575) > 0;
}
@Override
public void runActivity() throws InterruptedException {
if (getInventory().isEmptyExcept(BANK) || myPosition().getZ() > 0) {
if (getBank() != null && getBank().isOpen()) {
getBank().close();
return;
}
if (getInventory().contains(ENERGY) && !isStaminaPotionActive() && getSettings().getRunEnergy() < random(40, 60)) {
getInventory().interact("Drink", ENERGY);
getSettings().setRunning(true);
}
if (!getSettings().isRunning() && getSettings().getRunEnergy() >= enableRunEnergyAmount) {
getSettings().setRunning(true);
enableRunEnergyAmount = random(20, 50);
}
GroundItem markOfGrace = getGrace();
if (markOfGrace != null && (getInventory().contains("Mark of grace") || !getInventory().isFull())) {
takeItem(markOfGrace);
return;
}
if (course == null || course.isEmpty() || !course.peek().activeArea.contains(myPosition())) {
course = getCourse();
}
if (course.peek() == agilityCourse.COURSE_PARTS[0] && !agilityCourse.COURSE_PARTS[0].activeArea.contains(myPosition())) {
if (agilityCourse != AgilityCourse.GNOME_STRONGHOLD) {
getWalking().webWalk(agilityCourse.COURSE_PARTS[0].activeArea);
} else if (talkingToFemi()) {
getDialogues().completeDialogue("Okay then.");
} else if (!myPlayer().isMoving() && !myPlayer().isAnimating()) {
// The player may need to complete a dialog before being able to access the Gnome Stronghold
WebWalkEvent webWalkEvent = new WebWalkEvent(agilityCourse.COURSE_PARTS[0].activeArea);
webWalkEvent.setBreakCondition(new Condition() {
@Override
public boolean evaluate() {
return talkingToFemi();
}
});
execute(webWalkEvent);
}
return;
}
RS2Object obstacle = getObstacle();
if ((obstacle == null || getMap().distance(obstacle) > 10) && course.peek().pathToArea != null) {
WalkingEvent walkingEvent = new WalkingEvent();
walkingEvent.setPath(new LinkedList<>(Arrays.asList(course.peek().pathToArea)));
walkingEvent.setMiniMapDistanceThreshold(10);
walkingEvent.setBreakCondition(new Condition() {
@Override
public boolean evaluate() {
return getObstacle() != null && getMap().distance(getObstacle()) < random(10,12);
}
});
execute(walkingEvent);
if (walkingEvent.hasFailed()) {
return;
}
}
if (obstacle != null) {
if (getCamera().toPosition(obstacle.getPosition()) && obstacle.interact(course.peek().obstacle.ACTION)) {
long agilityXP = getSkills().getExperience(Skill.AGILITY);
int zPos = myPosition().getZ();
Sleep.sleepUntil(() -> getSkills().getExperience(Skill.AGILITY) > agilityXP || (zPos > 0 && myPosition().getZ() == 0), random(12_00, 13_000), random(200, 1200));
if (!course.peek().activeArea.contains(myPosition())) {
course.add(course.removeFirst());
}
if (getInventory().contains(ENERGY) && !isStaminaPotionActive() && getSettings().getRunEnergy() <= 1) {
getInventory().interact("Drink", ENERGY);
getSettings().setRunning(true);
}
} else {
log("Interaction got stuck, moving camera");
getCamera().moveYaw(getCamera().getYawAngle() - random(15, 60));
}
} else {
log("Could not find the next obstacle");
}
} else {
bankNode.run();
}
}
private boolean talkingToFemi() {
return getDialogues().inDialogue() && getNpcs().closest("Femi") != null;
}
private RS2Object getObstacle() {
return getObjects().closest(obj -> {
if (!obj.getName().equals(course.peek().obstacle.NAME)) {
return false;
}
if (!obj.hasAction(course.peek().obstacle.ACTION)) {
return false;
}
if (course.peek().obstaclePosition != null && !obj.getPosition().equals(course.peek().obstaclePosition)) {
return false;
}
return true;
});
}
private GroundItem getGrace() {
return getGroundItems().closest(item -> item.getName().equals("Mark of grace") && getMap().canReach(item.getPosition()));
}
public boolean takeItem(final GroundItem groundItem) {
long invAmount = getInventory().getAmount(groundItem.getName());
if (groundItem.interact("Take")) {
Sleep.sleepUntil(() -> getInventory().getAmount(groundItem.getName()) > invAmount || !groundItem.exists(), random(1000,4500));
}
return getInventory().getAmount(groundItem.getName()) > invAmount;
}
private LinkedList<CoursePart> getCourse() {
LinkedList<CoursePart> course = new LinkedList<>();
for (int i = 0; i < agilityCourse.COURSE_PARTS.length; i++) {
if (agilityCourse.COURSE_PARTS[i].activeArea.contains(myPosition())) {
course.add(agilityCourse.COURSE_PARTS[i]);
course.addAll(Arrays.asList(agilityCourse.COURSE_PARTS).subList(i + 1, agilityCourse.COURSE_PARTS.length));
course.addAll(Arrays.asList(agilityCourse.COURSE_PARTS).subList(0, i));
break;
}
}
if (course.isEmpty()) {
return new LinkedList<>(Arrays.asList(agilityCourse.COURSE_PARTS));
}
return course;
}
@Override
public AgilityActivity copy() {
return new AgilityActivity(agilityCourse);
}
private class AgilityBank extends Banking {
@Override
public boolean bank() {
if (getInventory().contains(ENERGY) && !isStaminaPotionActive() && getSettings().getRunEnergy() < random(40, 60)) {
getInventory().interact("Drink", ENERGY);
getSettings().setRunning(true);
}
getBank().depositAllExcept(BANK);
return true;
}
}
}