Jump to content
Nor3g

Hopping to PVP world Universal

Recommended Posts

I cant rly understand what you mean but the API has a few methods regarding world hopping.

boolean hop(int world)
Hops to the specified world id if the destination is not already the world you are in.
 
hopToF2PWorld()
Hops to a random F2P server which is not full or is PvP.

 

getCurrentWorld() 

isMembersWorld() 

 

You could solve your problem with the methods above, I guess.

 

Link to comment
Share on other sites

5 hours ago, Ragboys is back said:

I cant rly understand what you mean but the API has a few methods regarding world hopping.

boolean hop(int world)
Hops to the specified world id if the destination is not already the world you are in.
 
hopToF2PWorld()
Hops to a random F2P server which is not full or is PvP.

 

getCurrentWorld() 

isMembersWorld() 

 

You could solve your problem with the methods above, I guess.

 

 

 

Sorry for not being clear. I mean that when Jagex changes the F2P pvp world number, instead of hardcoding in Hop(371), I could just do Hop(pvp) or something like this. It doesn't seem to be in the API atm. 

Link to comment
Share on other sites

13 minutes ago, Nor3g said:

 

 

Sorry for not being clear. I mean that when Jagex changes the F2P pvp world number, instead of hardcoding in Hop(371), I could just do Hop(pvp) or something like this. It doesn't seem to be in the API atm. 

No i don't think api supports that, but you can use widgets as a solution for what you need now

Link to comment
Share on other sites

@Nor3g

CachedWidget.java

Spoiler

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

import java.util.Optional;

public class CachedWidget {

    private int parentID = -1, childID = -1, subChildID = -1;
    private String[] widgetTexts;
    private Filter<RS2Widget> filter;

    public CachedWidget(final int parentID, final int childID){
        if(parentID < 0 || childID < 0) {
            throw new IllegalArgumentException("Widget IDs must have a value > 0");
        }
        this.parentID = parentID;
        this.childID = childID;
    }

    public CachedWidget(final int parentID, final int childID, final int subChildID){
        if(parentID < 0 || childID < 0 || subChildID < 0) {
            throw new IllegalArgumentException("Widget IDs must have a value > 0");
        }
        this.parentID = parentID;
        this.childID = childID;
        this.subChildID = subChildID;
    }

    public CachedWidget(final String... widgetTexts){
        if(widgetTexts.length == 0) {
            throw new IllegalArgumentException("At least 1 String must be provided");
        }
        this.widgetTexts = widgetTexts;
    }

    public CachedWidget(final Filter<RS2Widget> filter) {
        if (filter == null) {
            throw new IllegalArgumentException("filter cannot be null");
        }
        this.filter = filter;
    }

    public Optional<RS2Widget> get(final Widgets widgets){
        if(subChildID != -1) {
            return Optional.ofNullable(widgets.get(parentID, childID, subChildID));
        } else if(parentID != -1) {
            return getSecondLevelWidget(widgets);
        } else if (widgetTexts != null) {
            return getWidgetWithText(widgets);
        } else {
            return getWidgetUsingFilter(widgets);
        }
    }

    private Optional<RS2Widget> getSecondLevelWidget(final Widgets widgets){
        RS2Widget rs2Widget = widgets.get(parentID, childID);
        if(rs2Widget != null && rs2Widget.isThirdLevel()){
            subChildID = rs2Widget.getThirdLevelId();
        }
        return Optional.ofNullable(rs2Widget);
    }

    private Optional<RS2Widget> getWidgetWithText(final Widgets widgets){
        RS2Widget rs2Widget = widgets.getWidgetContainingText(widgetTexts);
        if(rs2Widget != null){
            parentID = rs2Widget.getRootId();
            childID = rs2Widget.getSecondLevelId();
            if(rs2Widget.isThirdLevel()) {
                subChildID = rs2Widget.getThirdLevelId();
            }
        }
        return Optional.ofNullable(rs2Widget);
    }

    private Optional<RS2Widget> getWidgetUsingFilter(final Widgets widgets) {
        RS2Widget rs2Widget = widgets.singleFilter(widgets.getAll(), filter);
        if (rs2Widget != null) {
            parentID = rs2Widget.getRootId();
            childID = rs2Widget.getSecondLevelId();
            if (rs2Widget.isThirdLevel()) {
                subChildID = rs2Widget.getThirdLevelId();
            }
        }
        return Optional.ofNullable(rs2Widget);
    }

    @Override
    public String toString() {
        return parentID + ", " + childID + ", " + subChildID;
    }


Sleep.java

Spoiler

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

Spoiler

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

public final class WidgetActionFilter implements Filter<RS2Widget> {

    private final String[] actions;

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

    @Override
    public final 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;
    }
}


Credits to @Explv for all three classes above.

Usage:

int getPvPWorld() {
    Predicate<World> worldFilter = w -> w.getActivity().equals("PvP World - Free");
    if(openWorldSwitcher()) {
        List<World> worlds = getWorlds().getAvailableWorlds(true).stream().filter(worldFilter).collect(Collectors.toList());
        if(!worlds.isEmpty()) {
            return currentWorld = worlds.get(0).getId();
        }
    }
    return -1;
}

boolean openWorldSwitcher() {
    Event openWorldSwitcher = new OpenWorldSwitcherEvent();
    execute(openWorldSwitcher);
    return openWorldSwitcher.hasFinished();
}


 

Edited by Lordsthan
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...