Jump to content
lebotman

[Open Source] Tutorial Island Script, Need Advice/Help/Tips

Recommended Posts

Hello I'm new to osbot.

I wrote a tutorial island script following this https://github.com/Explv/Tutorial-Island/tree/master/src as a rough example to try and learn.

I'm looking for advice/help/trips on what I can improve upon since I want to get script writer. 

 

TutorialIsland.java


import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.EquipmentSlot;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.api.ui.Spells;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.event.InteractionEvent;
import org.osbot.rs07.event.WalkingEvent;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;


import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

@ScriptManifest(name = "TutorialIsland", version = 1.0, author = "lebotman", logo = "", info = "Does tutorial island.")
public class TutorialIsland extends Script{

    private final Position COOK_EXIT_DOOR = new Position(3071,3090,0);
    private final Position SMITH_EXIT_DOOR = new Position(3096, 9503, 0);
    private final Position RAT_RANGE_SPOT = new Position(3111,9518,0);
    private final Position FINANCIAL_ADVISOR_ENTRANCE_DOOR = new Position(3125, 3124, 0);
    private final Position FINANCIAL_ADVISOR_EXIT_DOOR = new Position(3130, 3124, 0);
    private final Position CHURCH_EXIT_DOOR = new Position(3122, 3101, 0);


    private final Area COOK_BUILDING = new Area(3073,3083,3078,3086);
    private final Area QUEST_BUILDING = new Area(3083,3119,3089,3125);
    private final Area SMITH_AREA = new Area(3076,9497,3082,9504);
    private final Area LADDER_AREA = new Area(3108,9523,3114,9529);
    private final Area INSIDE_RAT_CAGE_AREA = new Area(3107,9517,3110,9520);
    private final Area OUTSIDE_RAT_CAGE_AREA = new Area(3111,9516,3113,9521);
    private final Area BANK_AREA = new Area(new int[][]{{3125, 3121}, {3126, 3121}, {3126, 3119}, {3118, 3119}, {3118, 3121}, {3119, 3121}, {3119, 3123}, {3115, 3123}, {3115, 3128}, {3118, 3128}, {3118, 3126}, {3122, 3126}, {3122, 3130}, {3126, 3130}, {3126, 3128}, {3128, 3128}, {3128, 3126}, {3130, 3126}, {3130, 3123}, {3125, 3123}, {3125, 3121}});
    private final Area CHURCH_AREA = new Area(3120, 3103, 3128, 3110);
    private final Area WIZARD_BUILDING = new Area(new int[][]{{3140, 3085}, {3143, 3088}, {3140, 3083}, {3141, 3084}, {3140, 3089}, {3143, 3089}, {3137, 3091}, {3141, 3091}, {3138, 3090}, {3142, 3090}, {3139, 3089}, {3140, 3089}, {3141, 3084}, {3143, 3084}, {3141, 3083}, {3142, 3083}, {3138, 3082}, {3141, 3082}, {3138, 3083}, {3140, 3083}, {3139, 3084}, {3141, 3084}});
    private final Area CHICKEN_AREA = new Area(3139, 3091, 3140, 3090);

    private final List<Position> PATH_TO_GATE = Arrays.asList(new Position(3098,3092,0), new Position(3092,3091,0));
    private final List<Position> PATH_TO_COOK_BUILDING = Arrays.asList(new Position(3087,3091,0), new Position(3083,3086,0), new Position(3080,3083,0));
    private final List<Position> PATH_TO_QUEST_BUILDING = Arrays.asList(new Position(3071, 3090, 0), new Position(3071, 3094, 0), new Position(3071, 3099, 0), new Position(3072, 3103, 0), new Position(3074, 3108, 0), new Position(3076, 3111, 0), new Position(3077, 3115, 0), new Position(3076, 3118, 0), new Position(3076, 3122, 0), new Position(3079, 3125, 0), new Position(3083, 3127, 0), new Position(3086, 3126, 0));
    private final List<Position> PATH_TO_SMITH_AREA = Arrays.asList(new Position(3080, 9518, 0), new Position(3080, 9511, 0), new Position(3080, 9505, 0));
    private final List<Position> PATH_TO_CAVES_GATE = Arrays.asList(new Position(3086, 9505, 0), new Position(3091, 9503, 0));
    private final List<Position> PATH_TO_BANK = Arrays.asList(new Position(3111, 3123, 0), new Position(3114, 3119, 0), new Position(3118, 3116, 0), new Position(3121, 3118, 0));
    private final List<Position> PATH_TO_CHURCH = Arrays.asList(new Position(3131, 3124, 0), new Position(3134, 3121, 0), new Position(3134, 3117, 0), new Position(3132, 3114, 0), new Position(3130, 3111, 0), new Position(3130, 3108, 0), new Position(3129, 3106, 0), new Position(3124,3106,0));
    private final List<Position> PATH_TO_WIZARD_BUILDING = Arrays.asList(new Position(3122, 3101, 0), new Position(3125, 3097, 0), new Position(3127, 3093, 0), new Position(3129, 3088, 0), new Position(3135, 3087, 0), new Position(3141, 3086, 0));

    @Override
    public int onLoop() throws InterruptedException {
        RS2Widget continueWidget = getWidgets().singleFilter(getWidgets().getAll(),widget->widget.isVisible() && (widget.getMessage().contains("Click here to continue") || widget.getMessage().contains("Click to continue")));
        if(continueWidget != null){
            log("pending continue");
            continueWidget.interact();
            Sleep.sleepUntil(()->!continueWidget.isVisible(),1000,500);
            return 0;
        }

        log(getConfigs().get(281));
        switch(getConfigs().get(281)){
            case 0: //character creation
                final RS2Widget baseScreenWidget = getWidgets().getWidgetContainingText("Welcome to Runescape");
                if(baseScreenWidget != null){
                    log("create random character");
                    if(new Random().nextBoolean()) { //new Random().nextBoolean()
                        getWidgets().getWidgetContainingText("Female").interact();
                        sleep(500);
                    }
                    final RS2Widget[] designButtons = getWidgets().getWidgets(baseScreenWidget.getRootId());
                    for(final RS2Widget childWidget : designButtons){
                        if(childWidget != null && (childWidget.getToolTip().contains("Change") || childWidget.getToolTip().contains("Recolour"))){
                            for(int i = 0; i < random(4); i++){
                                childWidget.interact();
                                sleep(500);
                            }
                        }
                    }
                    if(getWidgets().getWidgetContainingText("Accept").interact()){
                        sleep(1000);
                    }
                }else if(getDialogues().isPendingOption()){
                    log("select second option");
                    getDialogues().selectOption(2);
                    sleep(200);
                }else{
                    log("talk to guide");
                    talkToInstructor("RuneScape Guide");
                    sleep(200);
                }
                break;

            case 3: //open settings tab
                log("open settings tab");
                getTabs().open(Tab.SETTINGS);
                sleep(200);
                break;

            case 7: //talk to guide
                log("talk to guide");
                talkToInstructor("RuneScape Guide");
                sleep(200);
                break;

            case 10: //disable audio
                log("disable audio");
                if(getConfigs().get(168) != 4 || getConfigs().get(169) != 4 || getConfigs().get(872) != 4){
                    final RS2Widget soundSettingsWidget = getWidgets().get(261,1,2); //action: Audio
                    final RS2Widget musicVolumeWidget = getWidgets().get(261,24); //action: Adjust Music Volume
                    final RS2Widget soundEffectVolumeWidget = getWidgets().get(261,30); //action: Adjust Sound Effect Volume
                    final RS2Widget areaSoundEffectVolumeWidget = getWidgets().get(261,36); //action: Adjust Area Sound Effect Volume
                    if(getTabs().open(Tab.SETTINGS)){
                        log("settings tab open");
                        if(soundSettingsWidget != null && soundSettingsWidget.isVisible() && musicVolumeWidget != null && !musicVolumeWidget.isVisible()){
                            log("Click Audio");
                            soundSettingsWidget.interact();
                        }else if(getConfigs().get(168) != 4 && musicVolumeWidget != null){
                            log("Click music volume");
                            musicVolumeWidget.interact();
                        }else if(getConfigs().get(169) != 4 && soundEffectVolumeWidget != null){
                            log("Click sound effect");
                            soundEffectVolumeWidget.interact();
                        }else if(getConfigs().get(872) != 4 && areaSoundEffectVolumeWidget != null){
                            log("click area sound effect");
                            areaSoundEffectVolumeWidget.interact();
                        }
                        sleep(200);
                    }
                }else if(!getSettings().areRoofsEnabled()){
                    log("toggle roofs");
                    final RS2Widget advancedOptionsWidget = getWidgets().getWidgetContainingText("Advanced Options");
                    final RS2Widget displaySettingsWidget = getWidgets().get(261,1,0); //action: Display
                    final RS2Widget toggleRoofHiddenWidget = getWidgets().get(60,14); //action: Roof-removal
                    if(getTabs().open(Tab.SETTINGS)){
                        log("settings tab open");
                        if(displaySettingsWidget != null && displaySettingsWidget.isVisible() && advancedOptionsWidget == null){
                            log("open display settings");
                            displaySettingsWidget.interact();
                        }else if(advancedOptionsWidget != null && advancedOptionsWidget.isVisible() && toggleRoofHiddenWidget == null){
                            log("click advanced options");
                            advancedOptionsWidget.interact();
                        }else if(toggleRoofHiddenWidget != null && toggleRoofHiddenWidget.isVisible()){
                            log("toggle roofs");
                            toggleRoofHiddenWidget.interact();
                        }
                        sleep(200);
                    }
                }else if(getObjects().closest("Door").interact("Open")){
                    log("interacting with door");
                    sleep(200);
                }
                break;

            case 20: //talk to survival expert
                log("talk to guide");
                talkToInstructor("Survival Expert");
                break;

            case 30: //open inventory
                log("open inventory");
                getTabs().open(Tab.INVENTORY);
                break;

            case 40: //chop tree
                log("chop tree");
                chopClosestTree();
                sleep(200);
                break;

            case 50: //make fire
                log("make fire");
                lightFire();
                sleep(200);
                break;

            case 60:
                getTabs().open(Tab.SKILLS);
                break;

            case 70:
                log("talk to guide");
                talkToInstructor("Survival Expert");
                break;

            case 80:
            case 90:
            case 100:
            case 110:
                log("fish");
                if(getTabs().open(Tab.INVENTORY)){
                    if((getInventory().getAmount("Raw shrimps")+getInventory().getAmount("Burnt shrimp")) < 2){
                        fish();
                    }else if(getObjects().closest("Fire") == null){
                        if(!getInventory().contains("Logs")){
                            chopClosestTree();
                        }else{
                            lightFire();
                        }
                    }else{
                        cookWithFire();
                    }
                }
                sleep(200);
                break;

            case 120:
                log("open gate");
                RS2Object gate = getObjects().closest("Gate");
                if(gate != null){
                    gate.interact("Open");
                }else{
                    getWalking().walkPath(PATH_TO_GATE);
                }
                sleep(200);
                break;

            case 130:
                log("enter cooking building");
                if(getWalking().walkPath(PATH_TO_COOK_BUILDING)){
                    getDoorHandler().handleNextObstacle(COOK_BUILDING);
                }
                break;

            case 140:
                log("talk to guide");
                talkToInstructor("Master Chef");
                break;

            case 150:
                log("make dough");
                makeDough();
                sleep(500);
                break;

            case 160:
                log("bake dough");
                bakeDoughOnRange();
                sleep(500);
                break;

            case 170:
                log("click music tab");
                getTabs().open(Tab.MUSIC);
                break;

            case 180:
                log("leave cooking area");
                getDoorHandler().handleNextObstacle(COOK_EXIT_DOOR);
                break;

            case 183:
            case 187:
                log("open emotes tab");
                if(getTabs().open(Tab.EMOTES)){
                    log("click random emote");
                    RS2Widget emoteWidget = getWidgets().get(216,1,new Random().nextInt(20));
                    if(emoteWidget != null){
                        emoteWidget.interact();
                        sleep(200);
                    }
                }
                break;

            case 190:
                log("open settings tab");
                getTabs().open(Tab.SETTINGS);
                break;

            case 200:
                log("set run on");
                if(!getSettings().isRunning()){
                    getSettings().setRunning(true);
                    sleep(200);
                }
                break;

            case 210:
                log("walk to quest building");
                if(getWalking().walkPath(PATH_TO_QUEST_BUILDING)){
                    getDoorHandler().handleNextObstacle(QUEST_BUILDING);
                }
                sleep(200);
                break;

            case 220:
                log("talk to guide");
                talkToInstructor("Quest Guide");
                break;

            case 230:
                log("open quest tab");
                getTabs().open(Tab.QUEST);
                break;

            case 240:
                log("talk to guide");
                talkToInstructor("Quest Guide");
                break;

            case 250:
                log("climb down ladder");
                RS2Object ladder = getObjects().closest("Ladder");
                if(ladder != null && getCamera().toEntity(ladder)){
                    ladder.interact();
                }
                sleep(200);
                break;

            case 260:
                log("talk to guide");
                if(getWalking().walkPath(PATH_TO_SMITH_AREA)){
                    talkToInstructor("Mining Instructor");
                }
                break;

            case 270:
                log("prospect tin");
                prospect(10080);
                sleep(1000);
                break;

            case 280:
                log("prospect copper");
                prospect(10079);
                sleep(1000);
                break;

            case 290:
                log("talk to guide");
                talkToInstructor("Mining Instructor");
                break;

            case 300:
                log("mine tin rock");
                mine(10080);
                sleep(200);
                break;

            case 310:
                log("mine copper rock");
                mine(10079);
                sleep(200);
                break;

            case 320:
                log("smelt at furnace");
                if(getTabs().open(Tab.INVENTORY)){
                    smelt();
                }
                break;

            case 330:
                log("talk to instructor");
                talkToInstructor("Mining Instructor");
                break;

            case 340:
            case 350:
                log("smith bronze dagger");
                if(getTabs().open(Tab.INVENTORY)){
                    smith();
                }
                break;

            case 360:
                log("walk through gate");
                if(getWalking().walkPath(PATH_TO_CAVES_GATE)){
                    getDoorHandler().handleNextObstacle(SMITH_EXIT_DOOR);
                }
                break;

            case 370:
                log("talk to instructor");
                talkToInstructor("Combat Instructor");
                break;

            case 390:
                log("open equipment tab");
                getTabs().open(Tab.EQUIPMENT);
                break;

            case 400:
                log("open equipment stats");
                RS2Widget equipmentStats = getWidgets().singleFilter(387,new WidgetActionFilter("View equipment stats"));
                if(equipmentStats != null && equipmentStats.isVisible()){
                    equipmentStats.interact();
                }
                sleep(200);
                break;

            case 405:
                log("wield bronze dagger");
                getInventory().getItem("Bronze dagger").interact();
                sleep(200);
                break;

            case 410:
                talkToInstructor("Combat Instructor");
                break;

            case 420:
                if(!getEquipment().isWearingItem(EquipmentSlot.WEAPON,"Bronze sword")){
                    getInventory().getItem("Bronze sword").interact();
                }else if(!getEquipment().isWearingItem(EquipmentSlot.SHIELD,"Wooden shield")){
                    getInventory().getItem("Wooden shield").interact();
                }
                sleep(200);
                break;

            case 430:
                getTabs().open(Tab.ATTACK);
                break;

            case 440:
            case 450:
            case 460:
                if(!inRatCage()){
                    enterRatCage();
                }else if(!isAttackingRat()){
                    attackRat();
                }
                sleep(200);
                break;

            case 470:
                if(inRatCage()){
                    leaveRatCage();
                }else{
                    talkToInstructor("Combat Instructor");
                }
                sleep(200);
                break;

            case 480:
            case 490:
                if (!getEquipment().isWearingItem(EquipmentSlot.WEAPON, "Shortbow")) {
                    getInventory().getItem("Shortbow").interact();
                } else if (!getEquipment().isWearingItem(EquipmentSlot.ARROWS, "Bronze arrow")) {
                    getInventory().getItem("Bronze arrow").interact();
                } else if (!isAttackingRat()) {
                    if(!RAT_RANGE_SPOT.equals(myPosition())){
                        WalkingEvent walkingEvent = new WalkingEvent(RAT_RANGE_SPOT);
                        walkingEvent.setMinDistanceThreshold(0);
                        execute(walkingEvent);
                    }else{
                        attackRat();
                    }
                }
                sleep(200);
                break;

            case 500:
                if(!LADDER_AREA.contains(myPosition())){
                    getWalking().walk(LADDER_AREA);
                }else if(!myPlayer().isAnimating()){
                    getObjects().closest("Ladder").interact("Climb-up");
                }
                sleep(200);
                break;

            case 510:
                if(!BANK_AREA.contains(myPosition())){
                    if(getWalking().walkPath(PATH_TO_BANK)){
                        getDoorHandler().handleNextObstacle(BANK_AREA);
                    }
                }else if(getDialogues().isPendingOption()){
                    getDialogues().selectOption("Yes.");
                }else if(getObjects().closest("Bank booth").interact("Use")){
                    sleep(1000);
                }
                break;

            case 520:
                if(getBank().isOpen()){
                    getBank().close();
                }else if(getObjects().closest("Poll booth").interact("Use")){
                    sleep(1000);
                }
                break;

            case 525:
                if (getWidgets().closeOpenInterface() && openDoorAtPosition(FINANCIAL_ADVISOR_ENTRANCE_DOOR)) {
                    sleep(1000);
                }
                break;

            case 530:
                talkToInstructor("Financial Advisor");
                break;

            case 540:
                if(openDoorAtPosition(FINANCIAL_ADVISOR_EXIT_DOOR)){
                    sleep(1000);
                }
                break;

            case 550:
                NPC instructor = getNpcs().closest("Brother Brace");
                if(instructor == null){
                    getWalking().walkPath(PATH_TO_CHURCH);
                }else if(!getMap().canReach(instructor)){
                    getDoorHandler().handleNextObstacle(CHURCH_AREA);
                }else if(!CHURCH_AREA.contains(myPosition())){
                    getWalking().walkPath(PATH_TO_CHURCH);
                }else{
                    talkToInstructor("Brother Brace");
                }


                /*if(!CHURCH_AREA.contains(myPosition()) && getWalking().walkPath(PATH_TO_CHURCH)){
                    getDoorHandler().handleNextObstacle(CHURCH_AREA);
                }else{
                    talkToInstructor("Brother Brace");
                }*/
                break;

            case 560:
                getTabs().open(Tab.PRAYER);
                break;

            case 570:
                talkToInstructor("Brother Brace");
                break;

            case 580:
                getTabs().open(Tab.FRIENDS);
                break;

            case 590:
                getTabs().open(Tab.IGNORES);
                break;

            case 600:
                talkToInstructor("Brother Brace");
                break;

            case 610:
                getDoorHandler().handleNextObstacle(CHURCH_EXIT_DOOR);
                break;

            case 620:
                if(!WIZARD_BUILDING.contains(myPosition())){
                    getWalking().walkPath(PATH_TO_WIZARD_BUILDING);
                }else{
                    talkToInstructor("Magic Instructor");
                }
                break;

            case 630:
                getTabs().open(Tab.MAGIC);
                break;

            case 640:
                talkToInstructor("Magic Instructor");
                break;

            case 650:
                if(!CHICKEN_AREA.contains(myPosition())){
                    WalkingEvent walkingEvent = new WalkingEvent(CHICKEN_AREA);
                    walkingEvent.setMinDistanceThreshold(0);
                    execute(walkingEvent);
                }else{
                    attackChicken();
                }
                break;

            case 670:
                if (getDialogues().isPendingOption()) {
                    getDialogues().selectOption("Yes.", "I'm fine, thanks.","No, I'm not planning to do that.");
                    sleep(200);
                } else {
                    talkToInstructor("Magic Instructor");
                    sleep(200);
                }
                break;

        }

        if(getConfigs().get(281) > 670){
            getBot().getScriptExecutor().stop();
        }

        return 0;
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

    public boolean talkToInstructor(String name){
        return execute(new InteractionEvent(getNpcs().closest(name),"Talk-to")).hasFinished();
    }

    public boolean chopClosestTree(){
        Entity tree = getObjects().closest("Tree");
        return tree != null && !myPlayer().isAnimating() && tree.interact("Chop down");
    }

    public boolean lightFire(){
        Object meme = getObjects().singleFilter(getObjects().getAll(),obj->obj.getPosition().equals(myPosition()) && obj.getName().equals("Fire"));
        if(meme != null){
            log("move away from fire");
            return execute(new WalkingEvent(myPlayer().getArea(4).getRandomPosition())).hasFinished();
        }else{
            log("make fire");
            if(getInventory().getSelectedItemName() == null && getInventory().contains("Tinderbox")){
                return getInventory().getItem("Tinderbox").interact();
            }else if(!getInventory().getSelectedItemName().equals("Tinderbox")){
                return getInventory().deselectItem();
            }else if(getInventory().getSelectedItemName().equals("Tinderbox") && getInventory().contains("Logs") && !myPlayer().isAnimating()){
                return getInventory().getItem("Logs").interact();
            }
        }
        return myPlayer().isAnimating();
    }

    public boolean fish(){
        NPC fishingSpot = getNpcs().closest("Fishing spot");
        return fishingSpot != null && !myPlayer().isAnimating() && fishingSpot.interact("Net");
    }

    public boolean cookWithFire(){
        if(getInventory().getSelectedItemName() == null || !getInventory().getSelectedItemName().equals("Raw shrimps")){
            return getInventory().getItem("Raw shrimps").interact();
        }else{
            RS2Object fire = getObjects().closest("fire");
            return fire != null && fire.interact();
        }
    }

    public boolean makeDough(){
        if(getInventory().getSelectedItemName() == null && getInventory().contains("Pot of flour")){
            return getInventory().getItem("Pot of flour").interact();
        }else if(!getInventory().getSelectedItemName().equals("Pot of flour")){
            return getInventory().deselectItem();
        }else if(getInventory().contains("Bucket of water")){
            return getInventory().getItem("Bucket of water").interact();
        }
        return false;
    }

    public boolean bakeDoughOnRange(){
        if(getInventory().getSelectedItemName() == null && getInventory().contains("Bread dough")){
            return getInventory().getItem("Bread dough").interact();
        }else if(!getInventory().getSelectedItemName().equals("Bread dough")){
            return getInventory().deselectItem();
        }else if(getObjects().closest("Range") != null){
            return getObjects().closest("Range").interact();
        }
        return true;
    }

    public boolean prospect(final int id){
        RS2Object rock = getObjects().closest(id);
        return rock != null && getMap().canReach(rock) && rock.interact("Prospect");
    }

    public boolean mine(final int id){
        RS2Object rock = getObjects().closest(id);
        return rock != null && getMap().canReach(rock) && !myPlayer().isAnimating() && rock.interact("Mine");
    }

    public boolean smelt(){
        if(getInventory().getSelectedItemName() == null){
            if(getInventory().contains("Tin ore")){
                return getInventory().getItem("Tin ore").interact();
            }
        }else if(getInventory().getSelectedItemName() != null && !getInventory().getSelectedItemName().equals("Tin ore")){
            return getInventory().deselectItem();
        }else if(getObjects().closest("Furnace") != null && !myPlayer().isAnimating()){
            return getObjects().closest("Furnace").interact("Use");
        }
        return false;
    }

    public boolean smith(){
        RS2Widget daggerWidget = getWidgets().getWidgetContainingText(312,"Dagger");
        if(daggerWidget != null && daggerWidget.isVisible() && daggerWidget.interact()){
            return Sleep.sleepUntil(()->getInventory().contains("Bronze dagger"),6000);
        }else{
            if(!SMITH_AREA.contains(myPosition())){
                return getWalking().walk(SMITH_AREA);
            }else if(!"Bronze bar".equals(getInventory().getSelectedItemName())){
                return getInventory().getItem("Bronze bar").interact();
            }else if(getObjects().closest("Anvil").interact()){
                return true;
            }
        }
        return false;
    }

    public boolean inRatCage(){
        return !getMap().canReach(getNpcs().closest("Combat Instructor"));
    }

    public boolean enterRatCage(){
        if(!OUTSIDE_RAT_CAGE_AREA.contains(myPosition())){
            return getWalking().walk(OUTSIDE_RAT_CAGE_AREA);
        }else{
            return getObjects().closest("Gate").interact();
        }
    }

    public boolean leaveRatCage(){
        if(!INSIDE_RAT_CAGE_AREA.contains(myPosition())){
            return getWalking().walk(INSIDE_RAT_CAGE_AREA);
        }else{
            return getObjects().closest("Gate").interact();
        }
    }

    public boolean isAttackingRat(){
        return myPlayer().getInteracting() != null && myPlayer().getInteracting().getName().equals("Giant rat");
    }

    public boolean attackRat(){
        NPC giantRat = getNpcs().closest(npc -> npc.getName().equals("Giant rat") && npc.isAttackable());
        return giantRat != null && giantRat.interact();
    }

    public boolean openDoorAtPosition(final Position position) {
        RS2Object door =  getObjects().closest(obj -> obj.getName().equals("Door") && obj.getPosition().equals(position));
        return door != null && door.interact("Open");
    }

    public boolean attackChicken(){
        NPC chicken = getNpcs().closest("Chicken");
        if(chicken != null && !myPlayer().isAnimating()){
            return getMagic().castSpellOnEntity(Spells.NormalSpells.WIND_STRIKE,chicken);
        }
        return false;
    }

}


 

Sleep.java

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

    public Sleep(final BooleanSupplier condition, final int timeout, final int interval) {
        super(timeout, interval);
        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();
    }

    public static boolean sleepUntil(final BooleanSupplier condition, final int timeout, final int interval) {
        return new Sleep(condition, timeout, interval).sleep();
    }
}

 

WidgetActionFilter.java

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.ui.RS2Widget;

public class WidgetActionFilter implements Filter<RS2Widget> {

    private final String[] actions;

    public WidgetActionFilter(final String... actions){
        this.actions = actions;
    }

    @Override
    public boolean match(final RS2Widget rs2Widget) {
        if(rs2Widget == null || !rs2Widget.isVisible() || rs2Widget.getInteractActions() == null){
            return false;
        }
        for(final String widgetAction : rs2Widget.getInteractActions()){
            for(final String matchAction : actions){
                if(widgetAction.equals(matchAction)){
                    return true;
                }
            }
        }
        return false;
    }
}

 

Thanks in advance. 

  • Like 1
Link to comment
Share on other sites

Skimmed over it, you're using conditional sleeps and following Java conventions which are requirements to upload a script to the SDN (and get Script Writer) which is good. Could use some organising though. Maybe put data in a seperate class and in a seperate package. Put your Sleep and WidgetActionFilters in a seperate package and perhaps use a task or node based system so you can seperate sections of the script such as the mining section, fighting section, bank section and so on.

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.

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...