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

Manages the world regions. More...

Public Member Functions

List< NpcgetLocalNpcs (Mob mob)
 Gets the local npcs around an entity.
List< PlayergetLocalPlayers (Mob mob)
 Gets the local players around an entity.
Region getRegion (final int x, final int y)
 Gets a region by its x and y coordinates.
Region getRegion (Position position)
 Gets a region by position.
Region[] getSurroundingRegions (Position position)
 Gets the regions surrounding a position.

Static Public Member Functions

static void forNearbyPlayer (Mob mob, int distance, Consumer< Player > action)
 Sends an action to Mob instance which is within a
distance
.
static void forNearbyPlayer (Position position, int distance, Consumer< Player > action)
 Sends an action to Mob instance which is within a
distance
.

Static Private Member Functions

static int hash (int x, int y)

Private Attributes

final Int2ObjectMap< RegionactiveRegions = new Int2ObjectOpenHashMap<>()
 The active (loaded) region map.

Detailed Description

Manages the world regions.

Author
Graham Edgecombe

Definition at line 20 of file RegionManager.java.

Member Function Documentation

◆ forNearbyPlayer() [1/2]

void com.runehive.game.world.region.RegionManager.forNearbyPlayer ( Mob mob,
int distance,
Consumer< Player > action )
static

Sends an action to Mob instance which is within a
distance
.

Parameters
actionaction consumer.

Definition at line 31 of file RegionManager.java.

31 {
32 mob.getRegion().getSurroundingRegions().ifPresent(regions -> {
33 for (Region region : regions) {
34 for (Player nearby : region.getPlayers(mob.getHeight())) {
35 if (nearby == null) continue;
36 if (Utility.getDistance(nearby, mob) > distance) continue;
37 if (nearby.getCurrentHealth() <= 0 || nearby.isDead()) continue;
38 action.accept(nearby);
39 }
40 }
41 });
42 }

References com.runehive.util.Utility.getDistance(), com.runehive.game.world.entity.Entity.getHeight(), com.runehive.game.world.entity.Entity.getRegion(), and com.runehive.game.world.region.Region.getSurroundingRegions().

Referenced by com.runehive.game.world.entity.combat.strategy.npc.boss.Vetion.Earthquake.hit(), com.runehive.content.clanchannel.channel.ClanChannel.splitLoot(), com.runehive.game.world.entity.combat.strategy.npc.boss.skotizo.Skotizo.LightingRain.start(), com.runehive.game.world.entity.combat.strategy.npc.boss.skotizo.Skotizo.Magic.start(), and com.runehive.game.world.entity.combat.strategy.npc.boss.Vetion.Magic.start().

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

◆ forNearbyPlayer() [2/2]

void com.runehive.game.world.region.RegionManager.forNearbyPlayer ( Position position,
int distance,
Consumer< Player > action )
static

Sends an action to Mob instance which is within a
distance
.

Parameters
actionaction consumer.

Definition at line 50 of file RegionManager.java.

50 {
51 position.getRegion().getSurroundingRegions().ifPresent(regions -> {
52 for (Region region : regions) {
53 for (Player other : region.getPlayers(position.getHeight())) {
54 if (other == null) continue;
55 if (Utility.getDistance(other, position) > distance) continue;
56 if (other.getCurrentHealth() <= 0 || other.isDead()) continue;
57 action.accept(other);
58 }
59 }
60 });
61 }

References com.runehive.util.Utility.getDistance().

Here is the call graph for this function:

◆ getLocalNpcs()

List< Npc > com.runehive.game.world.region.RegionManager.getLocalNpcs ( Mob mob)

Gets the local npcs around an entity.

Parameters
mobThe entity.
Returns
The collection of local npcs.

Definition at line 88 of file RegionManager.java.

88 {
89 List<Npc> localNpcs = new LinkedList<>();
90 for (Region region : getSurroundingRegions(mob.getPosition())) {
91 for (Npc npc : region.getNpcs(mob.getHeight())) {
92 if (mob.getPosition().isWithinDistance(npc.getPosition(), Region.VIEW_DISTANCE)) {
93 localNpcs.add(npc);
94 }
95 }
96 }
97 return localNpcs;
98 }

References com.runehive.game.world.entity.Entity.getHeight(), com.runehive.game.world.entity.Entity.getPosition(), getSurroundingRegions(), com.runehive.game.world.position.Position.isWithinDistance(), and com.runehive.game.world.region.Region.VIEW_DISTANCE.

Referenced by com.runehive.game.world.entity.combat.CombatUtil.areaAction(), and com.runehive.net.packet.out.SendNpcUpdate.encode().

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

◆ getLocalPlayers()

List< Player > com.runehive.game.world.region.RegionManager.getLocalPlayers ( Mob mob)

Gets the local players around an entity.

Parameters
mobThe entity.
Returns
The collection of local players.

Definition at line 69 of file RegionManager.java.

69 {
70 Preconditions.checkArgument(mob != null, "mob is null");
71 List<Player> localPlayers = new LinkedList<>();
72 for (Region region : getSurroundingRegions(mob.getPosition())) {
73 for (Player player : region.getPlayers(mob.getHeight())) {
74 if (mob.getPosition().isWithinDistance(player.getPosition(), Region.VIEW_DISTANCE)) {
75 localPlayers.add(player);
76 }
77 }
78 }
79 return localPlayers;
80 }

References com.runehive.game.world.entity.Entity.getHeight(), com.runehive.game.world.entity.Entity.getPosition(), getSurroundingRegions(), com.runehive.game.world.position.Position.isWithinDistance(), and com.runehive.game.world.region.Region.VIEW_DISTANCE.

Referenced by com.runehive.game.world.entity.combat.CombatUtil.areaAction(), and com.runehive.net.packet.out.SendPlayerUpdate.encode().

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

◆ getRegion() [1/2]

Region com.runehive.game.world.region.RegionManager.getRegion ( final int x,
final int y )

Gets a region by its x and y coordinates.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The region.

Definition at line 151 of file RegionManager.java.

151 {
152 final int hash = hash(x, y);
153
154 final Region region = activeRegions.get(hash);
155 if (region != null) {
156 return region;
157 }
158
159 final Region newRegion = new Region(x, y);
160 activeRegions.put(hash, newRegion);
161 return newRegion;
162 }

References activeRegions, and hash().

Here is the call graph for this function:

◆ getRegion() [2/2]

Region com.runehive.game.world.region.RegionManager.getRegion ( Position position)

Gets a region by position.

Parameters
positionThe position.
Returns
The region.

Definition at line 140 of file RegionManager.java.

140 {
141 return getRegion(position.getX(), position.getY());
142 }

References getRegion().

Referenced by com.runehive.content.Obelisks.activate(), com.runehive.game.world.pathfinding.TraversalMap.getFlags(), com.runehive.game.world.position.Position.getRegion(), getRegion(), getSurroundingRegions(), com.runehive.content.wintertodt.Wintertodt.init(), com.runehive.game.world.pathfinding.TraversalMap.isInactive(), and com.runehive.fs.cache.decoder.RegionDecoder.load().

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

◆ getSurroundingRegions()

Region[] com.runehive.game.world.region.RegionManager.getSurroundingRegions ( Position position)

Gets the regions surrounding a position.

Parameters
positionThe position.
Returns
The regions surrounding the position.

Definition at line 106 of file RegionManager.java.

106 {
107 Region target = getRegion(position.getX(), position.getY());
108
109 if (target.getSurroundingRegions().isPresent()) {
110 return target.getSurroundingRegions().get();
111 }
112
113 Set<Region> surrounding = new HashSet<>();
114 int chunkX = position.getChunkX();
115 int chunkY = position.getChunkY();
116
117 for (int y = -1; y <= 1; y++) {
118 for (int x = -1; x <= 1; x++) {
119 int xx = (chunkX + x * 8 + 6) << 3;
120 int yy = (chunkY + y * 8 + 6) << 3;
121 Region region = getRegion(xx, yy);
122
123 if (!surrounding.contains(region)) {
124 surrounding.add(region);
125 }
126 }
127 }
128
129 Region[] x = surrounding.toArray(new Region[surrounding.size()]);
130 target.setSurroundingRegions(Optional.of(x));
131 return target.getSurroundingRegions().get();
132 }

References getRegion(), com.runehive.game.world.region.Region.getSurroundingRegions(), and com.runehive.game.world.region.Region.setSurroundingRegions().

Referenced by com.runehive.game.world.items.ground.GroundItem.addToRegion(), com.runehive.game.world.object.CustomGameObject.addToRegion(), com.runehive.game.world.items.ground.GroundItemEvent.execute(), getLocalNpcs(), getLocalPlayers(), com.runehive.game.world.entity.mob.player.Player.loadRegion(), com.runehive.game.world.object.StaticGameObject.register(), com.runehive.game.world.items.ground.GroundItem.removeFromRegion(), com.runehive.game.world.object.CustomGameObject.removeFromRegion(), and com.runehive.game.world.object.StaticGameObject.unregister().

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

◆ hash()

int com.runehive.game.world.region.RegionManager.hash ( int x,
int y )
staticprivate

Definition at line 164 of file RegionManager.java.

164 {
165 return ((x >> 6) << 8) + (y >> 6);
166 }

Referenced by getRegion().

Here is the caller graph for this function:

Member Data Documentation

◆ activeRegions

final Int2ObjectMap<Region> com.runehive.game.world.region.RegionManager.activeRegions = new Int2ObjectOpenHashMap<>()
private

The active (loaded) region map.

Definition at line 23 of file RegionManager.java.

Referenced by getRegion().


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