Search in sources :

Example 1 with RegionChangeMessage

use of org.apollo.game.message.impl.RegionChangeMessage in project apollo by apollo-rsps.

the class PrePlayerSynchronizationTask method run.

@Override
public void run() {
    Position old = player.getPosition();
    player.getWalkingQueue().pulse();
    boolean local = true;
    if (player.isTeleporting()) {
        player.resetViewingDistance();
        local = false;
    }
    Position position = player.getPosition();
    if (!player.hasLastKnownRegion() || isRegionUpdateRequired()) {
        player.setRegionChanged(true);
        local = false;
        player.setLastKnownRegion(position);
        player.send(new RegionChangeMessage(position));
    }
    RegionRepository repository = player.getWorld().getRegionRepository();
    Set<RegionCoordinates> oldViewable = repository.fromPosition(old).getSurrounding();
    Set<RegionCoordinates> newViewable = repository.fromPosition(position).getSurrounding();
    Set<RegionCoordinates> differences = new HashSet<>(newViewable);
    differences.retainAll(oldViewable);
    Set<RegionCoordinates> full = new HashSet<>(newViewable);
    if (local) {
        full.removeAll(oldViewable);
    }
    sendUpdates(player.getLastKnownRegion(), differences, full);
}
Also used : RegionCoordinates(org.apollo.game.model.area.RegionCoordinates) Position(org.apollo.game.model.Position) RegionRepository(org.apollo.game.model.area.RegionRepository) RegionChangeMessage(org.apollo.game.message.impl.RegionChangeMessage) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 RegionChangeMessage (org.apollo.game.message.impl.RegionChangeMessage)1 Position (org.apollo.game.model.Position)1 RegionCoordinates (org.apollo.game.model.area.RegionCoordinates)1 RegionRepository (org.apollo.game.model.area.RegionRepository)1