Jump to content

Getting all objects in a wide area


Recommended Posts

Posted (edited)

You could pre-define these doors (at least the ones you care about):

public enum Door {
	
	// DEFINE DOORS HERE
	
	VARROCK_DOOR_A("Big door", 1000, 2000, 0),
	VARROCK_DOOR_B("Doory door", 2000, 3000, 1),
	FALADOR_DOOR_A("White door", 3000, 4000, 2),
	
	// etc.
	;
	
	// OOP CODE HERE
	
	private final String name;
	private final int x;
	private final int y;
	private final int z; // -1 = ignore plane check
	
	private Door(String name, int x, int y, int z) {
		this.name = name;
		this.x = x;
		this.y = y;
		this.z. = z;
	}
	
	private Door(String name, int x, int y, int z) {
		this(name, x, y, -1);
	}
	
	@Override
	public String toString() {
		return String.format("[name=%s, x=%s, y=%s, z=%s]", name, x, y, z);
	}
	
	public boolean isDefined(RS2Object gameObject) {
		return gameObject.getName().equals(name)
			&& gameObject.getX() == x
			&& gameObject.getY() == y
			&& (z == -1 || gameObject.getZ() == z);
	}
	
	// static methdo (it belongs to Door class, not instantiated Door objects)
	public static boolean isDefined(RS2Object gameObject) {
		boolean defined = false;
		for (Door door : values()) {
			if (door.isDefined(gameObject)) {
				defined = true;
				break;
			}
		}
		return defined;
	}
}

It's pretty verbose and isn't very future proof, but you can get very nitty-gritty with how exact it is the things you want to find are, then you can do:

List<RS2Object> openableDoors = s.objects.getAll().stream().filter(Door::isDefined).collect(Collectors.toList());

With this, you don't necessarily need to search for the doors because the information about those doors are already defined. You'd only need to actually find those doors in-game when you intend to interact with them.

 

(Also there might be problems because this is ad-hoc code I wrote in notepad)

Edited by liverare

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