Skip to content

Commit

Permalink
Add support for overridding movement animations
Browse files Browse the repository at this point in the history
  • Loading branch information
garyttierney committed Jan 28, 2018
1 parent 547ef90 commit 0e98d60
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 60 deletions.
194 changes: 194 additions & 0 deletions game/src/main/java/org/apollo/game/model/entity/AnimationMap.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 23 additions & 0 deletions game/src/main/java/org/apollo/game/model/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 0e98d60

Please sign in to comment.