diff --git a/game/src/main/java/org/apollo/game/model/entity/AnimationMap.java b/game/src/main/java/org/apollo/game/model/entity/AnimationMap.java new file mode 100644 index 000000000..a50662e84 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/AnimationMap.java @@ -0,0 +1,194 @@ +package org.apollo.game.model.entity; + +/** + * A map of animations for {@link Player}s. Contains animations such as standing, turning, running, etc. + * + * @author Steve Soltys + */ +public class AnimationMap { + /** + * The default animation set for {@link Player}s. + */ + public static final AnimationMap DEFAULT_ANIMATION_SET = new AnimationMap(0x328, 0x337, 0x333, 0x334, 0x335, 0x336, 0x338); + + /** + * The animation for standing in place. + */ + private int stand; + + /** + * The animation for turning while idle. + */ + private int idleTurn; + + /** + * The animation for walking. + */ + private int walking; + + /** + * The animation for turning 180 degrees. + */ + private int turnAround; + + /** + * The animation for turning 90 degrees right. + */ + private int turnRight; + + /** + * The animation for turning 90 degrees left. + */ + private int turnLeft; + + /** + * The animation for running. + */ + private int running; + + public AnimationMap(int stand, int idleTurn, int walking, int turnAround, int turnRight, int turnLeft, int running) { + this.stand = stand; + this.idleTurn = idleTurn; + this.walking = walking; + this.turnAround = turnAround; + this.turnRight = turnRight; + this.turnLeft = turnLeft; + this.running = running; + } + + /** + * Duplicates this animation set. + * + * @return the duplicated animation set. + */ + @Override + public AnimationMap clone() { + return new AnimationMap(stand, idleTurn, walking, turnAround, turnRight, turnLeft, running); + } + + /** + * Gets the animation for standing in place. + * + * @return the animation. + */ + public int getStand() { + return stand; + } + + /** + * Sets the animation for standing in place. + * + * @param stand the animation. + */ + public void setStand(int stand) { + this.stand = stand; + } + + /** + * Gets the animation for turning while idle. + * + * @return the animation. + */ + public int getIdleTurn() { + return idleTurn; + } + + /** + * Sets the animation for standing in place. + * + * @param idleTurn the animation. + */ + public void setIdleTurn(int idleTurn) { + this.idleTurn = idleTurn; + } + + /** + * Gets the animation for walking. + * + * @return the animation. + */ + public int getWalking() { + return walking; + } + + /** + * Sets the animation for walking. + * + * @param walking the animation. + */ + public void setWalking(int walking) { + this.walking = walking; + } + + /** + * Gets the animation for turning 180 degrees. + * + * @return the animation. + */ + public int getTurnAround() { + return turnAround; + } + + /** + * Sets the animation for turning 180 degrees. + * + * @param turnAround the animation. + */ + public void setTurnAround(int turnAround) { + this.turnAround = turnAround; + } + + /** + * Gets the animation for turning 90 degrees right. + * + * @return the animation. + */ + public int getTurnRight() { + return turnRight; + } + + /** + * Sets the animation for turning 90 degrees right. + * + * @param turnRight the animation. + */ + public void setTurnRight(int turnRight) { + this.turnRight = turnRight; + } + + /** + * Gets the animation for turning 90 degrees left. + * + * @return the animation. + */ + public int getTurnLeft() { + return turnLeft; + } + + /** + * Sets the animation for turning 90 degrees left. + * + * @param turnLeft the animation. + */ + public void setTurnLeft(int turnLeft) { + this.turnLeft = turnLeft; + } + + /** + * Gets the animation for running. + * + * @return the animation. + */ + public int getRunning() { + return running; + } + + /** + * Sets the animation for running. + * + * @param running the animation. + */ + public void setRunning(int running) { + this.running = running; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 76c06db95..35eacba4d 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -64,6 +64,11 @@ */ public final class Player extends Mob { + /** + * The {@code Mob}s current set of animations used in appearance updates. + */ + private AnimationMap animations = AnimationMap.DEFAULT_ANIMATION_SET; + /** * The default viewing distance, in tiles. */ @@ -317,6 +322,15 @@ public boolean friendsWith(String username) { return friends.contains(username.toLowerCase()); } + /** + * Gets the current set of animations used for character movement. + * + * @return The animation set. + */ + public final AnimationMap getAnimations() { + return animations; + } + /** * Gets the player's appearance. * @@ -797,6 +811,15 @@ public void sendUserLists() { } } + /** + * Sets the set of animations to use in {@code Mob} appearance updates. + * + * @param animations The set of animations to use. + */ + public final void setAnimations(AnimationMap animations) { + this.animations = animations; + } + /** * Sets the player's appearance. * diff --git a/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java index b628ded53..26ac6fc11 100644 --- a/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java @@ -9,6 +9,7 @@ import org.apollo.game.model.Item; import org.apollo.game.model.Position; import org.apollo.game.model.entity.EquipmentConstants; +import org.apollo.game.model.entity.AnimationMap; import org.apollo.game.model.entity.setting.Gender; import org.apollo.game.model.inv.Inventory; import org.apollo.game.sync.block.AnimationBlock; @@ -207,13 +208,14 @@ private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder playerProperties.put(DataType.BYTE, color); } - playerProperties.put(DataType.SHORT, 0x328); // stand - playerProperties.put(DataType.SHORT, 0x337); // stand turn - playerProperties.put(DataType.SHORT, 0x333); // walk - playerProperties.put(DataType.SHORT, 0x334); // turn 180 - playerProperties.put(DataType.SHORT, 0x335); // turn 90 cw - playerProperties.put(DataType.SHORT, 0x336); // turn 90 ccw - playerProperties.put(DataType.SHORT, 0x338); // run + AnimationMap animations = block.getAnimations(); + playerProperties.put(DataType.SHORT, animations.getStand()); // stand + playerProperties.put(DataType.SHORT, animations.getIdleTurn()); // stand turn + playerProperties.put(DataType.SHORT, animations.getWalking()); // walk + playerProperties.put(DataType.SHORT, animations.getTurnAround()); // turn 180 + playerProperties.put(DataType.SHORT, animations.getTurnRight()); // turn 90 cw + playerProperties.put(DataType.SHORT, animations.getTurnLeft()); // turn 90 ccw + playerProperties.put(DataType.SHORT, animations.getRunning()); // run playerProperties.put(DataType.LONG, block.getName()); playerProperties.put(DataType.BYTE, block.getCombatLevel()); diff --git a/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java index 5ef61f80c..77d1f4017 100644 --- a/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java @@ -2,36 +2,14 @@ import org.apollo.cache.def.EquipmentDefinition; import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Item; -import org.apollo.game.model.Position; +import org.apollo.game.model.*; import org.apollo.game.model.entity.EquipmentConstants; +import org.apollo.game.model.entity.AnimationMap; import org.apollo.game.model.entity.setting.Gender; import org.apollo.game.model.inv.Inventory; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.ChatBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.ForceMovementBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.AddPlayerSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.game.sync.seg.TeleportSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.game.sync.block.*; +import org.apollo.game.sync.seg.*; +import org.apollo.net.codec.game.*; import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; @@ -208,13 +186,14 @@ private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder playerProperties.put(DataType.BYTE, color); } - playerProperties.put(DataType.SHORT, 0x328); // stand - playerProperties.put(DataType.SHORT, 0x337); // stand turn - playerProperties.put(DataType.SHORT, 0x333); // walk - playerProperties.put(DataType.SHORT, 0x334); // turn 180 - playerProperties.put(DataType.SHORT, 0x335); // turn 90 cw - playerProperties.put(DataType.SHORT, 0x336); // turn 90 ccw - playerProperties.put(DataType.SHORT, 0x338); // run + AnimationMap animations = block.getAnimations(); + playerProperties.put(DataType.SHORT, animations.getStand()); // stand + playerProperties.put(DataType.SHORT, animations.getIdleTurn()); // stand turn + playerProperties.put(DataType.SHORT, animations.getWalking()); // walk + playerProperties.put(DataType.SHORT, animations.getTurnAround()); // turn 180 + playerProperties.put(DataType.SHORT, animations.getTurnRight()); // turn 90 cw + playerProperties.put(DataType.SHORT, animations.getTurnLeft()); // turn 90 ccw + playerProperties.put(DataType.SHORT, animations.getRunning()); // run playerProperties.put(DataType.LONG, block.getName()); playerProperties.put(DataType.BYTE, block.getCombatLevel()); diff --git a/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java b/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java index a2a54356c..9a23d00b8 100644 --- a/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java @@ -1,6 +1,7 @@ package org.apollo.game.sync.block; import org.apollo.game.model.Appearance; +import org.apollo.game.model.entity.AnimationMap; import org.apollo.game.model.inv.Inventory; /** @@ -10,6 +11,11 @@ */ public final class AppearanceBlock extends SynchronizationBlock { + /** + * The player's movement animations. + */ + private final AnimationMap animations; + /** * The player's appearance. */ @@ -53,32 +59,35 @@ public final class AppearanceBlock extends SynchronizationBlock { /** * Creates the appearance block. Assumes that the player is not appearing as an npc. * - * @param name The player's username, encoded to base 37. + * @param name The player's username, encoded to base 37. * @param appearance The {@link Appearance}. - * @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 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 headIcon, boolean isSkulled) { - this(name, appearance, combat, skill, equipment, headIcon, isSkulled, -1); + * @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 headIcon The head icon id of the player. + * @param isSkulled Whether or not the player is skulled. + * @param animations + */ + AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, boolean isSkulled, AnimationMap animations) { + this(name, animations, appearance, combat, skill, equipment, headIcon, isSkulled, -1); } /** * Creates the appearance block. * - * @param name The player's username, encoded to base 37. + * @param name The player's username, encoded to base 37. + * @param animations * @param appearance The {@link Appearance}. - * @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 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 headIcon, boolean isSkulled, int npcId) { + * @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 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, AnimationMap animations, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, boolean isSkulled, int npcId) { this.name = name; + this.animations = animations; this.appearance = appearance; this.combat = combat; this.skill = skill; @@ -97,6 +106,15 @@ public boolean appearingAsNpc() { return npcId != -1; } + /** + * Gets the player's {@link AnimationMap}. + * + * @return The player's animations. + */ + public AnimationMap getAnimations() { + return animations; + } + /** * Gets the player's {@link Appearance}. * diff --git a/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java b/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java index 238ed7bfd..e664e3f1d 100644 --- a/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java @@ -37,7 +37,7 @@ public static SynchronizationBlock createAppearanceBlock(Player player) { int combat = player.getSkillSet().getCombatLevel(); int id = player.hasNpcDefinition() ? player.getDefinition().getId() : -1; - return new AppearanceBlock(player.getEncodedName(), player.getAppearance(), combat, 0, player.getEquipment(), player.getPrayerIcon(), player.isSkulled(), id); + return new AppearanceBlock(player.getEncodedName(), player.getAnimations(), player.getAppearance(), combat, 0, player.getEquipment(), player.getPrayerIcon(), player.isSkulled(), id); } /**