Search in sources :

Example 1 with SynchronizationBlockSet

use of org.apollo.game.sync.block.SynchronizationBlockSet in project apollo by apollo-rsps.

the class NpcSynchronizationMessageEncoder method putBlocks.

/**
 * Puts the blocks for the specified segment.
 *
 * @param segment The segment.
 * @param builder The block builder.
 */
private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
    SynchronizationBlockSet blockSet = segment.getBlockSet();
    if (blockSet.size() > 0) {
        int mask = 0;
        if (blockSet.contains(AnimationBlock.class)) {
            mask |= 0x10;
        }
        if (blockSet.contains(HitUpdateBlock.class)) {
            mask |= 0x8;
        }
        if (blockSet.contains(GraphicBlock.class)) {
            mask |= 0x80;
        }
        if (blockSet.contains(InteractingMobBlock.class)) {
            mask |= 0x20;
        }
        if (blockSet.contains(ForceChatBlock.class)) {
            mask |= 0x1;
        }
        if (blockSet.contains(SecondaryHitUpdateBlock.class)) {
            mask |= 0x40;
        }
        if (blockSet.contains(TransformBlock.class)) {
            mask |= 0x2;
        }
        if (blockSet.contains(TurnToPositionBlock.class)) {
            mask |= 0x4;
        }
        builder.put(DataType.BYTE, mask);
        if (blockSet.contains(AnimationBlock.class)) {
            putAnimationBlock(blockSet.get(AnimationBlock.class), builder);
        }
        if (blockSet.contains(HitUpdateBlock.class)) {
            putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder);
        }
        if (blockSet.contains(GraphicBlock.class)) {
            putGraphicBlock(blockSet.get(GraphicBlock.class), builder);
        }
        if (blockSet.contains(InteractingMobBlock.class)) {
            putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder);
        }
        if (blockSet.contains(ForceChatBlock.class)) {
            putForceChatBlock(blockSet.get(ForceChatBlock.class), builder);
        }
        if (blockSet.contains(SecondaryHitUpdateBlock.class)) {
            putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder);
        }
        if (blockSet.contains(TransformBlock.class)) {
            putTransformBlock(blockSet.get(TransformBlock.class), builder);
        }
        if (blockSet.contains(TurnToPositionBlock.class)) {
            putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder);
        }
    }
}
Also used : AnimationBlock(org.apollo.game.sync.block.AnimationBlock) TransformBlock(org.apollo.game.sync.block.TransformBlock) TurnToPositionBlock(org.apollo.game.sync.block.TurnToPositionBlock) SecondaryHitUpdateBlock(org.apollo.game.sync.block.SecondaryHitUpdateBlock) ForceChatBlock(org.apollo.game.sync.block.ForceChatBlock) GraphicBlock(org.apollo.game.sync.block.GraphicBlock) InteractingMobBlock(org.apollo.game.sync.block.InteractingMobBlock) SecondaryHitUpdateBlock(org.apollo.game.sync.block.SecondaryHitUpdateBlock) HitUpdateBlock(org.apollo.game.sync.block.HitUpdateBlock) SynchronizationBlockSet(org.apollo.game.sync.block.SynchronizationBlockSet)

Example 2 with SynchronizationBlockSet

use of org.apollo.game.sync.block.SynchronizationBlockSet in project apollo by apollo-rsps.

the class PlayerSynchronizationTask method run.

@Override
public void run() {
    Position lastKnownRegion = player.getLastKnownRegion();
    boolean regionChanged = player.hasRegionChanged();
    int[] appearanceTickets = player.getAppearanceTickets();
    SynchronizationBlockSet blockSet = player.getBlockSet();
    if (blockSet.contains(ChatBlock.class)) {
        blockSet = blockSet.clone();
        blockSet.remove(ChatBlock.class);
    }
    Position position = player.getPosition();
    SynchronizationSegment segment = (player.isTeleporting() || player.hasRegionChanged()) ? new TeleportSegment(blockSet, position) : new MovementSegment(blockSet, player.getDirections());
    List<Player> localPlayers = player.getLocalPlayerList();
    int oldCount = localPlayers.size();
    List<SynchronizationSegment> segments = new ArrayList<>();
    int distance = player.getViewingDistance();
    for (Iterator<Player> iterator = localPlayers.iterator(); iterator.hasNext(); ) {
        Player other = iterator.next();
        if (removeable(position, distance, other)) {
            iterator.remove();
            segments.add(new RemoveMobSegment());
        } else {
            segments.add(new MovementSegment(other.getBlockSet(), other.getDirections()));
        }
    }
    int added = 0, count = localPlayers.size();
    RegionRepository repository = player.getWorld().getRegionRepository();
    Region current = repository.fromPosition(position);
    Set<RegionCoordinates> regions = current.getSurrounding();
    regions.add(current.getCoordinates());
    Stream<Player> players = regions.stream().map(repository::get).flatMap(region -> region.getEntities(EntityType.PLAYER));
    Iterator<Player> iterator = players.iterator();
    while (iterator.hasNext()) {
        if (count >= MAXIMUM_LOCAL_PLAYERS) {
            player.flagExcessivePlayers();
            break;
        } else if (added >= NEW_PLAYERS_PER_CYCLE) {
            break;
        }
        Player other = iterator.next();
        Position local = other.getPosition();
        if (other != player && local.isWithinDistance(position, distance) && !localPlayers.contains(other)) {
            localPlayers.add(other);
            count++;
            added++;
            blockSet = other.getBlockSet();
            int index = other.getIndex();
            if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index - 1, other.getAppearanceTicket())) {
                blockSet = blockSet.clone();
                blockSet.add(SynchronizationBlock.createAppearanceBlock(other));
            }
            segments.add(new AddPlayerSegment(blockSet, index, local));
        }
    }
    PlayerSynchronizationMessage message = new PlayerSynchronizationMessage(lastKnownRegion, position, regionChanged, segment, oldCount, segments);
    player.send(message);
}
Also used : Player(org.apollo.game.model.entity.Player) Position(org.apollo.game.model.Position) ArrayList(java.util.ArrayList) TeleportSegment(org.apollo.game.sync.seg.TeleportSegment) SynchronizationBlockSet(org.apollo.game.sync.block.SynchronizationBlockSet) MovementSegment(org.apollo.game.sync.seg.MovementSegment) RemoveMobSegment(org.apollo.game.sync.seg.RemoveMobSegment) RegionCoordinates(org.apollo.game.model.area.RegionCoordinates) RegionRepository(org.apollo.game.model.area.RegionRepository) AddPlayerSegment(org.apollo.game.sync.seg.AddPlayerSegment) Region(org.apollo.game.model.area.Region) SynchronizationSegment(org.apollo.game.sync.seg.SynchronizationSegment) PlayerSynchronizationMessage(org.apollo.game.message.impl.PlayerSynchronizationMessage)

Example 3 with SynchronizationBlockSet

use of org.apollo.game.sync.block.SynchronizationBlockSet in project apollo by apollo-rsps.

the class PlayerSynchronizationMessageEncoder method putBlocks.

/**
 * Puts the blocks for the specified segment.
 *
 * @param segment The segment.
 * @param builder The block builder.
 */
private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
    SynchronizationBlockSet blockSet = segment.getBlockSet();
    if (blockSet.size() > 0) {
        int mask = 0;
        if (blockSet.contains(AnimationBlock.class)) {
            mask |= 0x8;
        }
        if (blockSet.contains(ForceChatBlock.class)) {
            mask |= 0x10;
        }
        if (blockSet.contains(ForceMovementBlock.class)) {
            mask |= 0x100;
        }
        if (blockSet.contains(InteractingMobBlock.class)) {
            mask |= 0x1;
        }
        if (blockSet.contains(TurnToPositionBlock.class)) {
            mask |= 0x2;
        }
        if (blockSet.contains(GraphicBlock.class)) {
            mask |= 0x200;
        }
        if (blockSet.contains(AppearanceBlock.class)) {
            mask |= 0x4;
        }
        if (blockSet.contains(SecondaryHitUpdateBlock.class)) {
            mask |= 0x400;
        }
        if (blockSet.contains(ChatBlock.class)) {
            mask |= 0x40;
        }
        if (blockSet.contains(HitUpdateBlock.class)) {
            mask |= 0x80;
        }
        if (mask >= 0x100) {
            mask |= 0x20;
            builder.put(DataType.SHORT, DataOrder.LITTLE, mask);
        } else {
            builder.put(DataType.BYTE, mask);
        }
        if (blockSet.contains(AnimationBlock.class)) {
            putAnimationBlock(blockSet.get(AnimationBlock.class), builder);
        }
        if (blockSet.contains(ForceChatBlock.class)) {
            putForceChatBlock(blockSet.get(ForceChatBlock.class), builder);
        }
        if (blockSet.contains(ForceMovementBlock.class)) {
            putForceMovementBlock(blockSet.get(ForceMovementBlock.class), builder);
        }
        if (blockSet.contains(InteractingMobBlock.class)) {
            putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder);
        }
        if (blockSet.contains(TurnToPositionBlock.class)) {
            putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder);
        }
        if (blockSet.contains(GraphicBlock.class)) {
            putGraphicBlock(blockSet.get(GraphicBlock.class), builder);
        }
        if (blockSet.contains(AppearanceBlock.class)) {
            putAppearanceBlock(blockSet.get(AppearanceBlock.class), builder);
        }
        if (blockSet.contains(SecondaryHitUpdateBlock.class)) {
            putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder);
        }
        if (blockSet.contains(ChatBlock.class)) {
            putChatBlock(blockSet.get(ChatBlock.class), builder);
        }
        if (blockSet.contains(HitUpdateBlock.class)) {
            putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder);
        }
    }
}
Also used : AnimationBlock(org.apollo.game.sync.block.AnimationBlock) AppearanceBlock(org.apollo.game.sync.block.AppearanceBlock) TurnToPositionBlock(org.apollo.game.sync.block.TurnToPositionBlock) ForceChatBlock(org.apollo.game.sync.block.ForceChatBlock) ChatBlock(org.apollo.game.sync.block.ChatBlock) SecondaryHitUpdateBlock(org.apollo.game.sync.block.SecondaryHitUpdateBlock) ForceChatBlock(org.apollo.game.sync.block.ForceChatBlock) GraphicBlock(org.apollo.game.sync.block.GraphicBlock) InteractingMobBlock(org.apollo.game.sync.block.InteractingMobBlock) SecondaryHitUpdateBlock(org.apollo.game.sync.block.SecondaryHitUpdateBlock) HitUpdateBlock(org.apollo.game.sync.block.HitUpdateBlock) SynchronizationBlockSet(org.apollo.game.sync.block.SynchronizationBlockSet) ForceMovementBlock(org.apollo.game.sync.block.ForceMovementBlock)

Example 4 with SynchronizationBlockSet

use of org.apollo.game.sync.block.SynchronizationBlockSet in project apollo by apollo-rsps.

the class NpcSynchronizationMessageEncoder method putBlocks.

/**
 * Puts the blocks for the specified segment.
 *
 * @param segment The segment.
 * @param builder The block builder.
 */
private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
    SynchronizationBlockSet blockSet = segment.getBlockSet();
    if (blockSet.size() > 0) {
        int mask = 0;
        if (blockSet.contains(TransformBlock.class)) {
            mask |= 0x1;
        }
        if (blockSet.contains(InteractingMobBlock.class)) {
            mask |= 0x40;
        }
        if (blockSet.contains(HitUpdateBlock.class)) {
            mask |= 0x80;
        }
        if (blockSet.contains(GraphicBlock.class)) {
            mask |= 0x4;
        }
        if (blockSet.contains(ForceChatBlock.class)) {
            mask |= 0x20;
        }
        if (blockSet.contains(TurnToPositionBlock.class)) {
            mask |= 0x8;
        }
        if (blockSet.contains(AnimationBlock.class)) {
            mask |= 0x2;
        }
        if (blockSet.contains(SecondaryHitUpdateBlock.class)) {
            mask |= 0x10;
        }
        builder.put(DataType.BYTE, mask);
        if (blockSet.contains(TransformBlock.class)) {
            putTransformBlock(blockSet.get(TransformBlock.class), builder);
        }
        if (blockSet.contains(InteractingMobBlock.class)) {
            putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder);
        }
        if (blockSet.contains(HitUpdateBlock.class)) {
            putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder);
        }
        if (blockSet.contains(GraphicBlock.class)) {
            putGraphicBlock(blockSet.get(GraphicBlock.class), builder);
        }
        if (blockSet.contains(ForceChatBlock.class)) {
            putForceChatBlock(blockSet.get(ForceChatBlock.class), builder);
        }
        if (blockSet.contains(TurnToPositionBlock.class)) {
            putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder);
        }
        if (blockSet.contains(AnimationBlock.class)) {
            putAnimationBlock(blockSet.get(AnimationBlock.class), builder);
        }
        if (blockSet.contains(SecondaryHitUpdateBlock.class)) {
            putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder);
        }
    }
}
Also used : AnimationBlock(org.apollo.game.sync.block.AnimationBlock) TransformBlock(org.apollo.game.sync.block.TransformBlock) TurnToPositionBlock(org.apollo.game.sync.block.TurnToPositionBlock) SecondaryHitUpdateBlock(org.apollo.game.sync.block.SecondaryHitUpdateBlock) ForceChatBlock(org.apollo.game.sync.block.ForceChatBlock) GraphicBlock(org.apollo.game.sync.block.GraphicBlock) InteractingMobBlock(org.apollo.game.sync.block.InteractingMobBlock) SecondaryHitUpdateBlock(org.apollo.game.sync.block.SecondaryHitUpdateBlock) HitUpdateBlock(org.apollo.game.sync.block.HitUpdateBlock) SynchronizationBlockSet(org.apollo.game.sync.block.SynchronizationBlockSet)

Example 5 with SynchronizationBlockSet

use of org.apollo.game.sync.block.SynchronizationBlockSet in project apollo by apollo-rsps.

the class PlayerSynchronizationMessageEncoder method putBlocks.

/**
 * Puts the blocks for the specified segment.
 *
 * @param segment The segment.
 * @param builder The block builder.
 */
private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
    SynchronizationBlockSet blockSet = segment.getBlockSet();
    if (blockSet.size() > 0) {
        int mask = 0;
        if (blockSet.contains(ForceMovementBlock.class)) {
            mask |= 0x400;
        }
        if (blockSet.contains(GraphicBlock.class)) {
            mask |= 0x100;
        }
        if (blockSet.contains(AnimationBlock.class)) {
            mask |= 0x8;
        }
        if (blockSet.contains(ForceChatBlock.class)) {
            mask |= 0x4;
        }
        if (blockSet.contains(ChatBlock.class)) {
            mask |= 0x80;
        }
        if (blockSet.contains(InteractingMobBlock.class)) {
            mask |= 0x1;
        }
        if (blockSet.contains(AppearanceBlock.class)) {
            mask |= 0x10;
        }
        if (blockSet.contains(TurnToPositionBlock.class)) {
            mask |= 0x2;
        }
        if (blockSet.contains(HitUpdateBlock.class)) {
            mask |= 0x20;
        }
        if (blockSet.contains(SecondaryHitUpdateBlock.class)) {
            mask |= 0x200;
        }
        if (mask >= 0x100) {
            mask |= 0x40;
            builder.put(DataType.SHORT, DataOrder.LITTLE, mask);
        } else {
            builder.put(DataType.BYTE, mask);
        }
        if (blockSet.contains(ForceMovementBlock.class)) {
            putForceMovementBlock(blockSet.get(ForceMovementBlock.class), builder);
        }
        if (blockSet.contains(GraphicBlock.class)) {
            putGraphicBlock(blockSet.get(GraphicBlock.class), builder);
        }
        if (blockSet.contains(AnimationBlock.class)) {
            putAnimationBlock(blockSet.get(AnimationBlock.class), builder);
        }
        if (blockSet.contains(ForceChatBlock.class)) {
            putForceChatBlock(blockSet.get(ForceChatBlock.class), builder);
        }
        if (blockSet.contains(ChatBlock.class)) {
            putChatBlock(blockSet.get(ChatBlock.class), builder);
        }
        if (blockSet.contains(InteractingMobBlock.class)) {
            putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder);
        }
        if (blockSet.contains(AppearanceBlock.class)) {
            putAppearanceBlock(blockSet.get(AppearanceBlock.class), builder);
        }
        if (blockSet.contains(TurnToPositionBlock.class)) {
            putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder);
        }
        if (blockSet.contains(HitUpdateBlock.class)) {
            putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder);
        }
        if (blockSet.contains(SecondaryHitUpdateBlock.class)) {
            putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder);
        }
    }
}
Also used : AnimationBlock(org.apollo.game.sync.block.AnimationBlock) AppearanceBlock(org.apollo.game.sync.block.AppearanceBlock) ForceChatBlock(org.apollo.game.sync.block.ForceChatBlock) ChatBlock(org.apollo.game.sync.block.ChatBlock) TurnToPositionBlock(org.apollo.game.sync.block.TurnToPositionBlock) SecondaryHitUpdateBlock(org.apollo.game.sync.block.SecondaryHitUpdateBlock) ForceChatBlock(org.apollo.game.sync.block.ForceChatBlock) GraphicBlock(org.apollo.game.sync.block.GraphicBlock) InteractingMobBlock(org.apollo.game.sync.block.InteractingMobBlock) SecondaryHitUpdateBlock(org.apollo.game.sync.block.SecondaryHitUpdateBlock) HitUpdateBlock(org.apollo.game.sync.block.HitUpdateBlock) SynchronizationBlockSet(org.apollo.game.sync.block.SynchronizationBlockSet) ForceMovementBlock(org.apollo.game.sync.block.ForceMovementBlock)

Aggregations

SynchronizationBlockSet (org.apollo.game.sync.block.SynchronizationBlockSet)5 AnimationBlock (org.apollo.game.sync.block.AnimationBlock)4 ForceChatBlock (org.apollo.game.sync.block.ForceChatBlock)4 GraphicBlock (org.apollo.game.sync.block.GraphicBlock)4 HitUpdateBlock (org.apollo.game.sync.block.HitUpdateBlock)4 InteractingMobBlock (org.apollo.game.sync.block.InteractingMobBlock)4 SecondaryHitUpdateBlock (org.apollo.game.sync.block.SecondaryHitUpdateBlock)4 TurnToPositionBlock (org.apollo.game.sync.block.TurnToPositionBlock)4 AppearanceBlock (org.apollo.game.sync.block.AppearanceBlock)2 ChatBlock (org.apollo.game.sync.block.ChatBlock)2 ForceMovementBlock (org.apollo.game.sync.block.ForceMovementBlock)2 TransformBlock (org.apollo.game.sync.block.TransformBlock)2 ArrayList (java.util.ArrayList)1 PlayerSynchronizationMessage (org.apollo.game.message.impl.PlayerSynchronizationMessage)1 Position (org.apollo.game.model.Position)1 Region (org.apollo.game.model.area.Region)1 RegionCoordinates (org.apollo.game.model.area.RegionCoordinates)1 RegionRepository (org.apollo.game.model.area.RegionRepository)1 Player (org.apollo.game.model.entity.Player)1 AddPlayerSegment (org.apollo.game.sync.seg.AddPlayerSegment)1