Jump to content

EDIT: Think I got it working, Implemented use of stamina potions into Explvs' agility script


mariokiller64

Recommended Posts

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;
        }
    }
}
Edited by mariokiller64
Link to comment
Share on other sites

7 minutes ago, Medusa said:

This sounds like a porn title...

Anyways, just add a check to see if player should drink a pot. It should preferably be above any of the "run" code.

 

EDIT: You already have that. What seems to be the issue?

He wasn't using the potions. And I think I accidentally wrote it so it has to have 1-4 stamina potions in the inventory itself before being able to do anything because I have no idea what I'm doing lol.

Link to comment
Share on other sites

3 minutes ago, mariokiller64 said:

He wasn't using the potions. And I think I accidentally wrote it so it has to have 1-4 stamina potions in the inventory itself before being able to do anything because I have no idea what I'm doing lol.

Oh yea. You made it so you need all 1-4 ye.

Will update this post with useful stuff in a bit.

 

EDIT:

Pretty sure you can use this

final Filter<Item> POTION_FILTER = item -> item.getName().matches("Stamina potion \\(\\d\\)");

 

Edited by Medusa
  • Like 1
Link to comment
Share on other sites

1 hour ago, Medusa said:

Oh yea. You made it so you need all 1-4 ye.

Will update this post with useful stuff in a bit.

 

EDIT:

Pretty sure you can use this


final Filter<Item> POTION_FILTER = item -> item.getName().matches("Stamina potion \\(\\d\\)");

 

Not sure why but he isn't drinking any stamina potions still. He didn't deposit them at all at least, ha.

Don't know if the \\(\\d\\) did anything as it is still in the same colored text

 

Started working when I redid it a bit cleaner. Haven't done this in a while lol, thanks for the help though!

Edited by mariokiller64
Link to comment
Share on other sites

On 11/16/2019 at 8:08 AM, mariokiller64 said:

Not sure why but he isn't drinking any stamina potions still. He didn't deposit them at all at least, ha.

Don't know if the \\(\\d\\) did anything as it is still in the same colored text

 

Started working when I redid it a bit cleaner. Haven't done this in a while lol, thanks for the help though!

\\(\\d\\)

That should filter to work with any dosage amount.

That's the code I use for my amulet of glory handlers etc.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...