1package com.runehive.game.world.region;
3import com.runehive.game.world.Interactable;
4import com.runehive.game.world.entity.mob.npc.Npc;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.items.ground.GroundItem;
7import com.runehive.game.world.object.GameObject;
8import com.runehive.game.world.pathfinding.TraversalMap;
9import com.runehive.game.world.position.Position;
10import com.runehive.util.Utility;
14import static com.runehive.game.world.position.Position.HEIGHT_LEVELS;
25 public static final Map<Position, GameObject>
ACTIVE_OBJECT =
new HashMap<>();
44 this.id = ((
x >> 6) << 8) + (
y >> 6);
79 public void setFlags(
int height,
int x,
int y,
int flags) {
212 return getX() == ((
x >> 3) - 6) >> 3 &&
getY() == ((
y >> 3) - 6) >> 3;
216 if (height > HEIGHT_LEVELS || height < 0) {
217 throw new IllegalArgumentException(
"Height is out of bounds. Received (" + height +
"), expected range [0, " + HEIGHT_LEVELS +
"].");
220 if (
blocks[height] ==
null) {
231 public static boolean reachable(
Position source,
int sourceWidth,
int sourceLength,
Position target,
int targetWidth,
int targetLength) {
232 if (
Utility.
inside(source, sourceWidth, sourceLength, target, targetWidth, targetLength)) {
233 return targetWidth == 0 || targetLength == 0;
237 int sourceTopX = source.
getX() + sourceWidth - 1;
238 int sourceTopY = source.
getY() + sourceLength - 1;
239 int targetTopX = target.
getX() + targetWidth - 1;
240 int targetTopY = target.
getY() + targetLength - 1;
242 if (sourceTopY == target.
getY() - 1 && source.
getX() >= target.
getX() && source.
getX() <= targetTopX) {
243 for (
x = 0,
y = sourceLength - 1;
x < sourceWidth;
x++)
249 if (sourceTopX == target.
getX() - 1 && source.
getY() >= target.
getY() && source.
getY() <= targetTopY) {
250 for (
x = 0,
y = 0;
y < sourceLength;
y++)
256 if (source.
getY() == targetTopY + 1 && source.
getX() >= target.
getX() && source.
getX() <= targetTopX) {
257 for (
x = 0,
y = 0;
x < sourceWidth;
x++)
263 if (source.
getX() == targetTopX + 1 && source.
getY() >= target.
getY() && source.
getY() <= targetTopY) {
264 for (
x = sourceWidth - 1,
y = 0;
y < sourceLength;
y++)
279 return "Region[" +
x +
"_" +
y +
"]";
Represents a non-player character in the in-game world.
This class represents a character controlled by a player.
Represents a single Ground item on the world map.
Contains traversal data for a set of regions.
static boolean blockedSouth(Position position)
static boolean blockedNorth(Position position)
static boolean blockedEast(Position position)
static boolean blockedWest(Position position)
Represents a single tile on the game world.
int getY()
Gets the absolute y coordinate.
int getX()
Gets the absolute x coordinate.
Position transform(int diffX, int diffY, int diffZ)
Creates a new location based on this location.
Represents a single region.
boolean containsPlayer(Player player)
void removePlayer(Player player)
Removes a player from this block.
GameObject getCustomObject(int id, Position position)
void addPlayer(Player player)
Adds a player to this block.
void removeGroundItem(GroundItem item)
Adds a ground item to this block.
void skip(GameObject gameObject)
void removeNpc(Npc npc)
Removes an npc from this block.
Collection< Npc > getNpcs()
boolean containsNpc(Npc npc)
void removeObject(GameObject object)
Removes an object from this block.
Set< GroundItem > getGroundItems(Position position)
Gets a Set of GroundItems.
GameObject getGameObject(int id, Position position)
void unsetFlags(int x, int y, int flag)
Gets a single tile in this region from the specified height, x and y coordinates.
List< GameObject > getGameObjects(Position position)
void addObject(GameObject object)
Adds an object to this block.
GroundItem getGroundItem(int id, Position position)
The method that retrieves the item with id on position.
void addNpc(Npc npc)
Adds an npc to this block.
void sendGameObjects(Player player)
void sendGroundItems(Player player)
The method which handles updating when the specified player enters a new region.
void addGroundItem(GroundItem item)
Adds a ground item to this block.
void setFlags(int x, int y, int flag)
Gets a single tile in this region from the specified height, x and y coordinates.
Collection< Player > getPlayers()
int getFlags(int x, int y)
Gets a single tile in this region from the specified height, x and y coordinates.
boolean containsObject(GameObject object)
boolean containsObject(int height, GameObject object)
GameObject getGameObject(int id, Position position)
void sendGroundItems(Player player)
Sends ground items in this region to the player.
RegionBlock getBlock(int height)
void sendGameObjects(Player player)
Sends game objects in this region to the player.
final RegionBlock[] blocks
The region blocks that execute different heights.
static final int VIEW_DISTANCE
boolean contains(int x, int y)
Set< GroundItem > getGroundItems(Position position)
boolean containsNpc(int height, Npc npc)
List< GameObject > getObjects(Position position)
void addObject(GameObject object)
Adds an object to this region.
void removeObject(GameObject object)
Removes an object from this region.
void unsetFlags(int height, int x, int y, int flags)
Gets a single tile in this region from the specified height, x and y coordinates.
GameObject getCustomObject(int id, Position position)
Optional< Region[]> surroundingRegions
The surrounded regions.
Collection< Npc > getNpcs(int height)
void setFlags(int height, int x, int y, int flags)
Gets a single tile in this region from the specified height, x and y coordinates.
Collection< Player > getPlayers(int height)
boolean contains(Position position)
int getFlags(int height, int x, int y)
Gets a single tile in this region from the specified height, x and y coordinates.
boolean containsPlayer(int height, Player player)
int x
The region coordinates.
void removeGroundItem(GroundItem item)
Adds a ground item to this region.
void addGroundItem(GroundItem item)
Adds a ground item to this region.
static final Map< Position, GameObject > ACTIVE_OBJECT
static final Set< Position > SKIPPED_OBJECTS
void addNpc(Npc npc)
Adds an npc to this region.
static boolean reachable(Position source, int sourceWidth, int sourceLength, Position target, int targetWidth, int targetLength)
static boolean reachable(Interactable source, Interactable target)
void removeNpc(Npc npc)
Removes an npc from this region.
void setSurroundingRegions(Optional< Region[]> surroundingRegions)
Region(int x, int y)
Creates a region.
static final int CHUNK_SIZE
void skip(GameObject gameObject)
boolean containsObject(Position position)
void addPlayer(Player player)
Adds a player to this region.
GroundItem getGroundItem(int id, Position position)
Optional< Region[]> getSurroundingRegions()
void removePlayer(Player player)
Removes a player from this region.
Handles miscellaneous methods.
static boolean inside(Interactable source, Interactable target)
An object implementing Interactable has uses.
Represents a game object.