RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.game.world.region.RegionBlock Class Reference

Represents a single region. More...

Public Member Functions

Set< GroundItemgetGroundItems (Position position)
 Gets a Set of GroundItems.
Collection< NpcgetNpcs ()
Collection< PlayergetPlayers ()

Package Functions

void addGroundItem (GroundItem item)
 Adds a ground item to this block.
void addNpc (Npc npc)
 Adds an npc to this block.
void addObject (GameObject object)
 Adds an object to this block.
void addPlayer (Player player)
 Adds a player to this block.
boolean containsNpc (Npc npc)
boolean containsObject (GameObject object)
boolean containsObject (Position position)
boolean containsPlayer (Player player)
GameObject getCustomObject (int id, Position position)
int getFlags (int x, int y)
 Gets a single tile in this region from the specified height, x and y coordinates.
GameObject getGameObject (int id, Position position)
List< GameObjectgetGameObjects (Position position)
GroundItem getGroundItem (int id, Position position)
 The method that retrieves the item with id on position.
void removeGroundItem (GroundItem item)
 Adds a ground item to this block.
void removeNpc (Npc npc)
 Removes an npc from this block.
void removeObject (GameObject object)
 Removes an object from this block.
void removePlayer (Player player)
 Removes a player from this block.
void sendGameObjects (Player player)
void sendGroundItems (Player player)
 The method which handles updating when the specified player enters a new region.
void setFlags (int x, int y, int flag)
 Gets a single tile in this region from the specified height, x and y coordinates.
void skip (GameObject gameObject)
void unsetFlags (int x, int y, int flag)
 Gets a single tile in this region from the specified height, x and y coordinates.

Private Member Functions

Map< Position, Set< GroundItem > > getGroundItems ()
Map< Position, List< GameObject > > getObjects ()
Deque< GameObjectgetRemovedObjects ()

Private Attributes

int[] flags
 The clipping flags within the region.
Map< Position, Set< GroundItem > > groundItems
 A list of ground items in this region.
Deque< Npcnpcs = new ConcurrentLinkedDeque<>()
 A list of npcs in this region.
Map< Position, List< GameObject > > objects
 A list of objects in this region.
Deque< Playerplayers = new ConcurrentLinkedDeque<>()
 A list of players in this region.
Deque< GameObjectskipped
 A list of removed objects in this region.

Detailed Description

Represents a single region.

Author
Graham Edgecombe

Definition at line 24 of file RegionBlock.java.

Member Function Documentation

◆ addGroundItem()

void com.runehive.game.world.region.RegionBlock.addGroundItem ( GroundItem item)
package

Adds a ground item to this block.

Definition at line 117 of file RegionBlock.java.

117 {
118 Set<GroundItem> items = getGroundItems(item.getPosition());
119 int index = 0;
120 for (GroundItem other : items) {
121 if (other.getIndex() + 1 > index) {
122 index = other.getIndex() + 1;
123 }
124 }
125 item.setIndex(index);
126 items.add(item);
127 getGroundItems().put(item.getPosition(), items);
128 }
val index

References getGroundItems(), com.runehive.game.world.entity.Entity.getPosition(), and com.runehive.game.world.entity.Entity.setIndex().

Referenced by com.runehive.game.world.region.Region.addGroundItem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNpc()

void com.runehive.game.world.region.RegionBlock.addNpc ( Npc npc)
package

Adds an npc to this block.

Definition at line 93 of file RegionBlock.java.

93 {
94 npcs.add(npc);
95 }

References npcs.

Referenced by com.runehive.game.world.region.Region.addNpc().

Here is the caller graph for this function:

◆ addObject()

void com.runehive.game.world.region.RegionBlock.addObject ( GameObject object)
package

Adds an object to this block.

Definition at line 103 of file RegionBlock.java.

103 {
104 List<GameObject> objs = getObjects().getOrDefault(object.getPosition(), new LinkedList<>());
105 if (objs.add(object))
106 getObjects().put(object.getPosition(), objs);
107 }

References getObjects().

Referenced by com.runehive.game.world.region.Region.addObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addPlayer()

void com.runehive.game.world.region.RegionBlock.addPlayer ( Player player)
package

Adds a player to this block.

Definition at line 83 of file RegionBlock.java.

83 {
84 players.add(player);
85 }

References players.

Referenced by com.runehive.game.world.region.Region.addPlayer().

Here is the caller graph for this function:

◆ containsNpc()

boolean com.runehive.game.world.region.RegionBlock.containsNpc ( Npc npc)
package
Returns
true if this region contains this npc

Definition at line 142 of file RegionBlock.java.

142 {
143 return npcs.contains(npc);
144 }

References npcs.

Referenced by com.runehive.game.world.region.Region.containsNpc().

Here is the caller graph for this function:

◆ containsObject() [1/2]

boolean com.runehive.game.world.region.RegionBlock.containsObject ( GameObject object)
package
Returns
true if object is in region

Definition at line 152 of file RegionBlock.java.

152 {
153 List<GameObject> objs = getObjects().get(object.getPosition());
154 return objs != null && objs.contains(object);
155 }

References getObjects().

Referenced by com.runehive.game.world.region.Region.containsObject(), and com.runehive.game.world.region.Region.containsObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsObject() [2/2]

boolean com.runehive.game.world.region.RegionBlock.containsObject ( Position position)
package
Returns
true if position is occupied by object

Definition at line 158 of file RegionBlock.java.

158 {
159 List<GameObject> objs = getObjects().get(position);
160 return objs != null && !objs.isEmpty();
161 }

References getObjects().

Here is the call graph for this function:

◆ containsPlayer()

boolean com.runehive.game.world.region.RegionBlock.containsPlayer ( Player player)
package
Returns
true if this region contains this player

Definition at line 147 of file RegionBlock.java.

147 {
148 return players.contains(player);
149 }

References players.

Referenced by com.runehive.game.world.region.Region.containsPlayer().

Here is the caller graph for this function:

◆ getCustomObject()

GameObject com.runehive.game.world.region.RegionBlock.getCustomObject ( int id,
Position position )
package

Definition at line 172 of file RegionBlock.java.

172 {
173 Set<Map.Entry<Position, List<GameObject>>> entrySet = getObjects().entrySet();
174 for (Map.Entry<Position, List<GameObject>> entry : entrySet) {
175 for (GameObject object : entry.getValue()) {
176 if (!(object instanceof CustomGameObject))
177 continue;
178 CustomGameObject obj = (CustomGameObject) object;
179 if (!obj.isValid()) {
180 continue;
181 }
182 System.err.println("haha we got it " + obj.getId());
183 return obj;
184 }
185 }
186 return null;
187 }

References com.runehive.game.world.object.GameObject.getId(), getObjects(), and com.runehive.game.world.entity.Entity.isValid().

Referenced by com.runehive.game.world.region.Region.getCustomObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFlags()

int com.runehive.game.world.region.RegionBlock.getFlags ( int x,
int y )
package

Gets a single tile in this region from the specified height, x and y coordinates.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The tile in this region for the specified attributes.

Definition at line 254 of file RegionBlock.java.

254 {
255 if (flags == null)
256 flags = new int[SIZE * SIZE];
257 return flags[x + y * SIZE];
258 }

References flags.

Referenced by com.runehive.game.world.region.Region.getFlags().

Here is the caller graph for this function:

◆ getGameObject()

GameObject com.runehive.game.world.region.RegionBlock.getGameObject ( int id,
Position position )
package

Definition at line 163 of file RegionBlock.java.

163 {
164 for (GameObject object : getGameObjects(position)) {
165 if (object.getId() == id) {
166 return object;
167 }
168 }
169 return null;
170 }

References getGameObjects().

Referenced by com.runehive.game.world.region.Region.getGameObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGameObjects()

List< GameObject > com.runehive.game.world.region.RegionBlock.getGameObjects ( Position position)
package

Definition at line 189 of file RegionBlock.java.

189 {
190 return getObjects().getOrDefault(position, Collections.emptyList());
191 }

References getObjects().

Referenced by getGameObject(), and com.runehive.game.world.region.Region.getObjects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGroundItem()

GroundItem com.runehive.game.world.region.RegionBlock.getGroundItem ( int id,
Position position )
package

The method that retrieves the item with id on position.

Parameters
idthe identifier to retrieve the item with.
positionthe position to retrieve the item on.
Returns
the item instance wrapped in an optional, or an empty optional if no item is found.

Definition at line 73 of file RegionBlock.java.

73 {
74 for (GroundItem item : getGroundItems(position)) {
75 if (item.isRegistered() && item.item.matchesId(id)) {
76 return item;
77 }
78 }
79 return null;
80 }

References getGroundItems().

Referenced by com.runehive.game.world.region.Region.getGroundItem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGroundItems() [1/2]

Map< Position, Set< GroundItem > > com.runehive.game.world.region.RegionBlock.getGroundItems ( )
private

Definition at line 228 of file RegionBlock.java.

228 {
229 if (groundItems == null)
230 groundItems = new ConcurrentHashMap<>();
231 return groundItems;
232 }

References groundItems.

Referenced by addGroundItem(), getGroundItem(), getGroundItems(), and removeGroundItem().

Here is the caller graph for this function:

◆ getGroundItems() [2/2]

Set< GroundItem > com.runehive.game.world.region.RegionBlock.getGroundItems ( Position position)

Gets a Set of GroundItems.

If none then creating the set.

Parameters
positionthe position to grab from.
Returns
the set of item nodes on the specified position.

Definition at line 61 of file RegionBlock.java.

61 {
62 return getGroundItems().getOrDefault(position, ConcurrentHashMap.newKeySet());
63 }

References getGroundItems().

Referenced by com.runehive.game.world.region.Region.getGroundItems(), and sendGroundItems().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNpcs()

Collection< Npc > com.runehive.game.world.region.RegionBlock.getNpcs ( )
Returns
the npcs in this block

Definition at line 50 of file RegionBlock.java.

50 {
51 return npcs;
52 }

References npcs.

Referenced by com.runehive.game.world.region.Region.getNpcs().

Here is the caller graph for this function:

◆ getObjects()

Map< Position, List< GameObject > > com.runehive.game.world.region.RegionBlock.getObjects ( )
private

Definition at line 234 of file RegionBlock.java.

234 {
235 if (objects == null)
236 objects = new ConcurrentHashMap<>();
237 return objects;
238 }

References objects.

Referenced by addObject(), containsObject(), containsObject(), getCustomObject(), getGameObjects(), removeObject(), and sendGameObjects().

Here is the caller graph for this function:

◆ getPlayers()

Collection< Player > com.runehive.game.world.region.RegionBlock.getPlayers ( )
Returns
the players in this block

Definition at line 45 of file RegionBlock.java.

45 {
46 return players;
47 }

References players.

Referenced by com.runehive.game.world.region.Region.getPlayers().

Here is the caller graph for this function:

◆ getRemovedObjects()

Deque< GameObject > com.runehive.game.world.region.RegionBlock.getRemovedObjects ( )
private

Definition at line 240 of file RegionBlock.java.

240 {
241 if (skipped == null)
242 skipped = new ConcurrentLinkedDeque<>();
243 return skipped;
244 }

References skipped.

Referenced by sendGameObjects(), and skip().

Here is the caller graph for this function:

◆ removeGroundItem()

void com.runehive.game.world.region.RegionBlock.removeGroundItem ( GroundItem item)
package

Adds a ground item to this block.

Definition at line 131 of file RegionBlock.java.

131 {
132 Set<GroundItem> items = getGroundItems(item.getPosition());
133 items.remove(item);
134 if (items.isEmpty()) {
135 getGroundItems().remove(item.getPosition());
136 } else {
137 getGroundItems().put(item.getPosition(), items);
138 }
139 }

References getGroundItems(), and com.runehive.game.world.entity.Entity.getPosition().

Referenced by com.runehive.game.world.region.Region.removeGroundItem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeNpc()

void com.runehive.game.world.region.RegionBlock.removeNpc ( Npc npc)
package

Removes an npc from this block.

Definition at line 98 of file RegionBlock.java.

98 {
99 npcs.remove(npc);
100 }

References npcs.

Referenced by com.runehive.game.world.region.Region.removeNpc().

Here is the caller graph for this function:

◆ removeObject()

void com.runehive.game.world.region.RegionBlock.removeObject ( GameObject object)
package

Removes an object from this block.

Definition at line 110 of file RegionBlock.java.

110 {
111 List<GameObject> objs = getObjects().get(object.getPosition());
112 if (objs != null)
113 objs.remove(object);
114 }

References getObjects().

Referenced by com.runehive.game.world.region.Region.removeObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removePlayer()

void com.runehive.game.world.region.RegionBlock.removePlayer ( Player player)
package

Removes a player from this block.

Definition at line 88 of file RegionBlock.java.

88 {
89 players.remove(player);
90 }

References players.

Referenced by com.runehive.game.world.region.Region.removePlayer().

Here is the caller graph for this function:

◆ sendGameObjects()

void com.runehive.game.world.region.RegionBlock.sendGameObjects ( Player player)
package

Definition at line 193 of file RegionBlock.java.

193 {
194 for (GameObject object : getRemovedObjects()) {
195 player.send(new SendRemoveObject(object));
196 }
197 Set<Map.Entry<Position, List<GameObject>>> entrySet = getObjects().entrySet();
198 for (Map.Entry<Position, List<GameObject>> entry : entrySet) {
199 for (GameObject object : entry.getValue()) {
200 if (!(object instanceof CustomGameObject))
201 continue;
202 CustomGameObject obj = (CustomGameObject) object;
203 if (!obj.isValid())
204 continue;
205 player.send(new SendAddObject(obj));
206 }
207 }
208 }

References getObjects(), getRemovedObjects(), com.runehive.game.world.entity.Entity.isValid(), and com.runehive.game.world.entity.mob.player.Player.send().

Referenced by com.runehive.game.world.region.Region.sendGameObjects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendGroundItems()

void com.runehive.game.world.region.RegionBlock.sendGroundItems ( Player player)
package

The method which handles updating when the specified player enters a new region.

Definition at line 214 of file RegionBlock.java.

214 {
215 for (Map.Entry<Position, Set<GroundItem>> entry : getGroundItems().entrySet()) {
216 for (GroundItem groundItem : entry.getValue()) {
217 if (!groundItem.isRegistered())
218 continue;
219
220 if (!groundItem.canSee(player))
221 continue;
222
223 player.send(new SendGroundItem(groundItem));
224 }
225 }
226 }

References getGroundItems(), and com.runehive.game.world.entity.mob.player.Player.send().

Referenced by com.runehive.game.world.region.Region.sendGroundItems().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFlags()

void com.runehive.game.world.region.RegionBlock.setFlags ( int x,
int y,
int flag )
package

Gets a single tile in this region from the specified height, x and y coordinates.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The tile in this region for the specified attributes.

Definition at line 268 of file RegionBlock.java.

268 {
269 if (flags == null)
270 flags = new int[SIZE * SIZE];
271 flags[x + y * SIZE] |= flag;
272 }

References flags.

Referenced by com.runehive.game.world.region.Region.setFlags().

Here is the caller graph for this function:

◆ skip()

void com.runehive.game.world.region.RegionBlock.skip ( GameObject gameObject)
package

Definition at line 288 of file RegionBlock.java.

288 {
289 getRemovedObjects().add(gameObject);
290 }

References getRemovedObjects().

Referenced by com.runehive.game.world.region.Region.skip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unsetFlags()

void com.runehive.game.world.region.RegionBlock.unsetFlags ( int x,
int y,
int flag )
package

Gets a single tile in this region from the specified height, x and y coordinates.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The tile in this region for the specified attributes.

Definition at line 282 of file RegionBlock.java.

282 {
283 if (flags == null)
284 flags = new int[SIZE * SIZE];
285 flags[x + y * SIZE] &= ~flag;
286 }

References flags.

Referenced by com.runehive.game.world.region.Region.unsetFlags().

Here is the caller graph for this function:

Member Data Documentation

◆ flags

int [] com.runehive.game.world.region.RegionBlock.flags
private

The clipping flags within the region.

Definition at line 27 of file RegionBlock.java.

Referenced by getFlags(), setFlags(), and unsetFlags().

◆ groundItems

Map<Position, Set<GroundItem> > com.runehive.game.world.region.RegionBlock.groundItems
private

A list of ground items in this region.

Definition at line 42 of file RegionBlock.java.

Referenced by getGroundItems().

◆ npcs

Deque<Npc> com.runehive.game.world.region.RegionBlock.npcs = new ConcurrentLinkedDeque<>()
private

A list of npcs in this region.

Definition at line 33 of file RegionBlock.java.

Referenced by addNpc(), containsNpc(), getNpcs(), and removeNpc().

◆ objects

Map<Position, List<GameObject> > com.runehive.game.world.region.RegionBlock.objects
private

A list of objects in this region.

Definition at line 36 of file RegionBlock.java.

Referenced by getObjects().

◆ players

Deque<Player> com.runehive.game.world.region.RegionBlock.players = new ConcurrentLinkedDeque<>()
private

A list of players in this region.

Definition at line 30 of file RegionBlock.java.

Referenced by addPlayer(), containsPlayer(), getPlayers(), and removePlayer().

◆ skipped

Deque<GameObject> com.runehive.game.world.region.RegionBlock.skipped
private

A list of removed objects in this region.

Definition at line 39 of file RegionBlock.java.

Referenced by getRemovedObjects().


The documentation for this class was generated from the following file: