Jump to content

POH Locations


Recommended Posts

Posted (edited)

Returns POH location found in config 738. My cons is quite low so I've only tested this for rimmington/taverly/pollniveach, unless they do some weird shit it should work for other locations as well.

Note: positions for brimhaven/yanille are missing atm.

public class POH {

    private static final int POH_CONFIG = 738;

    public static POHLocation getLocation(MethodProvider api) {
        int c = api.configs.get(POH_CONFIG) & 0x7; // clear other bits
        return POHLocation.values()[c];
    }

    public enum POHLocation {
        None(0x0, new Position(0,0,0)),
        RIMMINGTON(0x1, new Position(2953,3224,0)),
        TAVERLY(0x2, new Position(2893,3465,0)),
        POLLNIVEACH(0x3, new Position(3340,3003,0)),
        RELLEKKA(0x4, new Position(2670,3631,0)),
        BRIMHAVEN(0x5, new Position(0,0,0)),
        YANILLE(0x6, new Position(0,0,0));


        public final int mask;
        public final Position position;

        POHLocation(int mask, Position position) {
            this.mask = mask;
            this.position = position;
        }

    }

}

Edited by Flamezzz
  • Like 3
Posted (edited)

Sorry but I just had to clean this code up:

package com.liverare.better.utility.data;

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.MethodProvider;

public enum HouseLocation implements Filter<RS2Object> {
	
	NONE("None", 0, 0),
	RIMMINGTON("Rimmington", 2953, 3224),
	TAVERLY("Taverly", 2893, 3465),
	POLLNIVEACH("Pollniveach", 3340, 3003),
	RELLEKKA("Rellekka", 2670, 3631),
	BRIMHAVEN("Brimhaven", 0, 0),  // TODO Data required
	YANILLE("Yanille", 0, 0), // TODO Data required
	;
	
	/*
	 * Static global variables
	 */
	
	public static final String PORTAL_NAME = "Portal";
	public static final Integer CONFIG_ID = 738;
	
	/*
	 * Local field variables
	 */
	
	private final String name;
	private final Position position;

	HouseLocation(String name, Integer x, Integer y) {
		this.name = name;
		this.position = new Position(x, y, 0);
	}
	
	/*
	 * Overriden methods
	 */
	
	@Override
	public String toString() {
		return name + " [" + position.toString() + "]";
	}
	
	@Override
	public boolean match(RS2Object object) {
		return object.getPosition().equals(position)
				&& object.getName().equals(PORTAL_NAME);
	}
	
	/*
	 * Getters/setters
	 */
	
	public Position getPosition() {
		return position;
	}
	
	/*
	 * Static methods
	 */
	
	public static HouseLocation getCurrent(MethodProvider methodProvider) {
		final Integer index = (methodProvider.configs.get(CONFIG_ID) & 0x7);
		return values()[index];
	}
}

Example of usage:

RS2Object housePortalEntrance = getObjects().closest(
				HouseLocation.getCurrent(this));
Edited by liverare
  • Like 1
Posted (edited)

Sorry but I just had to clean this code up:

public enum HouseLocation {
	
	NONE(0, 0),
	RIMMINGTON(2953, 3224),
	TAVERLY(2893, 3465),
	POLLNIVEACH(3340, 3003),
	RELLEKKA(2670, 3631),
	BRIMHAVEN(0, 0),  // TODO Data required
	YANILLE(0, 0), // TODO Data required
	;
	
	private static final int CONFIG_ID = 738;
	
	public final Position position;

	HouseLocation(Integer x, Integer y) {
		this.position = new Position(x, y, 0);
	}
	
	public Position getLocation() {
		return position;
	}
	
	/*
	 * Static methods
	 */
	
	public static HouseLocation getCurrent(MethodProvider methodProvider) {
		final Integer index = (api.configs.get(CONFIG_ID) & 0x7);
		return values()[index];
	}
}

Nice find though. It may be very useful in some scripts, especially gilded altar (own house) scripts. If you wanted, you could implement an Filter<RS2Object> onto the enum, implement the required filter methods and then use the Enumerator record itself to filter for the house portal RS2Object. smile.png

 

The Filter interface? ew.

 

Edited by Botre
Posted

For enum records, I use Filter. For records that need a tad more filtering, I use Lambda. smile.png

 

You can use lambdas with the Filter class.

 Filter<RS2Object> lambda = o -> o != null && o.exists();

Filtering a Stream with a Predicate is more efficient than using a Filter on a List, hence the ew. Lambdas are just a matter of reducing verbosity :p

 

Also, why are you boxing the ints ? Oo

Posted

You can use lambdas with the Filter class.

 Filter<RS2Object> lambda = o -> o != null && o.exists();

Filtering a Stream with a Predicate is more efficient than using a Filter on a List, hence the ew. Lambdas are just a matter of reducing verbosity tongue.png

 

Also, why are you boxing the ints ? Oo

As for efficiency, we're not talking about a great deal of loss there. It's not like you're gonna need to constantly iterate for the RS2Object like 100 times a second. It's just each time you encounter the zone containing the portal. It's not much of a loss in my eyes.

 

I've (almost) made a full habit of switching from primitives to their Object counterparts, save for the booleans, in order to future proof the programme encase Java remove primitives altogether. There's a bit of controversy surrounding this with people making the case for primitives to be kept. :)

Posted

 

I've (almost) made a full habit of switching from primitives to their Object counterparts, save for the booleans, in order to future proof the programme encase Java remove primitives altogether. There's a bit of controversy surrounding this with people making the case for primitives to be kept. smile.png

 

Java won't ever remove primitives.

Objects waste space, primitives don't, easy as that x)

But at this level it probably doesn't matter.

  • Like 1
Posted (edited)

As for efficiency, we're not talking about a great deal of loss there. It's not like you're gonna need to constantly iterate for the RS2Object like 100 times a second. It's just each time you encounter the zone containing the portal. It's not much of a loss in my eyes.

 

I've (almost) made a full habit of switching from primitives to their Object counterparts, save for the booleans, in order to future proof the programme encase Java remove primitives altogether. There's a bit of controversy surrounding this with people making the case for primitives to be kept. smile.png

Java would never remove primitives. Even with Java 9's value type, which lowers the footprint of object creation, they will not be removed. It would break too much code. 

Java won't ever remove primitives.

Objects waste space, primitives don't, easy as that x)

But at this level it probably doesn't matter.

Check this out wink.png

Edited by fixthissite
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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