diff --git a/src/org/apollo/game/model/Npc.java b/src/org/apollo/game/model/Npc.java index b7909366..d4b78cb2 100644 --- a/src/org/apollo/game/model/Npc.java +++ b/src/org/apollo/game/model/Npc.java @@ -10,6 +10,11 @@ import org.apollo.game.sync.block.SynchronizationBlock; */ public final class Npc extends Mob { + /** + * This npc's id. + */ + private int id; + /** * The positions representing the bounds (i.e. walking limits) of this npc. */ @@ -34,6 +39,7 @@ public final class Npc extends Mob { public Npc(NpcDefinition definition, Position position) { super(position); this.definition = definition; + this.id = definition.getId(); } /** @@ -51,12 +57,12 @@ public final class Npc extends Mob { } /** - * Gets the id of this npc. Shorthand for {@link #getDefinition().getId()}. + * Gets the id of this npc. * * @return The id. */ public int getId() { - return definition.getId(); + return id; } /** @@ -94,7 +100,7 @@ public final class Npc extends Mob { if (id < 0 || id >= NpcDefinition.count()) { throw new IllegalArgumentException("Id to transform to is out of bounds."); } - definition = NpcDefinition.lookup(id); + definition = NpcDefinition.lookup(this.id = id); blockSet.add(SynchronizationBlock.createTransformBlock(id)); } diff --git a/src/org/apollo/game/model/Player.java b/src/org/apollo/game/model/Player.java index 5d807e2e..d84f2b3e 100644 --- a/src/org/apollo/game/model/Player.java +++ b/src/org/apollo/game/model/Player.java @@ -99,9 +99,9 @@ public final class Player extends Mob { private List friends = new ArrayList<>(); /** - * This player's head icon. + * Whether or not the player is skulled. */ - private int headIcon = -1; + private boolean isSkulled = false; /** * The list of usernames of players this player has ignored. @@ -348,12 +348,12 @@ public final class Player extends Mob { } /** - * Gets the player's head icon. + * Indicates whether or not the player is skulled * - * @return The head icon. + * @return {@code true} if the player is skulled, otherwise {@code false}. */ - public int getHeadIcon() { - return headIcon; + public boolean isSkulled() { + return isSkulled; } /** @@ -810,12 +810,12 @@ public final class Player extends Mob { } /** - * Sets the player's head icon. + * Sets whether or not the player is skulled. * - * @param headIcon The head icon. + * @param isSkulled Whether or not the player is skulled. */ - public void setHeadIcon(int headIcon) { - this.headIcon = headIcon; + public void setSkulled(boolean isSkulled) { + this.isSkulled = isSkulled; } /** diff --git a/src/org/apollo/game/sync/block/AppearanceBlock.java b/src/org/apollo/game/sync/block/AppearanceBlock.java index 57efd2bb..292e84b7 100644 --- a/src/org/apollo/game/sync/block/AppearanceBlock.java +++ b/src/org/apollo/game/sync/block/AppearanceBlock.java @@ -26,9 +26,9 @@ public final class AppearanceBlock extends SynchronizationBlock { private final Inventory equipment; /** - * The player's head icon. + * Whether or not the player is skulled. */ - private final int headIcon; + private final boolean isSkulled; /** * The player's name. @@ -43,7 +43,7 @@ public final class AppearanceBlock extends SynchronizationBlock { /** * The player's prayer icon. */ - private final int prayerIcon; + private final int headIcon; /** * The player's total skill level (or 0). @@ -58,12 +58,12 @@ public final class AppearanceBlock extends SynchronizationBlock { * @param combat The player's combat. * @param skill The player's skill, or 0 if showing the combat level. * @param equipment The player's equipment. - * @param prayerIcon The prayer icon id of this player. - * @param headIcon The head icon id of this player. + * @param headIcon The head icon id of the player. + * @param isSkulled Whether or not the player is skulled. */ - AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int prayerIcon, - int headIcon) { - this(name, appearance, combat, skill, equipment, prayerIcon, headIcon, -1); + AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, + boolean isSkulled) { + this(name, appearance, combat, skill, equipment, headIcon, isSkulled, -1); } /** @@ -74,19 +74,19 @@ public final class AppearanceBlock extends SynchronizationBlock { * @param combat The player's combat. * @param skill The player's skill, or 0 if showing the combat level. * @param equipment The player's equipment. - * @param prayerIcon The prayer icon id of this player. - * @param headIcon The head icon id of this player. + * @param headIcon The prayer icon id of this player. + * @param isSkulled Whether or not the player is skulled. * @param npcId The npc id of the player, if they are appearing as an npc, (otherwise {@code -1}). */ - AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int prayerIcon, - int headIcon, int npcId) { + AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, + boolean isSkulled, int npcId) { this.name = name; this.appearance = appearance; this.combat = combat; this.skill = skill; this.equipment = equipment.clone(); - this.prayerIcon = prayerIcon; this.headIcon = headIcon; + this.isSkulled = isSkulled; this.npcId = npcId; } @@ -127,12 +127,12 @@ public final class AppearanceBlock extends SynchronizationBlock { } /** - * Gets the player's head icon. + * Whether or not the player is skulled. * - * @return The head icon. + * @return {@code true} if the player is skulled, otherwise {@code false}. */ - public int getHeadIcon() { - return headIcon; + public boolean isSkulled() { + return isSkulled; } /** @@ -154,12 +154,12 @@ public final class AppearanceBlock extends SynchronizationBlock { } /** - * Gets the player's prayer icon. + * Gets the player's head icon. * - * @return The prayer icon. + * @return The head icon. */ - public int getPrayerIcon() { - return prayerIcon; + public int getHeadIcon() { + return headIcon; } /** diff --git a/src/org/apollo/game/sync/block/SynchronizationBlock.java b/src/org/apollo/game/sync/block/SynchronizationBlock.java index 48d46d61..e3130bd0 100644 --- a/src/org/apollo/game/sync/block/SynchronizationBlock.java +++ b/src/org/apollo/game/sync/block/SynchronizationBlock.java @@ -35,7 +35,7 @@ public abstract class SynchronizationBlock { */ public static SynchronizationBlock createAppearanceBlock(Player player) { return new AppearanceBlock(player.getEncodedName(), player.getAppearance(), player.getSkillSet() - .getCombatLevel(), 0, player.getEquipment(), player.getPrayerIcon(), player.getHeadIcon(), + .getCombatLevel(), 0, player.getEquipment(), player.getPrayerIcon(), player.isSkulled(), player.getDefinition() == null ? -1 : player.getDefinition().getId()); } diff --git a/src/org/apollo/game/sync/task/NpcSynchronizationTask.java b/src/org/apollo/game/sync/task/NpcSynchronizationTask.java index 4e71509e..94480c71 100644 --- a/src/org/apollo/game/sync/task/NpcSynchronizationTask.java +++ b/src/org/apollo/game/sync/task/NpcSynchronizationTask.java @@ -7,13 +7,12 @@ import java.util.List; import org.apollo.game.event.impl.NpcSynchronizationEvent; import org.apollo.game.model.Npc; import org.apollo.game.model.Player; +import org.apollo.game.model.Position; import org.apollo.game.model.World; -import org.apollo.game.sync.block.SynchronizationBlockSet; import org.apollo.game.sync.seg.AddNpcSegment; import org.apollo.game.sync.seg.MovementSegment; import org.apollo.game.sync.seg.RemoveMobSegment; import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.util.MobRepository; /** * A {@link SynchronizationTask} which synchronizes npcs with the specified {@link Player}. @@ -44,15 +43,15 @@ public final class NpcSynchronizationTask extends SynchronizationTask { @Override public void run() { - SynchronizationBlockSet blockSet = player.getBlockSet(); List localNpcs = player.getLocalNpcList(); + List segments = new ArrayList<>(); int oldLocalNpcs = localNpcs.size(); - List segments = new ArrayList(); + final Position playerPosition = player.getPosition(); for (Iterator it = localNpcs.iterator(); it.hasNext();) { Npc npc = it.next(); if (!npc.isActive() || npc.isTeleporting() - || npc.getPosition().getLongestDelta(player.getPosition()) > player.getViewingDistance()) { + || npc.getPosition().getLongestDelta(playerPosition) > player.getViewingDistance()) { it.remove(); segments.add(new RemoveMobSegment()); } else { @@ -62,8 +61,7 @@ public final class NpcSynchronizationTask extends SynchronizationTask { int added = 0; - MobRepository repository = World.getWorld().getNpcRepository(); - for (Npc npc : repository) { + for (Npc npc : World.getWorld().getNpcRepository()) { if (localNpcs.size() >= 255) { player.flagExcessiveNpcs(); break; @@ -71,19 +69,17 @@ public final class NpcSynchronizationTask extends SynchronizationTask { break; } - if (npc.getPosition().isWithinDistance(player.getPosition(), player.getViewingDistance()) - && !localNpcs.contains(npc)) { + Position npcPosition = npc.getPosition(); + if (npcPosition.isWithinDistance(playerPosition, player.getViewingDistance()) && !localNpcs.contains(npc) + && npcPosition.getHeight() == playerPosition.getHeight()) { localNpcs.add(npc); added++; npc.turnTo(npc.getFacingPosition()); - blockSet = npc.getBlockSet(); - segments.add(new AddNpcSegment(blockSet, npc.getIndex(), npc.getPosition(), npc.getDefinition() - .getId())); + segments.add(new AddNpcSegment(npc.getBlockSet(), npc.getIndex(), npcPosition, npc.getId())); } } - NpcSynchronizationEvent event = new NpcSynchronizationEvent(player.getPosition(), segments, oldLocalNpcs); - player.send(event); + player.send(new NpcSynchronizationEvent(playerPosition, segments, oldLocalNpcs)); } } \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/NpcSynchronizationEventEncoder.java b/src/org/apollo/net/release/r317/NpcSynchronizationEventEncoder.java index 2f660fe2..3720ceb6 100644 --- a/src/org/apollo/net/release/r317/NpcSynchronizationEventEncoder.java +++ b/src/org/apollo/net/release/r317/NpcSynchronizationEventEncoder.java @@ -88,21 +88,21 @@ public final class NpcSynchronizationEventEncoder extends EventEncoder 0) { int mask = 0; @@ -139,38 +139,38 @@ public final class NpcSynchronizationEventEncoder extends EventEncoder 0) { int mask = 0; @@ -268,40 +268,40 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder= 0x100) { mask |= 0x40; - blockBuilder.put(DataType.SHORT, DataOrder.LITTLE, mask); + builder.put(DataType.SHORT, DataOrder.LITTLE, mask); } else { - blockBuilder.put(DataType.BYTE, mask); + builder.put(DataType.BYTE, mask); } if (blockSet.contains(ForceMovementBlock.class)) { - putForceMovementBlock(blockSet.get(ForceMovementBlock.class), blockBuilder); + putForceMovementBlock(blockSet.get(ForceMovementBlock.class), builder); } if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), blockBuilder); + putGraphicBlock(blockSet.get(GraphicBlock.class), builder); } if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), blockBuilder); + putAnimationBlock(blockSet.get(AnimationBlock.class), builder); } if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), blockBuilder); + putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); } if (blockSet.contains(ChatBlock.class)) { - putChatBlock(blockSet.get(ChatBlock.class), blockBuilder); + putChatBlock(blockSet.get(ChatBlock.class), builder); } if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), blockBuilder); + putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); } if (blockSet.contains(AppearanceBlock.class)) { - putAppearanceBlock(blockSet.get(AppearanceBlock.class), blockBuilder); + putAppearanceBlock(blockSet.get(AppearanceBlock.class), builder); } if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), blockBuilder); + putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); } if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), blockBuilder); + putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); } if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), blockBuilder); + putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); } } } diff --git a/src/org/apollo/net/release/r377/NpcSynchronizationEventEncoder.java b/src/org/apollo/net/release/r377/NpcSynchronizationEventEncoder.java index 77e98cd7..9b3414a0 100644 --- a/src/org/apollo/net/release/r377/NpcSynchronizationEventEncoder.java +++ b/src/org/apollo/net/release/r377/NpcSynchronizationEventEncoder.java @@ -78,8 +78,8 @@ public final class NpcSynchronizationEventEncoder extends EventEncoder 0) { int mask = 0; @@ -139,38 +139,38 @@ public final class NpcSynchronizationEventEncoder extends EventEncoder 0) { int mask = 0; @@ -268,42 +268,41 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder= 0x100) { mask |= 0x20; - blockBuilder.put(DataType.SHORT, DataOrder.LITTLE, mask); + builder.put(DataType.SHORT, DataOrder.LITTLE, mask); } else { - blockBuilder.put(DataType.BYTE, mask); + builder.put(DataType.BYTE, mask); } if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), blockBuilder); + putAnimationBlock(blockSet.get(AnimationBlock.class), builder); } if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), blockBuilder); + putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); } if (blockSet.contains(ForceMovementBlock.class)) { - putForceMovementBlock(blockSet.get(ForceMovementBlock.class), blockBuilder); + putForceMovementBlock(blockSet.get(ForceMovementBlock.class), builder); } if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), blockBuilder); + putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); } if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), blockBuilder); + putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); } if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), blockBuilder); + putGraphicBlock(blockSet.get(GraphicBlock.class), builder); } if (blockSet.contains(AppearanceBlock.class)) { - putAppearanceBlock(blockSet.get(AppearanceBlock.class), blockBuilder); + putAppearanceBlock(blockSet.get(AppearanceBlock.class), builder); } if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), blockBuilder); + putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); } if (blockSet.contains(ChatBlock.class)) { - putChatBlock(blockSet.get(ChatBlock.class), blockBuilder); + putChatBlock(blockSet.get(ChatBlock.class), builder); } if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), blockBuilder); + putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); } - } } @@ -311,14 +310,14 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder