mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Rename 'Sector' to 'Region'.
This commit is contained in:
@@ -43,9 +43,9 @@ module DoorUtil
|
||||
# Replaces a door object for a given player.
|
||||
# TODO: This is temporary.
|
||||
def self.replace_door(player, original, new)
|
||||
player.send PositionMessage.new(player.last_known_sector, original.position)
|
||||
player.send PositionMessage.new(player.last_known_region, original.position)
|
||||
player.send RemoveObjectMessage.new(original)
|
||||
player.send PositionMessage.new(player.last_known_sector, new.position)
|
||||
player.send PositionMessage.new(player.last_known_region, new.position)
|
||||
player.send SendObjectMessage.new(new)
|
||||
end
|
||||
|
||||
@@ -53,8 +53,8 @@ module DoorUtil
|
||||
def self.toggle(door, player)
|
||||
# First, we remove the door we're toggling (or un-toggling) from the game world.
|
||||
position = door.position
|
||||
sector = $world.sector_repository.from_position(position)
|
||||
sector.remove_entity door
|
||||
region = $world.region_repository.from_position(position)
|
||||
region.remove_entity door
|
||||
|
||||
# Have we toggled this door already?
|
||||
if TOGGLED_DOOR_REPOSITORY.include?(door)
|
||||
@@ -62,8 +62,8 @@ module DoorUtil
|
||||
original_door = TOGGLED_DOOR_REPOSITORY.delete(door)
|
||||
|
||||
# Now we add our new door to the game world.
|
||||
original_sector = $world.sector_repository.from_position(original_door.position)
|
||||
original_sector.add_entity original_door
|
||||
original_region = $world.region_repository.from_position(original_door.position)
|
||||
original_region.add_entity original_door
|
||||
|
||||
# TODO: This and the 'player' parameter are temporary. We still need to synchronize objects for local players.
|
||||
replace_door player, door, original_door
|
||||
@@ -74,8 +74,8 @@ module DoorUtil
|
||||
toggled_door = GameObject.new(door.id, toggled_position, door.type, toggled_orientation)
|
||||
|
||||
# Now we add our new door to the game world.
|
||||
toggled_sector = $world.sector_repository.from_position(toggled_position)
|
||||
toggled_sector.add_entity toggled_door
|
||||
toggled_region = $world.region_repository.from_position(toggled_position)
|
||||
toggled_region.add_entity toggled_door
|
||||
|
||||
# Insert our toggled door in the repository.
|
||||
TOGGLED_DOOR_REPOSITORY[toggled_door] = door
|
||||
@@ -87,7 +87,7 @@ module DoorUtil
|
||||
|
||||
# Gets the door object at the given position, if it exists.
|
||||
def self.get_door_object(position, object_id)
|
||||
game_objects = $world.sector_repository.from_position(position).get_entities(position, EntityType::GAME_OBJECT)
|
||||
game_objects = $world.region_repository.from_position(position).get_entities(position, EntityType::GAME_OBJECT)
|
||||
game_objects.each { |game_object| return game_object if game_object.id == object_id }
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -11,8 +11,8 @@ import java.util.function.Predicate;
|
||||
import org.apollo.fs.IndexedFileSystem;
|
||||
import org.apollo.fs.decoder.MapFileDecoder.MapDefinition;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.SectorRepository;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.area.RegionRepository;
|
||||
import org.apollo.game.model.area.collision.CollisionMatrix;
|
||||
import org.apollo.game.model.area.obj.ObjectType;
|
||||
import org.apollo.game.model.def.ObjectDefinition;
|
||||
@@ -51,19 +51,19 @@ public final class GameObjectDecoder {
|
||||
private final List<GameObject> objects = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The SectorRepository.
|
||||
* The RegionRepository.
|
||||
*/
|
||||
private final SectorRepository sectors;
|
||||
private final RegionRepository regions;
|
||||
|
||||
/**
|
||||
* Creates the GameObjectDecoder.
|
||||
*
|
||||
* @param fs The {@link IndexedFileSystem}.
|
||||
* @param sectors The {@link SectorRepository}.
|
||||
* @param regions The {@link RegionRepository}.
|
||||
*/
|
||||
public GameObjectDecoder(IndexedFileSystem fs, SectorRepository sectors) {
|
||||
public GameObjectDecoder(IndexedFileSystem fs, RegionRepository regions) {
|
||||
this.fs = fs;
|
||||
this.sectors = sectors;
|
||||
this.regions = regions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,10 +104,10 @@ public final class GameObjectDecoder {
|
||||
ObjectDefinition definition = ObjectDefinition.lookup(object.getId());
|
||||
int type = object.getType();
|
||||
|
||||
Sector sector = sectors.fromPosition(position);
|
||||
Region region = regions.fromPosition(position);
|
||||
int x = position.getX(), y = position.getY(), height = position.getHeight();
|
||||
|
||||
CollisionMatrix matrix = sector.getMatrix(height);
|
||||
CollisionMatrix matrix = region.getMatrix(height);
|
||||
|
||||
boolean block = false;
|
||||
|
||||
@@ -132,15 +132,15 @@ public final class GameObjectDecoder {
|
||||
if (block) {
|
||||
for (int dx = 0; dx < definition.getWidth(); dx++) {
|
||||
for (int dy = 0; dy < definition.getLength(); dy++) {
|
||||
int localX = (x % Sector.SECTOR_SIZE) + dx, localY = (y % Sector.SECTOR_SIZE) + dy;
|
||||
int localX = (x % Region.REGION_SIZE) + dx, localY = (y % Region.REGION_SIZE) + dy;
|
||||
|
||||
if (localX > 7 || localY > 7) {
|
||||
int nextLocalX = localX > 7 ? x + localX - 7 : x + localX;
|
||||
int nextLocalY = localY > 7 ? y + localY - 7 : y - localY;
|
||||
Position nextPosition = new Position(nextLocalX, nextLocalY);
|
||||
Sector next = sectors.fromPosition(nextPosition);
|
||||
Region next = regions.fromPosition(nextPosition);
|
||||
|
||||
int nextX = (nextPosition.getX() % Sector.SECTOR_SIZE) + dx, nextY = (nextPosition.getY() % Sector.SECTOR_SIZE)
|
||||
int nextX = (nextPosition.getX() % Region.REGION_SIZE) + dx, nextY = (nextPosition.getY() % Region.REGION_SIZE)
|
||||
+ dy;
|
||||
if (nextX > 7)
|
||||
nextX -= 7;
|
||||
@@ -164,10 +164,10 @@ public final class GameObjectDecoder {
|
||||
* @param position The {@link Position} of the tile whose attributes are being decoded.
|
||||
*/
|
||||
private void decodeAttributes(int attributes, Position position) {
|
||||
Sector sector = sectors.fromPosition(position);
|
||||
Region region = regions.fromPosition(position);
|
||||
int x = position.getX(), y = position.getY(), height = position.getHeight();
|
||||
|
||||
CollisionMatrix current = sector.getMatrix(height);
|
||||
CollisionMatrix current = region.getMatrix(height);
|
||||
|
||||
boolean block = false;
|
||||
if ((attributes & BLOCKED_TILE) != 0) {
|
||||
@@ -181,7 +181,7 @@ public final class GameObjectDecoder {
|
||||
}
|
||||
|
||||
if (block) {
|
||||
int localX = (x % Sector.SECTOR_SIZE), localY = (y % Sector.SECTOR_SIZE);
|
||||
int localX = (x % Region.REGION_SIZE), localY = (y % Region.REGION_SIZE);
|
||||
current.block(localX, localY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.Map;
|
||||
import org.apollo.fs.IndexedFileSystem;
|
||||
import org.apollo.fs.archive.Archive;
|
||||
import org.apollo.fs.archive.ArchiveEntry;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.Region;
|
||||
|
||||
/**
|
||||
* Decodes {@link MapDefinition}s from the {@link IndexedFileSystem}.
|
||||
@@ -21,7 +21,7 @@ public final class MapFileDecoder {
|
||||
/**
|
||||
* The width (and length) of a map file, in tiles.
|
||||
*/
|
||||
public static final int MAP_FILE_WIDTH = Sector.SECTOR_SIZE * Sector.SECTOR_SIZE;
|
||||
public static final int MAP_FILE_WIDTH = Region.REGION_SIZE * Region.REGION_SIZE;
|
||||
|
||||
/**
|
||||
* The file id of the versions archive.
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.apollo.game.message.handler.MessageHandlerContext;
|
||||
import org.apollo.game.message.impl.ObjectActionMessage;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.SectorRepository;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.area.RegionRepository;
|
||||
import org.apollo.game.model.def.ObjectDefinition;
|
||||
import org.apollo.game.model.entity.Entity.EntityType;
|
||||
import org.apollo.game.model.entity.GameObject;
|
||||
@@ -23,9 +23,9 @@ import org.apollo.game.model.entity.Player;
|
||||
public final class ObjectActionVerificationHandler extends MessageHandler<ObjectActionMessage> {
|
||||
|
||||
/**
|
||||
* The world's sector repository.
|
||||
* The world's RegionRepository.
|
||||
*/
|
||||
private final SectorRepository repository = World.getWorld().getSectorRepository();
|
||||
private final RegionRepository repository = World.getWorld().getRegionRepository();
|
||||
|
||||
@Override
|
||||
public void handle(MessageHandlerContext ctx, Player player, ObjectActionMessage message) {
|
||||
@@ -36,8 +36,8 @@ public final class ObjectActionVerificationHandler extends MessageHandler<Object
|
||||
}
|
||||
|
||||
Position position = message.getPosition();
|
||||
Sector sector = repository.fromPosition(position);
|
||||
Set<GameObject> objects = sector.getEntities(position, EntityType.GAME_OBJECT);
|
||||
Region region = repository.fromPosition(position);
|
||||
Set<GameObject> objects = region.getEntities(position, EntityType.GAME_OBJECT);
|
||||
|
||||
if (!player.getPosition().isWithinDistance(position, 15) || !containsObject(id, objects)) {
|
||||
ctx.breakHandlerChain();
|
||||
|
||||
@@ -14,9 +14,9 @@ import org.apollo.game.sync.seg.SynchronizationSegment;
|
||||
public final class PlayerSynchronizationMessage extends Message {
|
||||
|
||||
/**
|
||||
* The position in the last known sector.
|
||||
* The Position in the last known region.
|
||||
*/
|
||||
private final Position lastKnownSector;
|
||||
private final Position lastKnownRegion;
|
||||
|
||||
/**
|
||||
* The number of local players.
|
||||
@@ -29,9 +29,9 @@ public final class PlayerSynchronizationMessage extends Message {
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* A flag indicating if the sector has changed.
|
||||
* A flag indicating if the region has changed.
|
||||
*/
|
||||
private final boolean sectorChanged;
|
||||
private final boolean regionChanged;
|
||||
|
||||
/**
|
||||
* The current player's synchronization segment.
|
||||
@@ -46,29 +46,30 @@ public final class PlayerSynchronizationMessage extends Message {
|
||||
/**
|
||||
* Creates the player synchronization message.
|
||||
*
|
||||
* @param lastKnownSector The last known sector.
|
||||
* @param lastKnownRegion The last known region.
|
||||
* @param position The player's current position.
|
||||
* @param sectorChanged A flag indicating if the sector has changed.
|
||||
* @param regionChanged A flag indicating if the region has changed.
|
||||
* @param segment The current player's synchronization segment.
|
||||
* @param localPlayers The number of local players.
|
||||
* @param segments A list of segments.
|
||||
*/
|
||||
public PlayerSynchronizationMessage(Position lastKnownSector, Position position, boolean sectorChanged, SynchronizationSegment segment, int localPlayers, List<SynchronizationSegment> segments) {
|
||||
this.lastKnownSector = lastKnownSector;
|
||||
public PlayerSynchronizationMessage(Position lastKnownRegion, Position position, boolean regionChanged,
|
||||
SynchronizationSegment segment, int localPlayers, List<SynchronizationSegment> segments) {
|
||||
this.lastKnownRegion = lastKnownRegion;
|
||||
this.position = position;
|
||||
this.sectorChanged = sectorChanged;
|
||||
this.regionChanged = regionChanged;
|
||||
this.segment = segment;
|
||||
this.localPlayers = localPlayers;
|
||||
this.segments = segments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last known sector.
|
||||
* Gets the last known region.
|
||||
*
|
||||
* @return The last known sector.
|
||||
* @return The last known region.
|
||||
*/
|
||||
public Position getLastKnownSector() {
|
||||
return lastKnownSector;
|
||||
public Position getLastKnownRegion() {
|
||||
return lastKnownRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,12 +109,12 @@ public final class PlayerSynchronizationMessage extends Message {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the sector has changed.
|
||||
* Checks if the region has changed.
|
||||
*
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
public boolean hasSectorChanged() {
|
||||
return sectorChanged;
|
||||
public boolean hasRegionChanged() {
|
||||
return regionChanged;
|
||||
}
|
||||
|
||||
}
|
||||
+8
-8
@@ -4,30 +4,30 @@ import org.apollo.game.message.Message;
|
||||
import org.apollo.game.model.Position;
|
||||
|
||||
/**
|
||||
* A {@link Message} sent to the client instructing it to load the specified sector.
|
||||
* A {@link Message} sent to the client instructing it to load the specified region.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public final class SectorChangeMessage extends Message {
|
||||
public final class RegionChangeMessage extends Message {
|
||||
|
||||
/**
|
||||
* The position of the sector to load.
|
||||
* The position of the region to load.
|
||||
*/
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* Creates the sector changed message.
|
||||
* Creates the region changed message.
|
||||
*
|
||||
* @param position The position of the sector.
|
||||
* @param position The position of the region.
|
||||
*/
|
||||
public SectorChangeMessage(Position position) {
|
||||
public RegionChangeMessage(Position position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of the sector to load.
|
||||
* Gets the position of the region to load.
|
||||
*
|
||||
* @return The position of the sector to load.
|
||||
* @return The position of the region to load.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
@@ -38,7 +38,7 @@ public final class RemoveObjectMessage extends Message {
|
||||
* Creates the RemoveObjectMessage.
|
||||
*
|
||||
* @param object The {@link GameObject} to send.
|
||||
* @param positionOffset The offset of the object's position from the sector's central position.
|
||||
* @param positionOffset The offset of the object's position from the region's central position.
|
||||
*/
|
||||
public RemoveObjectMessage(GameObject object, int positionOffset) {
|
||||
this.positionOffset = positionOffset;
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class SendObjectMessage extends Message {
|
||||
* Creates the SendObjectMessage.
|
||||
*
|
||||
* @param object The {@link GameObject} to send.
|
||||
* @param positionOffset The offset of the object's position from the sector's central position.
|
||||
* @param positionOffset The offset of the object's position from the region's central position.
|
||||
*/
|
||||
public SendObjectMessage(GameObject object, int positionOffset) {
|
||||
this.id = object.getId();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.apollo.game.model;
|
||||
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.SectorCoordinates;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.area.RegionCoordinates;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
@@ -62,20 +62,20 @@ public final class Position {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x coordinate of the central sector.
|
||||
* Gets the x coordinate of the central region.
|
||||
*
|
||||
* @return The x coordinate of the central sector.
|
||||
* @return The x coordinate of the central region.
|
||||
*/
|
||||
public int getCentralSectorX() {
|
||||
public int getCentralRegionX() {
|
||||
return getX() / 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y coordinate of the central sector.
|
||||
* Gets the y coordinate of the central region.
|
||||
*
|
||||
* @return The y coordinate of the central sector.
|
||||
* @return The y coordinate of the central region.
|
||||
*/
|
||||
public int getCentralSectorY() {
|
||||
public int getCentralRegionY() {
|
||||
return getY() / 8;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public final class Position {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x coordinate inside the sector of this position.
|
||||
* Gets the x coordinate inside the region of this position.
|
||||
*
|
||||
* @return The local x coordinate.
|
||||
*/
|
||||
@@ -110,17 +110,17 @@ public final class Position {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the local x coordinate inside the sector of the {@code base} position.
|
||||
* Gets the local x coordinate inside the region of the {@code base} position.
|
||||
*
|
||||
* @param base The base position.
|
||||
* @return The local x coordinate.
|
||||
*/
|
||||
public int getLocalX(Position base) {
|
||||
return getX() - base.getTopLeftSectorX() * 8;
|
||||
return getX() - base.getTopLeftRegionX() * 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y coordinate inside the sector of this position.
|
||||
* Gets the y coordinate inside the region of this position.
|
||||
*
|
||||
* @return The local y coordinate.
|
||||
*/
|
||||
@@ -129,13 +129,13 @@ public final class Position {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the local y coordinate inside the sector of the {@code base} position.
|
||||
* Gets the local y coordinate inside the region of the {@code base} position.
|
||||
*
|
||||
* @param base The base position.
|
||||
* @return The local y coordinate.
|
||||
*/
|
||||
public int getLocalY(Position base) {
|
||||
return getY() - base.getTopLeftSectorY() * 8;
|
||||
return getY() - base.getTopLeftRegionY() * 8;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,29 +151,29 @@ public final class Position {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link SectorCoordinates} of the {@link Sector} this position is inside.
|
||||
* Returns the {@link RegionCoordinates} of the {@link Region} this position is inside.
|
||||
*
|
||||
* @return The sector coordinates.
|
||||
* @return The region coordinates.
|
||||
*/
|
||||
public SectorCoordinates getSectorCoordinates() {
|
||||
return SectorCoordinates.fromPosition(this);
|
||||
public RegionCoordinates getRegionCoordinates() {
|
||||
return RegionCoordinates.fromPosition(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x coordinate of the sector this position is in.
|
||||
* Gets the x coordinate of the region this position is in.
|
||||
*
|
||||
* @return The sector x coordinate.
|
||||
* @return The region x coordinate.
|
||||
*/
|
||||
public int getTopLeftSectorX() {
|
||||
public int getTopLeftRegionX() {
|
||||
return getX() / 8 - 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y coordinate of the sector this position is in.
|
||||
* Gets the y coordinate of the region this position is in.
|
||||
*
|
||||
* @return The sector y coordinate.
|
||||
* @return The region y coordinate.
|
||||
*/
|
||||
public int getTopLeftSectorY() {
|
||||
public int getTopLeftRegionY() {
|
||||
return getY() / 8 - 6;
|
||||
}
|
||||
|
||||
@@ -201,14 +201,14 @@ public final class Position {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this position is inside the specified {@link Sector}.
|
||||
* Returns whether or not this position is inside the specified {@link Region}.
|
||||
*
|
||||
* @param sector The sector.
|
||||
* @return {@code true} if this position is inside the specified sector, otherwise {@code false}.
|
||||
* @param region The region.
|
||||
* @return {@code true} if this position is inside the specified region, otherwise {@code false}.
|
||||
*/
|
||||
public boolean inside(Sector sector) {
|
||||
SectorCoordinates coordinates = sector.getCoordinates();
|
||||
return coordinates.equals(getSectorCoordinates());
|
||||
public boolean inside(Region region) {
|
||||
RegionCoordinates coordinates = region.getCoordinates();
|
||||
return coordinates.equals(getRegionCoordinates());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,7 +226,8 @@ public final class Position {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("x", getX()).add("y", getY()).add("height", getHeight()).add("sector", getSectorCoordinates()).toString();
|
||||
return MoreObjects.toStringHelper(this).add("x", getX()).add("y", getY()).add("height", getHeight())
|
||||
.add("region", getRegionCoordinates()).toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,8 +15,8 @@ import org.apollo.fs.decoder.ItemDefinitionDecoder;
|
||||
import org.apollo.fs.decoder.NpcDefinitionDecoder;
|
||||
import org.apollo.fs.decoder.ObjectDefinitionDecoder;
|
||||
import org.apollo.game.command.CommandDispatcher;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.SectorRepository;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.area.RegionRepository;
|
||||
import org.apollo.game.model.def.EquipmentDefinition;
|
||||
import org.apollo.game.model.def.ItemDefinition;
|
||||
import org.apollo.game.model.def.NpcDefinition;
|
||||
@@ -134,9 +134,9 @@ public final class World {
|
||||
private final Scheduler scheduler = new Scheduler();
|
||||
|
||||
/**
|
||||
* This world's {@link SectorRepository}.
|
||||
* This world's {@link RegionRepository}.
|
||||
*/
|
||||
private final SectorRepository sectors = SectorRepository.immutable();
|
||||
private final RegionRepository regions = RegionRepository.immutable();
|
||||
|
||||
/**
|
||||
* Creates the world.
|
||||
@@ -202,12 +202,12 @@ public final class World {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this world's {@link SectorRepository}.
|
||||
* Gets this world's {@link RegionRepository}.
|
||||
*
|
||||
* @return The sector repository.
|
||||
* @return The RegionRepository.
|
||||
*/
|
||||
public SectorRepository getSectorRepository() {
|
||||
return sectors;
|
||||
public RegionRepository getRegionRepository() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,7 +243,7 @@ public final class World {
|
||||
ObjectDefinition.init(objectDefs);
|
||||
logger.fine("Loaded " + objectDefs.length + " object definitions.");
|
||||
|
||||
GameObjectDecoder staticDecoder = new GameObjectDecoder(fs, sectors);
|
||||
GameObjectDecoder staticDecoder = new GameObjectDecoder(fs, regions);
|
||||
GameObject[] objects = staticDecoder.decode();
|
||||
placeEntities(objects);
|
||||
logger.fine("Loaded " + objects.length + " static objects.");
|
||||
@@ -292,8 +292,8 @@ public final class World {
|
||||
boolean success = npcRepository.add(npc);
|
||||
|
||||
if (success) {
|
||||
Sector sector = sectors.fromPosition(npc.getPosition());
|
||||
sector.addEntity(npc);
|
||||
Region region = regions.fromPosition(npc.getPosition());
|
||||
region.addEntity(npc);
|
||||
|
||||
if (npc.hasBoundaries()) {
|
||||
npcMovement.addNpc(npc);
|
||||
@@ -319,8 +319,8 @@ public final class World {
|
||||
boolean success = playerRepository.add(player);
|
||||
if (success) {
|
||||
players.put(NameUtil.encodeBase37(username), player);
|
||||
Sector sector = sectors.fromPosition(player.getPosition());
|
||||
sector.addEntity(player);
|
||||
Region region = regions.fromPosition(player.getPosition());
|
||||
region.addEntity(player);
|
||||
|
||||
logger.info("Registered player: " + player + " [count=" + playerRepository.size() + "]");
|
||||
return RegistrationStatus.OK;
|
||||
@@ -357,9 +357,9 @@ public final class World {
|
||||
*/
|
||||
public void unregister(final Npc npc) {
|
||||
if (npcRepository.remove(npc)) {
|
||||
Sector sector = sectors.fromPosition(npc.getPosition());
|
||||
Region region = regions.fromPosition(npc.getPosition());
|
||||
|
||||
sector.removeEntity(npc);
|
||||
region.removeEntity(npc);
|
||||
} else {
|
||||
logger.warning("Could not find npc " + npc + " to unregister!");
|
||||
}
|
||||
@@ -375,20 +375,20 @@ public final class World {
|
||||
players.remove(NameUtil.encodeBase37(player.getUsername()));
|
||||
logger.info("Unregistered player: " + player + " [count=" + playerRepository.size() + "]");
|
||||
|
||||
Sector sector = sectors.fromPosition(player.getPosition());
|
||||
sector.removeEntity(player);
|
||||
Region region = regions.fromPosition(player.getPosition());
|
||||
region.removeEntity(player);
|
||||
} else {
|
||||
logger.warning("Could not find player " + player + " to unregister!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds entities to sectors in the {@link SectorRepository}.
|
||||
* Adds entities to regions in the {@link RegionRepository}.
|
||||
*
|
||||
* @param entities The entities.
|
||||
*/
|
||||
private void placeEntities(Entity... entities) {
|
||||
Arrays.stream(entities).forEach(entity -> sectors.fromPosition(entity.getPosition()).addEntity(entity));
|
||||
Arrays.stream(entities).forEach(entity -> regions.fromPosition(entity.getPosition()).addEntity(entity));
|
||||
}
|
||||
|
||||
}
|
||||
+40
-39
@@ -23,12 +23,12 @@ import com.google.common.collect.ImmutableSet;
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class Sector {
|
||||
public final class Region {
|
||||
|
||||
/**
|
||||
* The width and length of a Sector, in tiles.
|
||||
* The width and length of a Region, in tiles.
|
||||
*/
|
||||
public static final int SECTOR_SIZE = 8;
|
||||
public static final int REGION_SIZE = 8;
|
||||
|
||||
/**
|
||||
* The default size of newly-created sets, to reduce memory usage.
|
||||
@@ -36,9 +36,9 @@ public final class Sector {
|
||||
private static final int DEFAULT_SET_SIZE = 2;
|
||||
|
||||
/**
|
||||
* The SectorCoordinates of this Sector.
|
||||
* The RegionCoordinates of this Region.
|
||||
*/
|
||||
private final SectorCoordinates coordinates;
|
||||
private final RegionCoordinates coordinates;
|
||||
|
||||
/**
|
||||
* The Map of Positions to Entities in that Position.
|
||||
@@ -46,40 +46,40 @@ public final class Sector {
|
||||
private final Map<Position, Set<Entity>> entities = new HashMap<>();
|
||||
|
||||
/**
|
||||
* A List of SectorListeners registered to this Sector.
|
||||
* A List of RegionListeners registered to this Region.
|
||||
*/
|
||||
private final List<SectorListener> listeners = new ArrayList<>();
|
||||
private final List<RegionListener> listeners = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The CollisionMatrix.
|
||||
*/
|
||||
private final CollisionMatrix[] matrices = CollisionMatrix.createMatrices(Position.HEIGHT_LEVELS, SECTOR_SIZE, SECTOR_SIZE);
|
||||
private final CollisionMatrix[] matrices = CollisionMatrix.createMatrices(Position.HEIGHT_LEVELS, REGION_SIZE, REGION_SIZE);
|
||||
|
||||
/**
|
||||
* Creates a new sector.
|
||||
* Creates a new Region.
|
||||
*
|
||||
* @param x The x coordinate of the sector.
|
||||
* @param y The y coordinate of the sector.
|
||||
* @param x The x coordinate of the Region.
|
||||
* @param y The y coordinate of the Region.
|
||||
*/
|
||||
public Sector(int x, int y) {
|
||||
this(new SectorCoordinates(x, y));
|
||||
public Region(int x, int y) {
|
||||
this(new RegionCoordinates(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new sector with the specified {@link SectorCoordinates}.
|
||||
* Creates a new Region with the specified {@link RegionCoordinates}.
|
||||
*
|
||||
* @param coordinates The coordinates.
|
||||
*/
|
||||
public Sector(SectorCoordinates coordinates) {
|
||||
public Region(RegionCoordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a {@link Entity} from to sector. Note that this does not spawn the Entity, or do any other action other than
|
||||
* register it to this sector.
|
||||
* Adds a {@link Entity} from to Region. Note that this does not spawn the Entity, or do any other action other than
|
||||
* register it to this Region.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this sector.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this Region.
|
||||
*/
|
||||
public void addEntity(Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
@@ -88,16 +88,16 @@ public final class Sector {
|
||||
Set<Entity> local = entities.computeIfAbsent(position, key -> new HashSet<>(DEFAULT_SET_SIZE));
|
||||
local.add(entity);
|
||||
|
||||
notifyListeners(entity, SectorOperation.ADD);
|
||||
notifyListeners(entity, RegionOperation.ADD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this sector contains the specified Entity.
|
||||
* Checks if this Region contains the specified Entity.
|
||||
* <p>
|
||||
* This method operates in constant time.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @return {@code true} if this sector contains the Entity, otherwise {@code false}.
|
||||
* @return {@code true} if this Region contains the Entity, otherwise {@code false}.
|
||||
*/
|
||||
public boolean contains(Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
@@ -107,11 +107,11 @@ public final class Sector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets this sector's {@link SectorCoordinates}.
|
||||
* Gets this Region's {@link RegionCoordinates}.
|
||||
*
|
||||
* @return The sector coordinates.
|
||||
* @return The Region coordinates.
|
||||
*/
|
||||
public SectorCoordinates getCoordinates() {
|
||||
public RegionCoordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@@ -162,11 +162,11 @@ public final class Sector {
|
||||
* Moves the {@link Entity} that was in the specified {@code old} {@link Position}, to the current position of the
|
||||
* Entity.
|
||||
* <p>
|
||||
* Both the {@code old} and current positions of the Entity must belong to this sector.
|
||||
* Both the {@code old} and current positions of the Entity must belong to this Region.
|
||||
*
|
||||
* @param old The old position of the Entity.
|
||||
* @param entity The Entity to move.
|
||||
* @throws IllegalArgumentException If either of the positions do not belong to this sector.
|
||||
* @throws IllegalArgumentException If either of the positions do not belong to this Region.
|
||||
*/
|
||||
public void moveEntity(Position old, Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
@@ -176,30 +176,30 @@ public final class Sector {
|
||||
Set<Entity> local = entities.get(old);
|
||||
|
||||
if (local == null || !local.remove(entity)) {
|
||||
throw new IllegalArgumentException("Entity belongs in this sector (" + this + ") but does not exist.");
|
||||
throw new IllegalArgumentException("Entity belongs in this Region (" + this + ") but does not exist.");
|
||||
}
|
||||
|
||||
local = entities.computeIfAbsent(position, key -> new HashSet<>(DEFAULT_SET_SIZE));
|
||||
|
||||
local.add(entity);
|
||||
notifyListeners(entity, SectorOperation.MOVE);
|
||||
notifyListeners(entity, RegionOperation.MOVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the {@link SectorListener}s registered to this sector that an update has occurred.
|
||||
* Notifies the {@link RegionListener}s registered to this Region that an update has occurred.
|
||||
*
|
||||
* @param entity The {@link Entity} that was updated.
|
||||
* @param operation The {@link SectorOperation} that occurred.
|
||||
* @param operation The {@link RegionOperation} that occurred.
|
||||
*/
|
||||
public void notifyListeners(Entity entity, SectorOperation operation) {
|
||||
public void notifyListeners(Entity entity, RegionOperation operation) {
|
||||
listeners.forEach(listener -> listener.execute(this, entity, operation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link Entity} from this sector.
|
||||
* Removes a {@link Entity} from this Region.
|
||||
*
|
||||
* @param entity The Entity.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this sector, or if it was never added.
|
||||
* @throws IllegalArgumentException If the Entity does not belong in this Region, or if it was never added.
|
||||
*/
|
||||
public void removeEntity(Entity entity) {
|
||||
Position position = entity.getPosition();
|
||||
@@ -208,10 +208,10 @@ public final class Sector {
|
||||
Set<Entity> local = entities.get(position);
|
||||
|
||||
if (local == null || !local.remove(entity)) {
|
||||
throw new IllegalArgumentException("Entity belongs in this sector (" + this + ") but does not exist.");
|
||||
throw new IllegalArgumentException("Entity belongs in this Region (" + this + ") but does not exist.");
|
||||
}
|
||||
|
||||
notifyListeners(entity, SectorOperation.REMOVE);
|
||||
notifyListeners(entity, RegionOperation.REMOVE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,7 +227,7 @@ public final class Sector {
|
||||
CollisionMatrix matrix = matrices[position.getHeight()];
|
||||
int x = position.getX(), y = position.getY();
|
||||
|
||||
return !matrix.untraversable(x % SECTOR_SIZE, y % SECTOR_SIZE, entity, direction);
|
||||
return !matrix.untraversable(x % REGION_SIZE, y % REGION_SIZE, entity, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,13 +236,14 @@ public final class Sector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the specified {@link Position} is included in this sector.
|
||||
* Checks that the specified {@link Position} is included in this Region.
|
||||
*
|
||||
* @param position The position.
|
||||
* @throws IllegalArgumentException If the specified position is not included in this sector.
|
||||
* @throws IllegalArgumentException If the specified position is not included in this Region.
|
||||
*/
|
||||
private void checkPosition(Position position) {
|
||||
Preconditions.checkArgument(coordinates.equals(SectorCoordinates.fromPosition(position)), "Position is not included in this sector.");
|
||||
Preconditions.checkArgument(coordinates.equals(RegionCoordinates.fromPosition(position)),
|
||||
"Position is not included in this Region.");
|
||||
}
|
||||
|
||||
}
|
||||
+15
-15
@@ -5,49 +5,49 @@ import org.apollo.game.model.Position;
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
/**
|
||||
* An immutable class representing the coordinates of a sector, where the coordinates ({@code x, y}) are the top-left of
|
||||
* the sector.
|
||||
* An immutable class representing the coordinates of a region, where the coordinates ({@code x, y}) are the top-left of
|
||||
* the region.
|
||||
*
|
||||
* @author Graham
|
||||
* @author Major
|
||||
*/
|
||||
public final class SectorCoordinates {
|
||||
public final class RegionCoordinates {
|
||||
|
||||
/**
|
||||
* Gets a pair of sector coordinates from a {@link Position}.
|
||||
* Gets a pair of region coordinates from a {@link Position}.
|
||||
*
|
||||
* @param position The position.
|
||||
* @return The sector coordinates.
|
||||
* @return The region coordinates.
|
||||
*/
|
||||
public static SectorCoordinates fromPosition(Position position) {
|
||||
return new SectorCoordinates(position.getTopLeftSectorX(), position.getTopLeftSectorY());
|
||||
public static RegionCoordinates fromPosition(Position position) {
|
||||
return new RegionCoordinates(position.getTopLeftRegionX(), position.getTopLeftRegionY());
|
||||
}
|
||||
|
||||
/**
|
||||
* The x coordinate of this sector.
|
||||
* The x coordinate of this region.
|
||||
*/
|
||||
private final int x;
|
||||
|
||||
/**
|
||||
* The y coordinate of this sector.
|
||||
* The y coordinate of this region.
|
||||
*/
|
||||
private final int y;
|
||||
|
||||
/**
|
||||
* Creates the sector coordinates.
|
||||
* Creates the RegionCoordinates.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
public SectorCoordinates(int x, int y) {
|
||||
public RegionCoordinates(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof SectorCoordinates) {
|
||||
SectorCoordinates other = (SectorCoordinates) obj;
|
||||
if (obj instanceof RegionCoordinates) {
|
||||
RegionCoordinates other = (RegionCoordinates) obj;
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class SectorCoordinates {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x coordinate (equivalent to the {@link Position#getTopLeftSectorX()} of a position within this sector).
|
||||
* Gets the x coordinate (equivalent to the {@link Position#getTopLeftRegionX()} of a position within this region).
|
||||
*
|
||||
* @return The x coordinate.
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ public final class SectorCoordinates {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y coordinate (equivalent to the {@link Position#getTopLeftSectorY()} of a position within this sector).
|
||||
* Gets the y coordinate (equivalent to the {@link Position#getTopLeftRegionY()} of a position within this region).
|
||||
*
|
||||
* @return The y coordinate.
|
||||
*/
|
||||
+6
-6
@@ -3,21 +3,21 @@ package org.apollo.game.model.area;
|
||||
import org.apollo.game.model.entity.Entity;
|
||||
|
||||
/**
|
||||
* A class that should be implemented by listeners that execute actions when an entity is added or removed from the
|
||||
* sector.
|
||||
* A class that should be implemented by listeners that execute actions when an entity is added, moved, or removed from
|
||||
* a region.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface SectorListener {
|
||||
public interface RegionListener {
|
||||
|
||||
/**
|
||||
* Executes the action for this listener.
|
||||
*
|
||||
* @param sector The {@link Sector} that was updated.
|
||||
* @param region The {@link Region} that was updated.
|
||||
* @param entity The affected {@link Entity}.
|
||||
* @param operation The type of {@link SectorOperation}.
|
||||
* @param operation The type of {@link RegionOperation}.
|
||||
*/
|
||||
public abstract void execute(Sector sector, Entity entity, SectorOperation operation);
|
||||
public abstract void execute(Region region, Entity entity, RegionOperation operation);
|
||||
|
||||
}
|
||||
+5
-5
@@ -1,24 +1,24 @@
|
||||
package org.apollo.game.model.area;
|
||||
|
||||
/**
|
||||
* An operation that can be performed by a sector, used by {@link SectorListener}s to differentiate between operations.
|
||||
* An operation that can be performed by a region, used by {@link RegionListener}s to differentiate between operations.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public enum SectorOperation {
|
||||
public enum RegionOperation {
|
||||
|
||||
/**
|
||||
* The add operation, when an entity has been added to a sector.
|
||||
* The add operation, when an entity has been added to a region.
|
||||
*/
|
||||
ADD,
|
||||
|
||||
/**
|
||||
* The move operation, when an entity has moved positions, but is still in the same sector.
|
||||
* The move operation, when an entity has moved positions, but is still in the same region.
|
||||
*/
|
||||
MOVE,
|
||||
|
||||
/**
|
||||
* The remove operation, when an entity has been removed from a sector.
|
||||
* The remove operation, when an entity has been removed from a region.
|
||||
*/
|
||||
REMOVE;
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package org.apollo.game.model.area;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apollo.game.model.Position;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* A repository of {@link Region}s, backed by a {@link HashMap} of {@link RegionCoordinates} that correspond to their
|
||||
* appropriate regions.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class RegionRepository {
|
||||
|
||||
/**
|
||||
* Returns an immutable RegionRepository, where {@link Region}s cannot be added or removed.
|
||||
* <p>
|
||||
* Note that, internally, regions are added lazily (i.e. only when necessary). As such, repositories are (again,
|
||||
* internally) not actually immutable, so do not rely on such behaviour.
|
||||
*
|
||||
* @return The RegionRepository.
|
||||
*/
|
||||
public static RegionRepository immutable() {
|
||||
return new RegionRepository(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mutable RegionRepository, where {@link Region}s may be removed.
|
||||
*
|
||||
* @return The RegionRepository.
|
||||
*/
|
||||
public static RegionRepository mutable() {
|
||||
return new RegionRepository(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not regions can be removed from this repository.
|
||||
*/
|
||||
private final boolean permitRemoval;
|
||||
|
||||
/**
|
||||
* The map of RegionCoordinates that correspond to the appropriate Regions.
|
||||
*/
|
||||
private final Map<RegionCoordinates, Region> regions = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Creates a new RegionRepository.
|
||||
*
|
||||
* @param permitRemoval If removal (of {@link Region}s) from this repository should be permitted.
|
||||
*/
|
||||
private RegionRepository(boolean permitRemoval) {
|
||||
this.permitRemoval = permitRemoval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a {@link Region} to the repository.
|
||||
*
|
||||
* @param region The Region.
|
||||
* @throws IllegalArgumentException If the provided Region is null.
|
||||
* @throws UnsupportedOperationException If the coordinates of the provided Region are already mapped (and hence the
|
||||
* existing Region would be replaced), and removal of regions is not permitted.
|
||||
*/
|
||||
private void add(Region region) {
|
||||
Preconditions.checkNotNull(region, "Region cannot be null.");
|
||||
if (regions.containsKey(region.getCoordinates()) && !permitRemoval) {
|
||||
throw new UnsupportedOperationException("Cannot add a Region with the same coordinates as an existing Region.");
|
||||
}
|
||||
|
||||
regions.put(region.getCoordinates(), region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the supplied value (i.e. the {@link Region}) has a mapping.
|
||||
*
|
||||
* @param region The Region.
|
||||
* @return {@code true} if this repository contains an entry with {@link RegionCoordinates} equal to the specified
|
||||
* Region, otherwise {@code false}.
|
||||
*/
|
||||
public boolean contains(Region region) {
|
||||
return contains(region.getCoordinates());
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the supplied key (i.e. the {@link RegionCoordinates}) has a mapping.
|
||||
*
|
||||
* @param coordinates The coordinates.
|
||||
* @return {@code true} if the key is already mapped to a value (i.e. a {@link Region}), otherwise {@code false}.
|
||||
*/
|
||||
public boolean contains(RegionCoordinates coordinates) {
|
||||
return regions.containsKey(coordinates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Region} that contains the specified {@link Position}. If the Region does not exist in this
|
||||
* repository then a new Region is created, submitted to the repository, and returned.
|
||||
*
|
||||
* @param position The position.
|
||||
* @return The Region.
|
||||
*/
|
||||
public Region fromPosition(Position position) {
|
||||
return get(RegionCoordinates.fromPosition(position));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Region} with the specified {@link RegionCoordinates}. If the Region does not exist in this
|
||||
* repository then a new Region is created, submitted to the repository, and returned.
|
||||
*
|
||||
* @param coordinates The RegionCoordinates.
|
||||
* @return The Region. Will never be null.
|
||||
*/
|
||||
public Region get(RegionCoordinates coordinates) {
|
||||
Region region = regions.get(coordinates);
|
||||
if (region == null) {
|
||||
region = new Region(coordinates);
|
||||
add(region);
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a shallow copy of the {@link List} of {@link Region}s. This will be an {@link ImmutableList}.
|
||||
*
|
||||
* @return The List.
|
||||
*/
|
||||
public List<Region> getRegions() {
|
||||
return ImmutableList.copyOf(regions.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link Region} from the repository, if permitted. This method removes the entry that has a key
|
||||
* identical to the {@link RegionCoordinates} of the specified Region.
|
||||
*
|
||||
* @param region The Region to remove.
|
||||
* @return {@code true} if the specified Region existed and was removed, {@code false} if not.
|
||||
* @throws UnsupportedOperationException If this method is called on a repository that does not permit removal.
|
||||
*/
|
||||
public boolean remove(Region region) {
|
||||
if (!permitRemoval) {
|
||||
throw new UnsupportedOperationException("Cannot remove regions from this repository.");
|
||||
}
|
||||
|
||||
return regions.remove(region.getCoordinates()) != null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package org.apollo.game.model.area;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apollo.game.model.Position;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* A repository of {@link Sector}s, backed by a {@link HashMap} of {@link SectorCoordinates} that correspond to their
|
||||
* appropriate sectors.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public final class SectorRepository {
|
||||
|
||||
/**
|
||||
* Returns an immutable sector repository, where {@link Sector}s cannot be added or removed.
|
||||
* <p>
|
||||
* Note that, internally, sectors are added lazily (i.e. only when necessary). As such, repositories are (again,
|
||||
* internally) not actually immutable, so do not rely on such behaviour.
|
||||
*
|
||||
* @return The sector repository.
|
||||
*/
|
||||
public static SectorRepository immutable() {
|
||||
return new SectorRepository(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mutable sector repository, where {@link Sector}s may be removed.
|
||||
*
|
||||
* @return The sector repository.
|
||||
*/
|
||||
public static SectorRepository mutable() {
|
||||
return new SectorRepository(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not sectors can be removed from this repository.
|
||||
*/
|
||||
private final boolean permitRemoval;
|
||||
|
||||
/**
|
||||
* The map of sector coordinates that correspond to the appropriate sectors.
|
||||
*/
|
||||
private final Map<SectorCoordinates, Sector> sectors = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Creates a new sector repository.
|
||||
*
|
||||
* @param permitRemoval If removal (of {@link Sector}s) from this repository should be permitted.
|
||||
*/
|
||||
private SectorRepository(boolean permitRemoval) {
|
||||
this.permitRemoval = permitRemoval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a {@link Sector} to the repository.
|
||||
*
|
||||
* @param sector The sector.
|
||||
* @throws IllegalArgumentException If the provided sector is null.
|
||||
* @throws UnsupportedOperationException If the coordinates of the provided sector are already mapped (and hence the
|
||||
* existing sector would be replaced), and removal of sectors is not permitted.
|
||||
*/
|
||||
private void add(Sector sector) {
|
||||
Preconditions.checkNotNull(sector, "Sector cannot be null.");
|
||||
if (sectors.containsKey(sector.getCoordinates()) && !permitRemoval) {
|
||||
throw new UnsupportedOperationException("Cannot add a sector with the same coordinates as an existing sector.");
|
||||
}
|
||||
|
||||
sectors.put(sector.getCoordinates(), sector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the supplied value (i.e. the {@link Sector}) has a mapping.
|
||||
*
|
||||
* @param sector The sector.
|
||||
* @return {@code true} if this repository contains an entry with {@link SectorCoordinates} equal to the specified
|
||||
* sector, otherwise {@code false}.
|
||||
*/
|
||||
public boolean contains(Sector sector) {
|
||||
return contains(sector.getCoordinates());
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the supplied key (i.e. the {@link SectorCoordinates}) has a mapping.
|
||||
*
|
||||
* @param coordinates The coordinates.
|
||||
* @return {@code true} if the key is already mapped to a value (i.e. a {@link Sector}), otherwise {@code false}.
|
||||
*/
|
||||
public boolean contains(SectorCoordinates coordinates) {
|
||||
return sectors.containsKey(coordinates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Sector} that contains the specified {@link Position}. If the sector does not exist in this
|
||||
* repository then a new sector is created, submitted to the repository, and returned.
|
||||
*
|
||||
* @param position The position.
|
||||
* @return The sector.
|
||||
*/
|
||||
public Sector fromPosition(Position position) {
|
||||
return get(SectorCoordinates.fromPosition(position));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Sector} with the specified {@link SectorCoordinates}. If the sector does not exist in this
|
||||
* repository then a new sector is created, submitted to the repository, and returned.
|
||||
*
|
||||
* @param coordinates The coordinates.
|
||||
* @return The sector. Will never be null.
|
||||
*/
|
||||
public Sector get(SectorCoordinates coordinates) {
|
||||
Sector sector = sectors.get(coordinates);
|
||||
if (sector == null) {
|
||||
sector = new Sector(coordinates);
|
||||
add(sector);
|
||||
}
|
||||
|
||||
return sector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a shallow copy of the {@link List} of {@link Sector}s. This will be an {@link ImmutableList}.
|
||||
*
|
||||
* @return The list.
|
||||
*/
|
||||
public List<Sector> getSectors() {
|
||||
return ImmutableList.copyOf(sectors.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a {@link Sector} from the repository, if permitted. This method removes the entry that has a key
|
||||
* identical to the {@link SectorCoordinates} of the specified sector.
|
||||
*
|
||||
* @param sector The sector to remove.
|
||||
* @return Whether or not the sector was removed.
|
||||
* @throws UnsupportedOperationException If this method is called on a repository that does not permit removal.
|
||||
*/
|
||||
public boolean remove(Sector sector) {
|
||||
if (!permitRemoval) {
|
||||
throw new UnsupportedOperationException("Cannot remove sectors from this repository.");
|
||||
}
|
||||
|
||||
return sectors.remove(sector.getCoordinates()) != null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
/**
|
||||
* Contains classes which represent in-game sectors - blocks of 8x8 tiles used to store ground items, temporary objects,
|
||||
* etc. efficiently.
|
||||
* Contains region-related classes.
|
||||
*/
|
||||
package org.apollo.game.model.area;
|
||||
@@ -11,8 +11,8 @@ import org.apollo.game.model.Direction;
|
||||
import org.apollo.game.model.Graphic;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.SectorRepository;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.area.RegionRepository;
|
||||
import org.apollo.game.model.def.NpcDefinition;
|
||||
import org.apollo.game.model.entity.attr.Attribute;
|
||||
import org.apollo.game.model.entity.attr.AttributeMap;
|
||||
@@ -433,14 +433,14 @@ public abstract class Mob extends Entity {
|
||||
// Intentionally ignore the Event result - accidentally terminating this method would break the entire server.
|
||||
|
||||
Position old = this.position;
|
||||
SectorRepository repository = World.getWorld().getSectorRepository();
|
||||
Sector current = repository.fromPosition(old);
|
||||
RegionRepository repository = World.getWorld().getRegionRepository();
|
||||
Region current = repository.fromPosition(old);
|
||||
|
||||
if (position.inside(current)) {
|
||||
this.position = position;
|
||||
current.moveEntity(old, this);
|
||||
} else {
|
||||
Sector next = repository.fromPosition(position);
|
||||
Region next = repository.fromPosition(position);
|
||||
current.removeEntity(this);
|
||||
this.position = position; // addEntity relies on the position being updated, so do that first.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.Optional;
|
||||
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.def.NpcDefinition;
|
||||
import org.apollo.game.sync.block.SynchronizationBlock;
|
||||
|
||||
@@ -127,9 +127,9 @@ public final class Npc extends Mob {
|
||||
*/
|
||||
private void init() {
|
||||
// This has to be here instead of in Mob#init because of ordering issues - the Npc cannot be added to the
|
||||
// sector until their credentials have been set, which is only done after the super constructors are called.
|
||||
Sector sector = World.getWorld().getSectorRepository().get(position.getSectorCoordinates());
|
||||
sector.addEntity(this);
|
||||
// region until their credentials have been set, which is only done after the super constructors are called.
|
||||
Region region = World.getWorld().getRegionRepository().get(position.getRegionCoordinates());
|
||||
region.addEntity(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import org.apollo.game.message.impl.UpdateRunEnergyMessage;
|
||||
import org.apollo.game.model.Appearance;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.entity.attr.Attribute;
|
||||
import org.apollo.game.model.entity.attr.AttributeDefinition;
|
||||
import org.apollo.game.model.entity.attr.AttributeMap;
|
||||
@@ -131,9 +131,9 @@ public final class Player extends Mob {
|
||||
private boolean isSkulled = false;
|
||||
|
||||
/**
|
||||
* The centre of the last sector the client has loaded.
|
||||
* The centre of the last region the client has loaded.
|
||||
*/
|
||||
private transient Position lastKnownSector;
|
||||
private transient Position lastKnownRegion;
|
||||
|
||||
/**
|
||||
* The MembershipStatus of this Player.
|
||||
@@ -166,9 +166,9 @@ public final class Player extends Mob {
|
||||
private ScreenBrightness screenBrightness = ScreenBrightness.NORMAL;
|
||||
|
||||
/**
|
||||
* A flag indicating if the sector changed in the last cycle.
|
||||
* A flag indicating if the region changed in the last cycle.
|
||||
*/
|
||||
private transient boolean sectorChanged = false;
|
||||
private transient boolean regionChanged = false;
|
||||
|
||||
/**
|
||||
* The {@link GameSession} currently attached to this {@link Player}.
|
||||
@@ -399,12 +399,12 @@ public final class Player extends Mob {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last known sector.
|
||||
* Gets the last known region.
|
||||
*
|
||||
* @return The last known sector, or {@code null} if the player has never known a sector.
|
||||
* @return The last known region, or {@code null} if the player has never known a region.
|
||||
*/
|
||||
public Position getLastKnownSector() {
|
||||
return lastKnownSector;
|
||||
public Position getLastKnownRegion() {
|
||||
return lastKnownRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -505,21 +505,21 @@ public final class Player extends Mob {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this player has ever known a sector.
|
||||
* Checks if this player has ever known a region.
|
||||
*
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
public boolean hasLastKnownSector() {
|
||||
return lastKnownSector != null;
|
||||
public boolean hasLastKnownRegion() {
|
||||
return lastKnownRegion != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the sector has changed.
|
||||
* Checks if the region has changed.
|
||||
*
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
public boolean hasSectorChanged() {
|
||||
return sectorChanged;
|
||||
public boolean hasRegionChanged() {
|
||||
return regionChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -811,12 +811,12 @@ public final class Player extends Mob {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last known sector.
|
||||
* Sets the last known region.
|
||||
*
|
||||
* @param lastKnownSector The last known sector.
|
||||
* @param lastKnownRegion The last known region.
|
||||
*/
|
||||
public void setLastKnownSector(Position lastKnownSector) {
|
||||
this.lastKnownSector = lastKnownSector;
|
||||
public void setLastKnownRegion(Position lastKnownRegion) {
|
||||
this.lastKnownRegion = lastKnownRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -866,12 +866,12 @@ public final class Player extends Mob {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sector changed flag.
|
||||
* Sets the region changed flag.
|
||||
*
|
||||
* @param sectorChanged A flag indicating if the sector has changed.
|
||||
* @param regionChanged A flag indicating if the region has changed.
|
||||
*/
|
||||
public void setSectorChanged(boolean sectorChanged) {
|
||||
this.sectorChanged = sectorChanged;
|
||||
public void setRegionChanged(boolean regionChanged) {
|
||||
this.regionChanged = regionChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -954,9 +954,9 @@ public final class Player extends Mob {
|
||||
initSkills();
|
||||
|
||||
// This has to be here instead of in Mob#init because of ordering issues - the player cannot be added to the
|
||||
// sector until their credentials have been set, which is only done after the super constructors are called.
|
||||
Sector sector = World.getWorld().getSectorRepository().get(position.getSectorCoordinates());
|
||||
sector.addEntity(this);
|
||||
// region until their credentials have been set, which is only done after the super constructors are called.
|
||||
Region region = World.getWorld().getRegionRepository().get(position.getRegionCoordinates());
|
||||
region.addEntity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -969,7 +969,8 @@ public final class Player extends Mob {
|
||||
|
||||
InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this, SynchronizationInventoryListener.INVENTORY_ID);
|
||||
InventoryListener syncBankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID);
|
||||
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this, SynchronizationInventoryListener.EQUIPMENT_ID);
|
||||
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this,
|
||||
SynchronizationInventoryListener.EQUIPMENT_ID);
|
||||
|
||||
inventory.addListener(syncInventoryListener);
|
||||
inventory.addListener(fullInventoryListener);
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.Optional;
|
||||
import org.apollo.game.model.Direction;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.SectorRepository;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.area.RegionRepository;
|
||||
import org.apollo.game.model.entity.Entity.EntityType;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
@@ -20,9 +20,9 @@ import com.google.common.base.Preconditions;
|
||||
abstract class PathfindingAlgorithm {
|
||||
|
||||
/**
|
||||
* The repository of Sectors.
|
||||
* The repository of Regions.
|
||||
*/
|
||||
private static final SectorRepository REPOSITORY = World.getWorld().getSectorRepository();
|
||||
private static final RegionRepository REPOSITORY = World.getWorld().getRegionRepository();
|
||||
|
||||
/**
|
||||
* Finds a valid path from the origin {@link Position} to the target one.
|
||||
@@ -77,8 +77,8 @@ abstract class PathfindingAlgorithm {
|
||||
}
|
||||
|
||||
Position next = new Position(x, y, height);
|
||||
Sector sector = REPOSITORY.get(next.getSectorCoordinates());
|
||||
if (sector.traversable(next, EntityType.NPC, direction) && (positions.length == 0 || inside(next, positions))) {
|
||||
Region region = REPOSITORY.get(next.getRegionCoordinates());
|
||||
if (region.traversable(next, EntityType.NPC, direction) && (positions.length == 0 || inside(next, positions))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public final class PlayerSynchronizationTask extends SynchronizationTask {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Position lastKnownSector = player.getLastKnownSector();
|
||||
boolean sectorChanged = player.hasSectorChanged();
|
||||
Position lastKnownRegion = player.getLastKnownRegion();
|
||||
boolean regionChanged = player.hasRegionChanged();
|
||||
|
||||
SynchronizationSegment segment;
|
||||
SynchronizationBlockSet blockSet = player.getBlockSet();
|
||||
@@ -58,7 +58,7 @@ public final class PlayerSynchronizationTask extends SynchronizationTask {
|
||||
blockSet.remove(ChatBlock.class);
|
||||
}
|
||||
|
||||
if (player.isTeleporting() || player.hasSectorChanged()) {
|
||||
if (player.isTeleporting() || player.hasRegionChanged()) {
|
||||
segment = new TeleportSegment(blockSet, player.getPosition());
|
||||
} else {
|
||||
segment = new MovementSegment(blockSet, player.getDirections());
|
||||
@@ -105,7 +105,7 @@ public final class PlayerSynchronizationTask extends SynchronizationTask {
|
||||
}
|
||||
}
|
||||
|
||||
PlayerSynchronizationMessage message = new PlayerSynchronizationMessage(lastKnownSector, player.getPosition(), sectorChanged, segment, oldLocalPlayers, segments);
|
||||
PlayerSynchronizationMessage message = new PlayerSynchronizationMessage(lastKnownRegion, player.getPosition(), regionChanged, segment, oldLocalPlayers, segments);
|
||||
player.send(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public final class PostPlayerSynchronizationTask extends SynchronizationTask {
|
||||
@Override
|
||||
public void run() {
|
||||
player.setTeleporting(false);
|
||||
player.setSectorChanged(false);
|
||||
player.setRegionChanged(false);
|
||||
player.resetBlockSet();
|
||||
if (!player.isExcessivePlayersSet()) {
|
||||
player.incrementViewingDistance();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.apollo.game.sync.task;
|
||||
|
||||
import org.apollo.game.message.impl.SectorChangeMessage;
|
||||
import org.apollo.game.message.impl.RegionChangeMessage;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.entity.Player;
|
||||
|
||||
@@ -26,13 +26,13 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a sector update is required.
|
||||
* Checks if a region update is required.
|
||||
*
|
||||
* @return {@code true} if so, {@code false} otherwise.
|
||||
*/
|
||||
private boolean isSectorUpdateRequired() {
|
||||
private boolean isRegionUpdateRequired() {
|
||||
Position current = player.getPosition();
|
||||
Position last = player.getLastKnownSector();
|
||||
Position last = player.getLastKnownRegion();
|
||||
|
||||
int deltaX = current.getLocalX(last);
|
||||
int deltaY = current.getLocalY(last);
|
||||
@@ -48,12 +48,12 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
player.resetViewingDistance();
|
||||
}
|
||||
|
||||
if (!player.hasLastKnownSector() || isSectorUpdateRequired()) {
|
||||
player.setSectorChanged(true);
|
||||
if (!player.hasLastKnownRegion() || isRegionUpdateRequired()) {
|
||||
player.setRegionChanged(true);
|
||||
|
||||
Position position = player.getPosition();
|
||||
player.setLastKnownSector(position);
|
||||
player.send(new SectorChangeMessage(position));
|
||||
player.setLastKnownRegion(position);
|
||||
player.send(new RegionChangeMessage(position));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -395,10 +395,10 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
|
||||
builder.putBits(1, 1);
|
||||
builder.putBits(2, 3);
|
||||
builder.putBits(2, position.getHeight());
|
||||
builder.putBits(1, message.hasSectorChanged() ? 0 : 1);
|
||||
builder.putBits(1, message.hasRegionChanged() ? 0 : 1);
|
||||
builder.putBits(1, updateRequired ? 1 : 0);
|
||||
builder.putBits(7, position.getLocalY(message.getLastKnownSector()));
|
||||
builder.putBits(7, position.getLocalX(message.getLastKnownSector()));
|
||||
builder.putBits(7, position.getLocalY(message.getLastKnownRegion()));
|
||||
builder.putBits(7, position.getLocalX(message.getLastKnownRegion()));
|
||||
} else if (seg.getType() == SegmentType.RUN) {
|
||||
Direction[] directions = ((MovementSegment) seg).getDirections();
|
||||
builder.putBits(1, 1);
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
package org.apollo.net.release.r317;
|
||||
|
||||
import org.apollo.game.message.impl.SectorChangeMessage;
|
||||
import org.apollo.game.message.impl.RegionChangeMessage;
|
||||
import org.apollo.net.codec.game.DataTransformation;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
@@ -8,17 +8,17 @@ import org.apollo.net.codec.game.GamePacketBuilder;
|
||||
import org.apollo.net.release.MessageEncoder;
|
||||
|
||||
/**
|
||||
* A {@link MessageEncoder} for the {@link SectorChangeMessage}.
|
||||
* A {@link MessageEncoder} for the {@link RegionChangeMessage}.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public final class SectorChangeMessageEncoder extends MessageEncoder<SectorChangeMessage> {
|
||||
public final class RegionChangeMessageEncoder extends MessageEncoder<RegionChangeMessage> {
|
||||
|
||||
@Override
|
||||
public GamePacket encode(SectorChangeMessage message) {
|
||||
public GamePacket encode(RegionChangeMessage message) {
|
||||
GamePacketBuilder builder = new GamePacketBuilder(73);
|
||||
builder.put(DataType.SHORT, DataTransformation.ADD, message.getPosition().getCentralSectorX());
|
||||
builder.put(DataType.SHORT, message.getPosition().getCentralSectorY());
|
||||
builder.put(DataType.SHORT, DataTransformation.ADD, message.getPosition().getCentralRegionX());
|
||||
builder.put(DataType.SHORT, message.getPosition().getCentralRegionY());
|
||||
return builder.toGamePacket();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.apollo.game.message.impl.PositionMessage;
|
||||
import org.apollo.game.message.impl.PrivacyOptionMessage;
|
||||
import org.apollo.game.message.impl.RemoveObjectMessage;
|
||||
import org.apollo.game.message.impl.RemoveTileItemMessage;
|
||||
import org.apollo.game.message.impl.SectorChangeMessage;
|
||||
import org.apollo.game.message.impl.RegionChangeMessage;
|
||||
import org.apollo.game.message.impl.SendFriendMessage;
|
||||
import org.apollo.game.message.impl.SendObjectMessage;
|
||||
import org.apollo.game.message.impl.ServerChatMessage;
|
||||
@@ -173,7 +173,7 @@ public final class Release317 extends Release {
|
||||
|
||||
// register encoders
|
||||
register(IdAssignmentMessage.class, new IdAssignmentMessageEncoder());
|
||||
register(SectorChangeMessage.class, new SectorChangeMessageEncoder());
|
||||
register(RegionChangeMessage.class, new RegionChangeMessageEncoder());
|
||||
register(ServerChatMessage.class, new ServerMessageMessageEncoder());
|
||||
register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder());
|
||||
register(OpenInterfaceMessage.class, new OpenInterfaceMessageEncoder());
|
||||
|
||||
@@ -394,10 +394,10 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
|
||||
Position pos = ((TeleportSegment) seg).getDestination();
|
||||
builder.putBits(1, 1);
|
||||
builder.putBits(2, 3);
|
||||
builder.putBits(1, message.hasSectorChanged() ? 0 : 1);
|
||||
builder.putBits(1, message.hasRegionChanged() ? 0 : 1);
|
||||
builder.putBits(2, pos.getHeight());
|
||||
builder.putBits(7, pos.getLocalY(message.getLastKnownSector()));
|
||||
builder.putBits(7, pos.getLocalX(message.getLastKnownSector()));
|
||||
builder.putBits(7, pos.getLocalY(message.getLastKnownRegion()));
|
||||
builder.putBits(7, pos.getLocalX(message.getLastKnownRegion()));
|
||||
builder.putBits(1, updateRequired ? 1 : 0);
|
||||
} else if (seg.getType() == SegmentType.RUN) {
|
||||
Direction[] directions = ((MovementSegment) seg).getDirections();
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
package org.apollo.net.release.r377;
|
||||
|
||||
import org.apollo.game.message.impl.SectorChangeMessage;
|
||||
import org.apollo.game.message.impl.RegionChangeMessage;
|
||||
import org.apollo.net.codec.game.DataOrder;
|
||||
import org.apollo.net.codec.game.DataTransformation;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
@@ -9,17 +9,17 @@ import org.apollo.net.codec.game.GamePacketBuilder;
|
||||
import org.apollo.net.release.MessageEncoder;
|
||||
|
||||
/**
|
||||
* A {@link MessageEncoder} for the {@link SectorChangeMessage}.
|
||||
* A {@link MessageEncoder} for the {@link RegionChangeMessage}.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public final class SectorChangeMessageEncoder extends MessageEncoder<SectorChangeMessage> {
|
||||
public final class RegionChangeMessageEncoder extends MessageEncoder<RegionChangeMessage> {
|
||||
|
||||
@Override
|
||||
public GamePacket encode(SectorChangeMessage message) {
|
||||
public GamePacket encode(RegionChangeMessage message) {
|
||||
GamePacketBuilder builder = new GamePacketBuilder(222);
|
||||
builder.put(DataType.SHORT, message.getPosition().getCentralSectorY());
|
||||
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getPosition().getCentralSectorX());
|
||||
builder.put(DataType.SHORT, message.getPosition().getCentralRegionY());
|
||||
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getPosition().getCentralRegionX());
|
||||
return builder.toGamePacket();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.apollo.game.message.impl.PositionMessage;
|
||||
import org.apollo.game.message.impl.PrivacyOptionMessage;
|
||||
import org.apollo.game.message.impl.RemoveObjectMessage;
|
||||
import org.apollo.game.message.impl.RemoveTileItemMessage;
|
||||
import org.apollo.game.message.impl.SectorChangeMessage;
|
||||
import org.apollo.game.message.impl.RegionChangeMessage;
|
||||
import org.apollo.game.message.impl.SendFriendMessage;
|
||||
import org.apollo.game.message.impl.SendObjectMessage;
|
||||
import org.apollo.game.message.impl.ServerChatMessage;
|
||||
@@ -169,7 +169,7 @@ public final class Release377 extends Release {
|
||||
|
||||
// register encoders
|
||||
register(IdAssignmentMessage.class, new IdAssignmentMessageEncoder());
|
||||
register(SectorChangeMessage.class, new SectorChangeMessageEncoder());
|
||||
register(RegionChangeMessage.class, new RegionChangeMessageEncoder());
|
||||
register(ServerChatMessage.class, new ServerMessageMessageEncoder());
|
||||
register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder());
|
||||
register(OpenInterfaceMessage.class, new OpenInterfaceMessageEncoder());
|
||||
|
||||
Reference in New Issue
Block a user