Jump to content

Getting all objects in a wide area


Butters

Recommended Posts

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