Format and cleanup.

This commit is contained in:
Major-
2013-11-24 01:29:04 +00:00
parent ea115562c0
commit a66a901dd4
296 changed files with 1224 additions and 1266 deletions
+3 -3
View File
@@ -4,10 +4,10 @@
<chain />
</event>
<event>
<type>org.apollo.game.event.impl.CharacterDesignEvent</type>
<type>org.apollo.game.event.impl.PlayerDesignEvent</type>
<chain>
<handler>org.apollo.game.event.handler.impl.CharacterDesignVerificationHandler</handler>
<handler>org.apollo.game.event.handler.impl.CharacterDesignEventHandler</handler>
<handler>org.apollo.game.event.handler.impl.PlayerDesignVerificationHandler</handler>
<handler>org.apollo.game.event.handler.impl.PlayerDesignEventHandler</handler>
</chain>
</event>
<event>
+22 -24
View File
@@ -91,7 +91,7 @@ public final class IndexedFileSystem implements Closeable {
} else if (newEngineData.exists() && !oldEngineData.isDirectory()) {
data = new RandomAccessFile(newEngineData, readOnly ? "r" : "rw");
} else {
throw new FileNotFoundException("No data file present");
throw new FileNotFoundException("no data file present");
}
}
@@ -123,27 +123,27 @@ public final class IndexedFileSystem implements Closeable {
for (int i = 1; i < crcs.length; i++) {
crc32.reset();
ByteBuffer bb = getFile(0, i);
byte[] bytes = new byte[bb.remaining()];
bb.get(bytes, 0, bytes.length);
ByteBuffer buffer = getFile(0, i);
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes, 0, bytes.length);
crc32.update(bytes, 0, bytes.length);
crcs[i] = (int) crc32.getValue();
}
// hash the CRCs and place them in the buffer
ByteBuffer buf = ByteBuffer.allocate(crcs.length * 4 + 4);
ByteBuffer buffer = ByteBuffer.allocate(crcs.length * 4 + 4);
for (int crc : crcs) {
hash = (hash << 1) + crc;
buf.putInt(crc);
buffer.putInt(crc);
}
// place the hash into the buffer
buf.putInt(hash);
buf.flip();
buffer.putInt(hash);
buffer.flip();
synchronized (this) {
crcTable = buf.asReadOnlyBuffer();
crcTable = buffer.asReadOnlyBuffer();
return crcTable.duplicate();
}
}
@@ -153,16 +153,16 @@ public final class IndexedFileSystem implements Closeable {
/**
* Gets a file.
*
* @param fd The {@link FileDescriptor} which points to the file.
* @param descriptor The {@link FileDescriptor} which points to the file.
* @return A {@link ByteBuffer} which contains the contents of the file.
* @throws IOException If an I/O error occurs.
*/
public ByteBuffer getFile(FileDescriptor fd) throws IOException {
Index index = getIndex(fd);
public ByteBuffer getFile(FileDescriptor descriptor) throws IOException {
Index index = getIndex(descriptor);
ByteBuffer buffer = ByteBuffer.allocate(index.getSize());
// calculate some initial values
long ptr = (long) index.getBlock() * (long) FileSystemConstants.BLOCK_SIZE;
long ptr = index.getBlock() * FileSystemConstants.BLOCK_SIZE;
int read = 0;
int size = index.getSize();
int blocks = size / FileSystemConstants.CHUNK_SIZE;
@@ -171,7 +171,6 @@ public final class IndexedFileSystem implements Closeable {
}
for (int i = 0; i < blocks; i++) {
// read header
byte[] header = new byte[FileSystemConstants.HEADER_SIZE];
synchronized (data) {
@@ -211,15 +210,14 @@ public final class IndexedFileSystem implements Closeable {
read += chunkSize;
ptr = (long) nextBlock * (long) FileSystemConstants.BLOCK_SIZE;
// if we still have more data to read, check the validity of the
// header
// if we still have more data to read, check the validity of the header
if (size > read) {
if (nextType != fd.getType() + 1) {
throw new IOException("File type mismatch.");
if (nextType != descriptor.getType() + 1) {
throw new IOException("file type mismatch.");
}
if (nextFile != fd.getFile()) {
throw new IOException("File id mismatch.");
if (nextFile != descriptor.getFile()) {
throw new IOException("file id mismatch.");
}
}
}
@@ -261,12 +259,12 @@ public final class IndexedFileSystem implements Closeable {
/**
* Gets the index of a file.
*
* @param fd The {@link FileDescriptor} which points to the file.
* @param descriptor The {@link FileDescriptor} which points to the file.
* @return The {@link Index}.
* @throws IOException If an I/O error occurs.
*/
private Index getIndex(FileDescriptor fd) throws IOException {
int index = fd.getType();
private Index getIndex(FileDescriptor descriptor) throws IOException {
int index = descriptor.getType();
if (index < 0 || index >= indices.length) {
throw new IndexOutOfBoundsException("file descriptor type out of bounds");
}
@@ -274,7 +272,7 @@ public final class IndexedFileSystem implements Closeable {
byte[] buffer = new byte[FileSystemConstants.INDEX_SIZE];
RandomAccessFile indexFile = indices[index];
synchronized (indexFile) {
long ptr = (long) fd.getFile() * (long) FileSystemConstants.INDEX_SIZE;
long ptr = descriptor.getFile() * FileSystemConstants.INDEX_SIZE;
if (ptr >= 0 && indexFile.length() >= ptr + FileSystemConstants.INDEX_SIZE) {
indexFile.seek(ptr);
indexFile.readFully(buffer);
@@ -2,4 +2,3 @@
* Contains classes which deal with archives.
*/
package org.apollo.fs.archive;
@@ -2,4 +2,3 @@
* Contains classes which parse files within the game's cache.
*/
package org.apollo.fs.decoder;
-1
View File
@@ -3,4 +3,3 @@
* store game data files.
*/
package org.apollo.fs;
+11 -11
View File
@@ -4,7 +4,7 @@ import org.apollo.game.model.Mob;
import org.apollo.game.scheduling.ScheduledTask;
/**
* An action is a specialised {@link ScheduledTask} which is specific to a character.
* An action is a specialised {@link ScheduledTask} which is specific to a mob.
* <p>
* <strong>ALL</strong> actions <strong>MUST</strong> implement the {@link #equals(Object)} method. This is to check if
* two actions are identical: if they are, then the new action does not replace the old one (so spam/accidental clicking
@@ -15,9 +15,9 @@ import org.apollo.game.scheduling.ScheduledTask;
public abstract class Action<T extends Mob> extends ScheduledTask {
/**
* The character performing the action.
* The mob performing the action.
*/
private final T character;
protected final T mob;
/**
* A flag indicating if this action is stopping.
@@ -29,20 +29,20 @@ public abstract class Action<T extends Mob> extends ScheduledTask {
*
* @param delay The delay in pulses.
* @param immediate A flag indicating if the action should happen immediately.
* @param character The character performing the action.
* @param mob The mob performing the action.
*/
public Action(int delay, boolean immediate, T character) {
public Action(int delay, boolean immediate, T mob) {
super(delay, immediate);
this.character = character;
this.mob = mob;
}
/**
* Gets the character which performed the action.
* Gets the mob which performed the action.
*
* @return The character.
* @return The mob.
*/
public T getCharacter() {
return character;
public T getMob() {
return mob;
}
@Override
@@ -50,7 +50,7 @@ public abstract class Action<T extends Mob> extends ScheduledTask {
super.stop();
if (!stopping) {
stopping = true;
character.stopAction();
mob.stopAction();
}
}
@@ -41,12 +41,12 @@ public abstract class DistancedAction<T extends Mob> extends Action<T> {
*
* @param delay The delay between executions once the distance threshold is reached.
* @param immediate Whether or not this action fires immediately after the distance threshold is reached.
* @param character The character.
* @param mob The mob.
* @param position The position.
* @param distance The distance.
*/
public DistancedAction(int delay, boolean immediate, T character, Position position, int distance) {
super(0, true, character);
public DistancedAction(int delay, boolean immediate, T mob, Position position, int distance) {
super(0, true, mob);
this.position = position;
this.distance = distance;
this.delay = delay;
@@ -59,7 +59,7 @@ public abstract class DistancedAction<T extends Mob> extends Action<T> {
// some actions (e.g. agility) will cause the player to move away again
// so we don't check once the player got close enough once
executeAction();
} else if (getCharacter().getPosition().getDistance(position) <= distance) {
} else if (mob.getPosition().getDistance(position) <= distance) {
reached = true;
setDelay(delay);
if (immediate) { // TODO: required?
+1 -2
View File
@@ -1,6 +1,5 @@
/**
* Contains classes related to actions, specialised scheduled tasks which
* characters perform.
* mobs perform.
*/
package org.apollo.game.action;
@@ -2,4 +2,3 @@
* Contains classes related to in-game commands.
*/
package org.apollo.game.command;
@@ -2,4 +2,3 @@
* Contains classes related to the chaining of event handlers.
*/
package org.apollo.game.event.handler.chain;
@@ -23,7 +23,6 @@ public final class CommandEventHandler extends EventHandler<CommandEvent> {
String[] arguments = new String[components.length - 1];
System.arraycopy(components, 1, arguments, 0, arguments.length);
Command command = new Command(name, arguments);
World.getWorld().getCommandDispatcher().dispatch(player, command);
@@ -27,7 +27,6 @@ public final class ItemOnItemVerificationHandler extends EventHandler<ItemOnItem
Item item = inventory.get(slot);
if (item == null || item.getId() != event.getTargetId()) {
ctx.breakHandlerChain();
return;
}
}
@@ -2,21 +2,21 @@ package org.apollo.game.event.handler.impl;
import org.apollo.game.event.handler.EventHandler;
import org.apollo.game.event.handler.EventHandlerContext;
import org.apollo.game.event.impl.CharacterDesignEvent;
import org.apollo.game.event.impl.PlayerDesignEvent;
import org.apollo.game.event.impl.CloseInterfaceEvent;
import org.apollo.game.model.Player;
/**
* A handler which handles {@link CharacterDesignEvent}s.
* A handler which handles {@link PlayerDesignEvent}s.
*
* @author Graham
*/
public final class CharacterDesignEventHandler extends EventHandler<CharacterDesignEvent> {
public final class PlayerDesignEventHandler extends EventHandler<PlayerDesignEvent> {
@Override
public void handle(EventHandlerContext ctx, Player player, CharacterDesignEvent event) {
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
player.setAppearance(event.getAppearance());
player.setDesignedCharacter(true);
player.setDesigned(true);
player.send(new CloseInterfaceEvent());
}
@@ -2,21 +2,21 @@ package org.apollo.game.event.handler.impl;
import org.apollo.game.event.handler.EventHandler;
import org.apollo.game.event.handler.EventHandlerContext;
import org.apollo.game.event.impl.CharacterDesignEvent;
import org.apollo.game.event.impl.PlayerDesignEvent;
import org.apollo.game.model.Appearance;
import org.apollo.game.model.Gender;
import org.apollo.game.model.Player;
/**
* A handler which verifies {@link CharacterDesignEvent}s.
* A handler which verifies {@link PlayerDesignEvent}s.
*
* @author Graham
*/
public final class CharacterDesignVerificationHandler extends EventHandler<CharacterDesignEvent> {
public final class PlayerDesignVerificationHandler extends EventHandler<PlayerDesignEvent> {
@Override
public void handle(EventHandlerContext ctx, Player player, CharacterDesignEvent event) {
if (!valid(event.getAppearance()) || player.hasDesignedCharacter()) {
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
if (!valid(event.getAppearance()) || player.hasDesignedAvatar()) {
ctx.breakHandlerChain();
}
}
@@ -42,7 +42,7 @@ public final class CharacterDesignVerificationHandler extends EventHandler<Chara
} else if (gender == Gender.FEMALE) {
return validFemaleStyle(appearance);
} else {
return false; // maybe null?
throw new IllegalArgumentException("player can only be either male or female");
}
}
@@ -21,7 +21,6 @@ public final class SwitchItemEventHandler extends EventHandler<SwitchItemEvent>
Inventory inventory;
boolean insertPermitted = false;
// TODO is there a better way of doing this??
switch (event.getInterfaceId()) {
case SynchronizationInventoryListener.INVENTORY_ID:
case BankConstants.SIDEBAR_INVENTORY_ID:
@@ -23,7 +23,7 @@ public final class WalkEventHandler extends EventHandler<WalkEvent> {
Position step = steps[i];
if (i == 0) {
if (!queue.addFirstStep(step)) {
return; /* ignore packet */
return; // ignore packet
}
} else {
queue.addStep(step);
@@ -2,4 +2,3 @@
* Contains event handler implementations.
*/
package org.apollo.game.event.handler.impl;
@@ -2,4 +2,3 @@
* Contains classes which define abstract event handlers.
*/
package org.apollo.game.event.handler;
@@ -1,12 +0,0 @@
package org.apollo.game.event.impl;
import org.apollo.game.event.Event;
/**
* An outgoing event sent to reset the animations of every character.
*
* @author Major
*/
public class CharacterAnimationResetEvent extends Event {
}
@@ -0,0 +1,12 @@
package org.apollo.game.event.impl;
import org.apollo.game.event.Event;
/**
* An outgoing event sent to reset the animations of every mob.
*
* @author Major
*/
public class MobAnimationResetEvent extends Event {
}
@@ -4,11 +4,11 @@ import org.apollo.game.event.Event;
import org.apollo.game.model.Appearance;
/**
* An event sent by the client when the player modifies their character's design.
* An event sent by the client when the player modifies their design.
*
* @author Graham
*/
public final class CharacterDesignEvent extends Event {
public final class PlayerDesignEvent extends Event {
/**
* The appearance.
@@ -16,11 +16,11 @@ public final class CharacterDesignEvent extends Event {
private final Appearance appearance;
/**
* Creates the character design event.
* Creates the player design event.
*
* @param appearance The appearance.
*/
public CharacterDesignEvent(Appearance appearance) {
public PlayerDesignEvent(Appearance appearance) {
this.appearance = appearance;
}
@@ -3,14 +3,14 @@ package org.apollo.game.event.impl;
import org.apollo.game.event.Event;
/**
* An event which is sent to the client to make a character model on an interface play a certain animation.
* An event which is sent to the client to make a mob model on an interface play a certain animation.
*
* @author Chris Fletcher
*/
public final class SetWidgetModelAnimationEvent extends Event {
/**
* The model's mood id.
* The model's animation id.
*/
private final int animation;
@@ -31,17 +31,5 @@ public class SpamPacketEvent extends Event {
public byte[] getData() {
return data;
}
// 0
// random * 256
// 101
// 233
// 45092 (short)
// 35784 if random * 2= 0
// random * 256
// 64
// 38
// Math.random() * 65536
// Math.random() * 65536
// offset - start offset (exc. the first 0 sent) - size byte.
}
@@ -2,4 +2,3 @@
* Contains event implementations.
*/
package org.apollo.game.event.impl;
@@ -2,4 +2,3 @@
* Contains classes related to the event management in the game.
*/
package org.apollo.game.event;
+18 -18
View File
@@ -7,16 +7,16 @@ package org.apollo.game.model;
*/
public enum Direction {
/**
* East movement.
*/
EAST(4),
/**
* No movement.
*/
NONE(-1),
/**
* North west movement.
*/
NORTH_WEST(0),
/**
* North movement.
*/
@@ -28,9 +28,19 @@ public enum Direction {
NORTH_EAST(2),
/**
* North west movement.
* West movement.
*/
NORTH_WEST(0),
WEST(3),
/**
* East movement.
*/
EAST(4),
/**
* South west movement.
*/
SOUTH_WEST(5),
/**
* South movement.
@@ -40,17 +50,7 @@ public enum Direction {
/**
* South east movement.
*/
SOUTH_EAST(7),
/**
* South west movement.
*/
SOUTH_WEST(5),
/**
* West movement.
*/
WEST(3);
SOUTH_EAST(7);
/**
* An empty direction array.
+3 -3
View File
@@ -1,14 +1,14 @@
package org.apollo.game.model;
/**
* Represents an in-game entity, such as a character, object, projectile etc.
* Represents an in-game entity, such as a mob, object, projectile etc.
*
* @author Major
*/
public abstract class Entity {
/**
* The position of the entity.
* The position of this entity.
*/
protected Position position;
@@ -20,7 +20,7 @@ public abstract class Entity {
public abstract EntityType getEntityType();
/**
* Gets the position of this entity.
* Gets the {@link Position} of this entity.
*
* @return The position.
*/
+1 -1
View File
@@ -33,7 +33,7 @@ public enum EntityType {
PROJECTILE,
/**
* A permanent object appearing on the map.
* A permanent object appearing on the map, loaded from the cache.
*/
STATIC_OBJECT;
@@ -8,59 +8,59 @@ package org.apollo.game.model;
public final class EquipmentConstants {
/**
* The amulet slot.
* The hat slot.
*/
public static final int AMULET = 2;
/**
* The arrows slot.
*/
public static final int ARROWS = 13;
public static final int HAT = 0;
/**
* The cape slot.
*/
public static final int CAPE = 1;
/**
* The amulet slot.
*/
public static final int AMULET = 2;
/**
* The weapon slot.
*/
public static final int WEAPON = 3;
/**
* The chest slot.
*/
public static final int CHEST = 4;
/**
* The feet slot.
*/
public static final int FEET = 10;
/**
* The hands slot.
*/
public static final int HANDS = 9;
/**
* The hat slot.
*/
public static final int HAT = 0;
/**
* The legs slot.
*/
public static final int LEGS = 7;
/**
* The ring slot.
*/
public static final int RING = 12;
/**
* The shield slot.
*/
public static final int SHIELD = 5;
/**
* The weapon slot.
* The legs slot.
*/
public static final int WEAPON = 3;
public static final int LEGS = 7;
/**
* The hands slot.
*/
public static final int HANDS = 9;
/**
* The feet slot.
*/
public static final int FEET = 10;
/**
* The ring slot.
*/
public static final int RING = 12;
/**
* The arrows slot.
*/
public static final int ARROWS = 13;
/**
* Default private constructor to prevent instantiation;
+6 -6
View File
@@ -7,15 +7,15 @@ package org.apollo.game.model;
*/
public enum Gender {
/**
* The female gender.
*/
FEMALE(1),
/**
* The male gender.
*/
MALE(0);
MALE(0),
/**
* The female gender.
*/
FEMALE(1);
/**
* An integer representation used by the client.
+9 -14
View File
@@ -73,7 +73,6 @@ public final class Inventory implements Cloneable {
* Creates an inventory.
*
* @param capacity The capacity.
* @throws IllegalArgumentException If the capacity is negative.
*/
public Inventory(int capacity) {
this(capacity, StackMode.STACK_STACKABLE_ITEMS);
@@ -83,7 +82,7 @@ public final class Inventory implements Cloneable {
* Creates an inventory.
*
* @param capacity The capacity.
* @param mode The stacking mode.
* @param mode The {@link StackMode}.
* @throws IllegalArgumentException If the capacity is negative.
* @throws NullPointerException If the mode is {@code null}.
*/
@@ -92,7 +91,7 @@ public final class Inventory implements Cloneable {
throw new IllegalArgumentException("capacity cannot be negative");
}
if (mode == null) {
throw new NullPointerException("mode");
throw new NullPointerException("stacking mode cannot be null");
}
this.capacity = capacity;
items = new Item[capacity];
@@ -195,9 +194,9 @@ public final class Inventory implements Cloneable {
}
/**
* Adds a listener.
* Adds an {@link InventoryListener}.
*
* @param listener The listener to add.
* @param listener The listener.
*/
public void addListener(InventoryListener listener) {
listeners.add(listener);
@@ -298,7 +297,6 @@ public final class Inventory implements Cloneable {
*
* @param slot The slot.
* @return The item, or {@code null} if the slot is empty.
* @throws IndexOutOfBoundsException If the slot is out of bounds.
*/
public Item get(int slot) {
checkBounds(slot);
@@ -447,7 +445,6 @@ public final class Inventory implements Cloneable {
*
* @param slot
* @return The item that was in the slot.
* @throws IndexOutOfBoundsException If the slot is out of bounds.
*/
public Item reset(int slot) {
checkBounds(slot);
@@ -467,7 +464,6 @@ public final class Inventory implements Cloneable {
* @param slot The slot.
* @param item The item, or {@code null} to remove the item that is in the slot.
* @return The item that was in the slot.
* @throws IndexOutOfBoundsException If the slot is out of bounds.
*/
public Item set(int slot, Item item) {
if (item == null) {
@@ -529,7 +525,6 @@ public final class Inventory implements Cloneable {
* @param insert If the swap should be done in insertion mode.
* @param oldSlot The old slot.
* @param newSlot The new slot.
* @throws IndexOutOfBoundsException If the slot is out of bounds.
*/
public void swap(boolean insert, int oldSlot, int newSlot) {
checkBounds(oldSlot);
@@ -543,13 +538,14 @@ public final class Inventory implements Cloneable {
for (int slot = oldSlot; slot > newSlot; slot--) {
swap(slot, slot - 1);
}
} // else no change is required - aren't we lucky?
}
forceRefresh();
} else {
Item temp = items[oldSlot];
Item tmp = items[oldSlot];
items[oldSlot] = items[newSlot];
items[newSlot] = temp;
notifyItemsUpdated(); // TODO can we just fire for the two slots?
items[newSlot] = tmp;
notifyItemUpdated(oldSlot);
notifyItemUpdated(newSlot);
}
}
@@ -558,7 +554,6 @@ public final class Inventory implements Cloneable {
*
* @param oldSlot The old slot.
* @param newSlot The new slot.
* @throws IndexOutOufBoundsException If the slot is out of bounds.
*/
public void swap(int oldSlot, int newSlot) {
swap(false, oldSlot, newSlot);
+83 -90
View File
@@ -4,13 +4,12 @@ import java.util.ArrayList;
import java.util.List;
import org.apollo.game.action.Action;
import org.apollo.game.event.Event;
import org.apollo.game.model.Inventory.StackMode;
import org.apollo.game.model.def.NpcDefinition;
import org.apollo.game.scheduling.impl.SkillNormalizationTask;
import org.apollo.game.sync.block.SynchronizationBlock;
import org.apollo.game.sync.block.SynchronizationBlockSet;
import org.apollo.util.CharacterRepository;
import org.apollo.util.MobRepository;
/**
* A {@link Mob} is a living entity in the world, such as a player or NPC.
@@ -20,95 +19,80 @@ import org.apollo.util.CharacterRepository;
public abstract class Mob extends Entity {
/**
* The character's current action.
* This mob's current action.
*/
private Action<?> action;
/**
* The character's bank.
* This mob's set of {@link SynchronizationBlock}s.
*/
private final Inventory bank = new Inventory(InventoryConstants.BANK_CAPACITY, StackMode.STACK_ALWAYS);
protected SynchronizationBlockSet blockSet = new SynchronizationBlockSet();
/**
* A set of {@link SynchronizationBlock}s.
* This mob's {@link NpcDefinition). A {@link Player} only uses this if they are appearing as an npc in-game.
*/
private SynchronizationBlockSet blockSet = new SynchronizationBlockSet();
protected NpcDefinition definition;
/**
* The character's {@link NpcDefinition). This is only used by an instance of the {@link Player} class if they are
* appearing as an npc in-game.
*/
private NpcDefinition definition;
/**
* The character's equipment.
* This mob's equipment.
*/
private final Inventory equipment = new Inventory(InventoryConstants.EQUIPMENT_CAPACITY, StackMode.STACK_ALWAYS);
/**
* The first direction.
* This mob's first movement {@link Direction}.
*/
private Direction firstDirection = Direction.NONE;
/**
* The index of this character in the {@link CharacterRepository} it belongs to.
* The index of this mob in the {@link MobRepository} it belongs to.
*/
private int index = -1;
/**
* The character's inventory.
* This mob's inventory.
*/
private final Inventory inventory = new Inventory(InventoryConstants.INVENTORY_CAPACITY);
/**
* The list of local npcs.
* This mob's {@link List} of local npcs.
*/
private final List<Npc> localNpcs = new ArrayList<Npc>();
/**
* A list of local players.
* This mob's {@link List} of local players.
*/
private final List<Player> localPlayers = new ArrayList<Player>();
/**
* The second direction.
* This mob's second movement direction.
*/
private Direction secondDirection = Direction.NONE;
/**
* The character's skill set.
* This mob's skill set.
*/
private final SkillSet skillSet = new SkillSet();
/**
* Teleportation flag.
* Indicates whether this mob is currently teleporting or not.
*/
private boolean teleporting = false;
/**
* The walking queue.
* This mob's walking queue.
*/
private final WalkingQueue walkingQueue = new WalkingQueue(this);
/**
* Creates a new character with the specified initial position.
* Creates a new mob with the specified initial {@link Position}.
*
* @param position The initial position of this character.
* @param position The initial position.
*/
public Mob(Position position) {
this.position = position;
init();
}
/**
* Gets the character's bank.
*
* @return The character's bank.
*/
public Inventory getBank() {
return bank;
}
/**
* Gets the {@link SynchronizationBlockSet}.
*
@@ -118,6 +102,19 @@ public abstract class Mob extends Entity {
return blockSet;
}
/**
* Deals damage to this mob.
*
* @param damage The damage dealt.
* @param type The type of damage.
* @param secondary Whether this should be dealt as a secondary hit or not.
*/
public void damage(int damage, int type, boolean secondary) {
Skill hitpoints = skillSet.getSkill(Skill.HITPOINTS);
blockSet.add(SynchronizationBlock.createHitUpdateBlock(damage, type, hitpoints.getCurrentLevel(),
hitpoints.getMaximumLevel(), secondary));
}
/**
* Gets the directions as an array.
*
@@ -132,27 +129,27 @@ public abstract class Mob extends Entity {
}
/**
* Gets the character's equipment.
* Gets the mob's equipment.
*
* @return The character's equipment.
* @return The mob's equipment.
*/
public Inventory getEquipment() {
return equipment;
}
/**
* Gets the first direction.
* Gets the first {@link Direction}.
*
* @return The first direction.
* @return The direction.
*/
public Direction getFirstDirection() {
return firstDirection;
}
/**
* Gets the index of this character.
* Gets the index of this mob.
*
* @return The index of this character.
* @return The index.
*/
public int getIndex() {
synchronized (this) {
@@ -161,34 +158,34 @@ public abstract class Mob extends Entity {
}
/**
* Gets the character's inventory.
* Gets the mob's inventory.
*
* @return The character's inventory.
* @return The inventory.
*/
public Inventory getInventory() {
return inventory;
}
/**
* Gets the local npc list.
* Gets the local npc {@link List}.
*
* @return The local npc list.
* @return The list.
*/
public List<Npc> getLocalNpcList() {
return localNpcs;
}
/**
* Gets the local player list.
* Gets the local player {@link List}.
*
* @return The local player list.
* @return The list.
*/
public List<Player> getLocalPlayerList() {
return localPlayers;
}
/**
* Gets this character's {@link NpcDefinition}.
* Gets this mob's {@link NpcDefinition}.
*
* @param definition The definition.
*/
@@ -196,31 +193,26 @@ public abstract class Mob extends Entity {
return definition;
}
@Override
public Position getPosition() {
return position;
}
/**
* Gets the second direction.
* Gets the second {@link Direction}.
*
* @return The second direction.
* @return The direction.
*/
public Direction getSecondDirection() {
return secondDirection;
}
/**
* Gets the character's skill set.
* Gets this mob's {@link SkillSet}.
*
* @return The character's skill set.
* @return The skill set.
*/
public SkillSet getSkillSet() {
return skillSet;
}
/**
* Gets the walking queue.
* Gets the {@link WalkingQueue}.
*
* @return The walking queue.
*/
@@ -229,14 +221,14 @@ public abstract class Mob extends Entity {
}
/**
* Initialises this character.
* Initialises this mob.
*/
private void init() {
World.getWorld().schedule(new SkillNormalizationTask(this));
}
/**
* Checks if this character is active.
* Checks if this mob is active.
*
* @return {@code true} if so, {@code false} if not.
*/
@@ -245,7 +237,7 @@ public abstract class Mob extends Entity {
}
/**
* Checks if this player is currently teleporting.
* Checks if this mob is currently teleporting.
*
* @return {@code true} if so, {@code false} if not.
*/
@@ -254,7 +246,7 @@ public abstract class Mob extends Entity {
}
/**
* Plays the specified animation.
* Plays the specified {@link Animation}.
*
* @param animation The animation.
*/
@@ -263,7 +255,7 @@ public abstract class Mob extends Entity {
}
/**
* Plays the specified graphic.
* Plays the specified {@link Graphic}.
*
* @param graphic The graphic.
*/
@@ -279,18 +271,7 @@ public abstract class Mob extends Entity {
}
/**
* Sends an {@link Event} to either:
* <ul>
* <li>The client if this {@link Mob} is a {@link Player}.</li>
* <li>The AI routines if this {@link Mob} is an NPC</li>
* </ul>
*
* @param event The event.
*/
public abstract void send(Event event);
/**
* Sets this character's {@link NpcDefinition}.
* Sets this mob's {@link NpcDefinition}.
*
* @param definition The definition.
*/
@@ -299,7 +280,7 @@ public abstract class Mob extends Entity {
}
/**
* Sets the next directions for this character.
* Sets the next directions for this mob.
*
* @param first The first direction.
* @param second The second direction.
@@ -310,9 +291,9 @@ public abstract class Mob extends Entity {
}
/**
* Sets the index of this character.
* Sets the index of this mob.
*
* @param index The index of this character.
* @param index The index.
*/
public void setIndex(int index) {
synchronized (this) {
@@ -321,18 +302,29 @@ public abstract class Mob extends Entity {
}
/**
* Sets the position of this character.
* Sets the position of this mob.
*
* @param position The position of this character.
* @param position The position.
*/
public void setPosition(Position position) {
this.position = position;
}
/**
* Sets the teleporting flag.
* Forces this mob to shout a message. Note that messages can only be shown in the chat box if they are said by a
* player.
*
* @param teleporting {@code true} if the player is teleporting, {@code false} if not.
* @param message The message.
* @param chatBox If the message should be shown in the player's chat box.
*/
public void shout(String message, boolean chatBox) {
blockSet.add(SynchronizationBlock.createForceChatBlock(message));
}
/**
* Sets whether this mob is teleporting or not.
*
* @param teleporting {@code true} if the mob is teleporting, {@code false} if not.
*/
public void setTeleporting(boolean teleporting) {
this.teleporting = teleporting;
@@ -366,21 +358,22 @@ public abstract class Mob extends Entity {
}
/**
* Stops the current animation.
* Stops the current {@link Animation}.
*/
public void stopAnimation() {
playAnimation(Animation.STOP_ANIMATION);
}
/**
* Stops the current graphic.
* Stops the current {@link Graphic}.
*/
public void stopGraphic() {
playGraphic(Graphic.STOP_GRAPHIC);
}
/**
* Teleports this character to the specified position, setting the appropriate flags and clearing the walking queue.
* Teleports this mob to the specified {@link Position}, setting the appropriate flags and clearing the walking
* queue.
*
* @param position The position.
*/
@@ -388,11 +381,11 @@ public abstract class Mob extends Entity {
teleporting = true;
this.position = position;
walkingQueue.clear();
stopAction(); // TODO do it on any movement is a must.. walking queue perhaps?
stopAction(); // TODO do it on any movement is a must... walking queue perhaps?
}
/**
* Turns the character to face the specified position.
* Turns the mob to face the specified {@link Position}.
*
* @param position The position to face.
*/
@@ -401,12 +394,12 @@ public abstract class Mob extends Entity {
}
/**
* Updates the character's interacting character.
* Updates this mob's interacting mob.
*
* @param index The index of the interacting character.
* @param index The index of the interacting mob.
*/
public void updateInteractingCharacter(int index) {
blockSet.add(SynchronizationBlock.createInteractingCharacterBlock(index));
public void updateInteractingMob(int index) {
blockSet.add(SynchronizationBlock.createInteractingMobBlock(index));
}
}
+24 -21
View File
@@ -1,19 +1,14 @@
package org.apollo.game.model;
import org.apollo.game.event.Event;
import org.apollo.game.model.def.NpcDefinition;
import org.apollo.game.sync.block.SynchronizationBlock;
/**
* An {@link Npc} is a {@link Mob} that is not being controlled by a player.
*
* @author Major
*/
public class Npc extends Mob {
/**
* This npc's definition.
*/
private final NpcDefinition definition;
public final class Npc extends Mob {
/**
* Creates a new npc with the specified id and {@link Position}.
@@ -36,23 +31,31 @@ public class Npc extends Mob {
this.definition = definition;
}
/**
* Gets the id of this npc. Shorthand for {@link #getDefinition().getId()}.
*
* @return The id.
*/
public int getId() {
return definition.getId();
}
/**
* Transforms this npc into the npc with the specified id.
*
* @param id The id.
*/
public void transform(int id) {
if (id < 0 || id > NpcDefinition.count()) {
throw new IllegalArgumentException("id to transform to is out of bounds");
}
definition = NpcDefinition.lookup(id);
blockSet.add(SynchronizationBlock.createTransformBlock(id));
}
@Override
public EntityType getEntityType() {
return EntityType.NPC;
}
/**
* Gets this npc's {@link NpcDefinition}
*
* @return The definition.
*/
@Override
public NpcDefinition getNpcDefinition() {
return definition;
}
@Override
public void send(Event event) {
}
}
+41 -20
View File
@@ -12,6 +12,7 @@ import org.apollo.game.event.impl.ServerMessageEvent;
import org.apollo.game.event.impl.SetWidgetTextEvent;
import org.apollo.game.event.impl.SwitchTabInterfaceEvent;
import org.apollo.game.event.impl.UpdateRunEnergyEvent;
import org.apollo.game.model.Inventory.StackMode;
import org.apollo.game.model.inter.InterfaceConstants;
import org.apollo.game.model.inter.InterfaceSet;
import org.apollo.game.model.inter.bank.BankConstants;
@@ -102,20 +103,25 @@ public final class Player extends Mob {
*/
private Appearance appearance = Appearance.DEFAULT_APPEARANCE;
/**
* This player's bank.
*/
private final Inventory bank = new Inventory(InventoryConstants.BANK_CAPACITY, StackMode.STACK_ALWAYS);
/**
* A {@link List} of this player's mouse clicks.
*/
private Deque<Point> clicks = new ArrayDeque<Point>();
/**
* The player's credentials.
* This player's credentials.
*/
private PlayerCredentials credentials;
/**
* A flag indicating if the player has designed their character.
* A flag indicating if the player has designed their avatar.
*/
private boolean designedCharacter = false;
private boolean designedAvatar = false;
/**
* A flag which indicates there are npcs that couldn't be added.
@@ -150,7 +156,7 @@ public final class Player extends Mob {
/**
* This player's prayer icon.
*/
private int prayerIcon = -1;
private int prayerIcon = 0;
/**
* The privilege level.
@@ -246,6 +252,15 @@ public final class Player extends Mob {
return appearance;
}
/**
* Gets the mob's bank.
*
* @return The bank.
*/
public Inventory getBank() {
return bank;
}
/**
* Gets the {@link Deque} of clicks.
*
@@ -369,12 +384,12 @@ public final class Player extends Mob {
}
/**
* Checks if the player has designed their character.
* Checks if the player has designed their avatar.
*
* @return A flag indicating if the player has designed their character.
* @return A flag indicating if the player has designed their avatar.
*/
public boolean hasDesignedCharacter() {
return designedCharacter;
public boolean hasDesignedAvatar() {
return designedAvatar;
}
/**
@@ -424,8 +439,6 @@ public final class Player extends Mob {
InventoryListener fullInventoryListener = new FullInventoryListener(this,
FullInventoryListener.FULL_INVENTORY_MESSAGE);
InventoryListener fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE);
InventoryListener fullEquipmentListener = new FullInventoryListener(this,
FullInventoryListener.FULL_EQUIPMENT_MESSAGE);
// equipment appearance listener
InventoryListener appearanceListener = new AppearanceInventoryListener(this);
@@ -444,7 +457,6 @@ public final class Player extends Mob {
bank.addListener(fullBankListener);
equipment.addListener(syncEquipmentListener);
equipment.addListener(appearanceListener);
equipment.addListener(fullEquipmentListener);
}
/**
@@ -530,7 +542,11 @@ public final class Player extends Mob {
viewingDistance = 1;
}
@Override
/**
* Sends an {@link Event} to this player.
*
* @param event The event.
*/
public void send(Event event) {
if (isActive()) {
if (!queuedEvents.isEmpty()) {
@@ -552,8 +568,8 @@ public final class Player extends Mob {
send(new IdAssignmentEvent(getIndex(), members)); // TODO should this be sent when we reconnect?
sendMessage("Welcome to RuneScape.");
if (!designedCharacter) {
interfaceSet.openWindow(InterfaceConstants.CHARACTER_DESIGN);
if (!designedAvatar) {
interfaceSet.openWindow(InterfaceConstants.AVATAR_DESIGN);
}
int[] tabs = InterfaceConstants.DEFAULT_INVENTORY_TABS;
@@ -569,7 +585,7 @@ public final class Player extends Mob {
}
/**
* Sends a message to the character.
* Sends a message to the player.
*
* @param message The message.
*/
@@ -605,12 +621,12 @@ public final class Player extends Mob {
}
/**
* Sets the character design flag.
* Sets the design flag.
*
* @param designedCharacter A flag indicating if the character has been designed.
* @param designed A flag indicating if the player has been designed.
*/
public void setDesignedCharacter(boolean designedCharacter) {
this.designedCharacter = designedCharacter;
public void setDesigned(boolean designed) {
this.designedAvatar = designed;
}
/**
@@ -700,9 +716,14 @@ public final class Player extends Mob {
this.withdrawingNotes = withdrawingNotes;
}
@Override
public void shout(String message, boolean chatBox) {
blockSet.add(SynchronizationBlock.createForceChatBlock(chatBox ? '~' + message : message));
}
@Override
public void teleport(Position position) {
super.teleport(position); // TODO put this in the same place as Character#teleport and WalkEventHandler!!
super.teleport(position);
if (interfaceSet.size() > 0) {
interfaceSet.close();
}
+16 -23
View File
@@ -48,8 +48,8 @@ public final class SkillSet {
* @return The minimum level.
*/
public static int getLevelForExperience(double experience) {
int points = 0;
int output = 0;
int points = 0, output = 0;
for (int lvl = 1; lvl <= 99; lvl++) {
points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
output = (int) Math.floor(points / 4);
@@ -110,22 +110,21 @@ public final class SkillSet {
setSkill(id, new Skill(newExperience, newCurrentLevel, newMaximumLevel));
if (delta > 0) {
// here so it notifies using the updated skill
notifyLevelledUp(id);
notifyLevelledUp(id); // here so it notifies using the updated skill
}
}
/**
* Adds a listener.
* Adds a {@link SkillListener} to this set.
*
* @param listener The listener to add.
* @param listener The listener.
*/
public boolean addListener(SkillListener listener) {
return listeners.add(listener);
}
/**
* Gets the combat level for this skill set.
* Calculates the combat level for this skill set.
*
* @return The combat level.
*/
@@ -138,15 +137,12 @@ public final class SkillSet {
int ranged = skills[Skill.RANGED].getMaximumLevel();
int magic = skills[Skill.MAGIC].getMaximumLevel();
double combatLevel = (defence + hitpoints + Math.floor(prayer / 2)) * 0.25;
double base = (defence + hitpoints + Math.floor(prayer / 2)) * 0.25;
double melee = (attack + strength) * 0.325;
double range = ranged * 0.4875;
double mage = magic * 0.4875;
this.combatLevel = (int) (combatLevel + Math.max(melee, Math.max(range, mage)));
this.combatLevel = (int) (base + Math.max(melee, Math.max(range, mage)));
}
/**
@@ -169,7 +165,7 @@ public final class SkillSet {
}
/**
* Gets the combat level for this skill set.
* Gets the combat level of this skill set.
*
* @return The combat level.
*/
@@ -218,13 +214,10 @@ public final class SkillSet {
int cur = skills[id].getCurrentLevel();
int max = skills[id].getMaximumLevel();
if (cur > max) {
cur--;
} else if (max > cur) {
cur++;
} else {
if (cur == max) {
continue;
}
cur += cur < max ? 1 : -1;
setSkill(id, new Skill(skills[id].getExperience(), cur, max));
}
@@ -270,14 +263,14 @@ public final class SkillSet {
}
/**
* Removes all the listeners.
* Removes all the {@link SkillListener}s.
*/
public void removeAllListeners() {
listeners.clear();
}
/**
* Removes a listener.
* Removes a {@link SkillListener}.
*
* @param listener The listener to remove.
*/
@@ -286,7 +279,7 @@ public final class SkillSet {
}
/**
* Sets a skill.
* Sets a {@link Skill}.
*
* @param id The id.
* @param skill The skill.
@@ -298,7 +291,7 @@ public final class SkillSet {
}
/**
* Gets the number of skills.
* Gets the number of {@link Skill}s in this set.
*
* @return The number of skills.
*/
@@ -307,7 +300,7 @@ public final class SkillSet {
}
/**
* Re-enables the firing of events.
* Starts the firing of events.
*/
public void startFiringEvents() {
firingEvents = true;
+20 -19
View File
@@ -51,9 +51,9 @@ public final class WalkingQueue {
private static final int MAXIMUM_SIZE = 128;
/**
* The character whose walking queue this is.
* The mob whose walking queue this is.
*/
private final Mob character;
private final Mob mob;
/**
* The old queue of directions.
@@ -71,32 +71,32 @@ public final class WalkingQueue {
private boolean runningQueue;
/**
* Creates a walking queue for the specified character.
* Creates a walking queue for the specified mob.
*
* @param character The character.
* @param mob The mob.
*/
public WalkingQueue(Mob character) {
this.character = character;
public WalkingQueue(Mob mob) {
this.mob = mob;
}
/**
* Adds the first step to the queue, attempting to connect the server and client position by looking at the previous
* queue.
*
* @param clientConnectionPosition The first step.
* @param clientPosition The first step.
* @return {@code true} if the queues could be connected correctly, {@code false} if not.
*/
public boolean addFirstStep(Position clientConnectionPosition) {
Position serverPosition = character.getPosition();
public boolean addFirstStep(Position clientPosition) {
Position serverPosition = mob.getPosition();
int deltaX = clientConnectionPosition.getX() - serverPosition.getX();
int deltaY = clientConnectionPosition.getY() - serverPosition.getY();
int deltaX = clientPosition.getX() - serverPosition.getX();
int deltaY = clientPosition.getY() - serverPosition.getY();
if (Direction.isConnectable(deltaX, deltaY)) {
points.clear();
oldPoints.clear();
addStep(clientConnectionPosition);
addStep(clientPosition);
return true;
}
@@ -119,7 +119,7 @@ public final class WalkingQueue {
addStep(travelBackPosition);
}
addStep(clientConnectionPosition);
addStep(clientPosition);
return true;
}
}
@@ -147,7 +147,7 @@ public final class WalkingQueue {
Direction direction = Direction.fromDeltas(deltaX, deltaY);
if (direction != Direction.NONE) {
Point p = new Point(new Position(x, y, character.getPosition().getHeight()), direction);
Point p = new Point(new Position(x, y, mob.getPosition().getHeight()), direction);
points.add(p);
oldPoints.add(p);
}
@@ -202,7 +202,7 @@ public final class WalkingQueue {
private Point getLast() {
Point last = points.peekLast();
if (last == null) {
return new Point(character.getPosition(), Direction.NONE);
return new Point(mob.getPosition(), Direction.NONE);
}
return last;
}
@@ -211,17 +211,18 @@ public final class WalkingQueue {
* Called every pulse, updates the queue.
*/
public void pulse() {
Position position = character.getPosition();
Position position = mob.getPosition();
Direction first = Direction.NONE;
Direction second = Direction.NONE;
Point next = points.poll();
if (next != null) {
mob.stopAction();
first = next.direction;
position = next.position;
if (runningQueue /* or run toggled AND enough energy */) {
if (runningQueue /* and enough energy */) {
next = points.poll();
if (next != null) {
second = next.direction;
@@ -230,8 +231,8 @@ public final class WalkingQueue {
}
}
character.setDirections(first, second);
character.setPosition(position);
mob.setDirections(first, second);
mob.setPosition(position);
}
/**
+27 -28
View File
@@ -26,13 +26,13 @@ import org.apollo.game.model.sector.SectorRepository;
import org.apollo.game.scheduling.ScheduledTask;
import org.apollo.game.scheduling.Scheduler;
import org.apollo.io.EquipmentDefinitionParser;
import org.apollo.util.CharacterRepository;
import org.apollo.util.MobRepository;
import org.apollo.util.plugin.PluginManager;
/**
* The world class is a singleton which contains objects like the {@link CharacterRepository} for players and NPCs. It
* should only contain things relevant to the in-game world and not classes which deal with I/O and such (these may be
* better off inside some custom {@link Service} or other code, however, the circumstances are rare).
* The world class is a singleton which contains objects like the {@link MobRepository} for players and NPCs. It should
* only contain things relevant to the in-game world and not classes which deal with I/O and such (these may be better
* off inside some custom {@link Service} or other code, however, the circumstances are rare).
*
* @author Graham
*/
@@ -86,20 +86,14 @@ public final class World {
private final CommandDispatcher dispatcher = new CommandDispatcher();
/**
* The {@link CharacterRepository} of {@link Npc}s.
* The {@link MobRepository} of {@link Npc}s.
*/
private final CharacterRepository<Npc> npcRepository = new CharacterRepository<Npc>(WorldConstants.MAXIMUM_NPCS);
private final MobRepository<Npc> npcRepository = new MobRepository<Npc>(WorldConstants.MAXIMUM_NPCS);
/**
* The {@link CharacterRepository} of {@link Player}s.
* The {@link MobRepository} of {@link Player}s.
*/
private final CharacterRepository<Player> playerRepository = new CharacterRepository<Player>(
WorldConstants.MAXIMUM_PLAYERS);
/**
* The release number (i.e. version) of this world.
*/
private int releaseNumber;
private final MobRepository<Player> playerRepository = new MobRepository<Player>(WorldConstants.MAXIMUM_PLAYERS);
/**
* A {@link Map} of player usernames and the player objects.
@@ -111,6 +105,11 @@ public final class World {
*/
private PluginManager pluginManager;
/**
* The release number (i.e. version) of this world.
*/
private int releaseNumber;
/**
* This world's {@link SectorRepository}.
*/
@@ -128,7 +127,7 @@ public final class World {
}
/**
* Gets the command dispatcher. TODO should this be here?
* Gets the command dispatcher.
*
* @return The command dispatcher.
*/
@@ -141,7 +140,7 @@ public final class World {
*
* @return The npc repository.
*/
public CharacterRepository<Npc> getNpcRepository() {
public MobRepository<Npc> getNpcRepository() {
return npcRepository;
}
@@ -156,14 +155,14 @@ public final class World {
}
/**
* Gets the character repository.
* Gets the player repository.
* <p>
* Note: players should be registered and unregistered using {@link World#register(Player)} and
* {@link World#unregister(Player)} respectively, not by adding to or removing from this repository directly.
*
* @return The character repository.
* @return The player repository.
*/
public CharacterRepository<Player> getPlayerRepository() {
public MobRepository<Player> getPlayerRepository() {
return playerRepository;
}
@@ -176,6 +175,15 @@ public final class World {
return pluginManager;
}
/**
* Gets the release number of this world.
*
* @return The release number.
*/
public int getReleaseNumber() {
return releaseNumber;
}
/**
* Initialises the world by loading definitions from the specified file system.
*
@@ -288,15 +296,6 @@ public final class World {
return RegistrationStatus.WORLD_FULL;
}
/**
* Gets the release number of this world.
*
* @return The release number.
*/
public int getReleaseNumber() {
return releaseNumber;
}
/**
* Schedules a new task.
*
@@ -3,4 +3,3 @@
* NPCs, etc.
*/
package org.apollo.game.model.def;
@@ -8,9 +8,9 @@ package org.apollo.game.model.inter;
public class InterfaceConstants {
/**
* The character design interface id.
* The avatar design interface id.
*/
public static final int CHARACTER_DESIGN = 3559;
public static final int AVATAR_DESIGN = 3559;
/**
* The default inventory tab ids.
@@ -63,7 +63,6 @@ public final class InterfaceSet {
*/
public void close() {
closeAndNotify();
player.send(new CloseInterfaceEvent());
}
@@ -33,7 +33,6 @@ public final class BankUtils {
Inventory bank = player.getBank();
Item item = inventory.get(slot);
int newId = ItemDefinition.noteToItem(item.getId());
if (bank.freeSlots() == 0 && !bank.contains(item.getId())) {
@@ -126,7 +125,7 @@ public final class BankUtils {
}
/**
* Default private constructor to prevent insantiation.
* Default private constructor to prevent instantiation.
*/
private BankUtils() {
@@ -2,4 +2,3 @@
* Contains bank-related classes.
*/
package org.apollo.game.model.inter.bank;
@@ -2,4 +2,3 @@
* Contains interface-related classes.
*/
package org.apollo.game.model.inter;
@@ -17,11 +17,6 @@ public final class FullInventoryListener extends InventoryAdapter {
*/
public static final String FULL_BANK_MESSAGE = "Not enough bank space.";
/**
* The equipment full message.
*/
public static final String FULL_EQUIPMENT_MESSAGE = "Not enough equipment space."; // TODO confirm if possible
/**
* The inventory full message.
*/
@@ -12,17 +12,17 @@ public abstract class InventoryAdapter implements InventoryListener {
@Override
public void capacityExceeded(Inventory inventory) {
/* empty */
}
@Override
public void itemsUpdated(Inventory inventory) {
/* empty */
}
@Override
public void itemUpdated(Inventory inventory, int slot, Item item) {
/* empty */
}
}
@@ -2,4 +2,3 @@
* Contains inventory listeners.
*/
package org.apollo.game.model.inv;
@@ -2,4 +2,3 @@
* Contains models related to in-game objects.
*/
package org.apollo.game.model.obj;
@@ -3,4 +3,3 @@
* players and NPCs.
*/
package org.apollo.game.model;
@@ -12,17 +12,17 @@ public abstract class SkillAdapter implements SkillListener {
@Override
public void levelledUp(SkillSet set, int id, Skill skill) {
/* empty */
}
@Override
public void skillsUpdated(SkillSet set) {
/* empty */
}
@Override
public void skillUpdated(SkillSet set, int id, Skill skill) {
/* empty */
}
}
@@ -11,25 +11,25 @@ import org.apollo.game.model.SkillSet;
public interface SkillListener {
/**
* Called when a skill is levelled up.
* Called when a {@link Skill} is levelled up.
*
* @param set The skill set.
* @param set The {@link SkillSet}.
* @param id The skill's id.
* @param skill The skill.
*/
public void levelledUp(SkillSet set, int id, Skill skill);
/**
* Called when all the skills are updated.
* Called when all {@link Skill}s are updated.
*
* @param set The skill set.
* @param set The {@link SkillSet}.
*/
public void skillsUpdated(SkillSet set);
/**
* Called when a single skill is updated.
* Called when a single {@link Skill} is updated.
*
* @param set The skill set.
* @param set The {@link SkillSet}.
* @param id The skill's id.
* @param skill The skill.
*/
@@ -2,4 +2,3 @@
* Contains skill listeners.
*/
package org.apollo.game.model.skill;
-1
View File
@@ -2,4 +2,3 @@
* Contains classes related to the game server.
*/
package org.apollo.game;
@@ -12,26 +12,26 @@ import org.apollo.game.scheduling.ScheduledTask;
public final class SkillNormalizationTask extends ScheduledTask {
/**
* The character.
* The mob.
*/
private final Mob character;
private final Mob mob;
/**
* Creates the skill normalization task.
*
* @param character The character.
* @param mob The mob.
*/
public SkillNormalizationTask(Mob character) {
public SkillNormalizationTask(Mob mob) {
super(100, false);
this.character = character;
this.mob = mob;
}
@Override
public void execute() {
if (!character.isActive()) { // TODO is this check okay for this? an NPC could be temporarily removed from list
if (!mob.isActive()) {
stop();
} else {
character.getSkillSet().normalize();
mob.getSkillSet().normalize();
}
}
@@ -2,4 +2,3 @@
* Contains scheduled task implementations.
*/
package org.apollo.game.scheduling.impl;
@@ -3,4 +3,3 @@
* future pulses periodically.
*/
package org.apollo.game.scheduling;
@@ -17,7 +17,7 @@ import org.apollo.game.sync.task.PostPlayerSynchronizationTask;
import org.apollo.game.sync.task.PreNpcSynchronizationTask;
import org.apollo.game.sync.task.PrePlayerSynchronizationTask;
import org.apollo.game.sync.task.SynchronizationTask;
import org.apollo.util.CharacterRepository;
import org.apollo.util.MobRepository;
import org.apollo.util.NamedThreadFactory;
/**
@@ -54,8 +54,8 @@ public final class ParallelClientSynchronizer extends ClientSynchronizer {
@Override
public void synchronize() {
CharacterRepository<Player> players = World.getWorld().getPlayerRepository();
CharacterRepository<Npc> npcs = World.getWorld().getNpcRepository();
MobRepository<Player> players = World.getWorld().getPlayerRepository();
MobRepository<Npc> npcs = World.getWorld().getNpcRepository();
int playerCount = players.size();
int npcCount = npcs.size();
@@ -11,7 +11,7 @@ import org.apollo.game.sync.task.PostPlayerSynchronizationTask;
import org.apollo.game.sync.task.PreNpcSynchronizationTask;
import org.apollo.game.sync.task.PrePlayerSynchronizationTask;
import org.apollo.game.sync.task.SynchronizationTask;
import org.apollo.util.CharacterRepository;
import org.apollo.util.MobRepository;
/**
* An implementation of {@link ClientSynchronizer} which runs in a single thread (the {@link GameService} thread from
@@ -26,8 +26,8 @@ public final class SequentialClientSynchronizer extends ClientSynchronizer {
@Override
public void synchronize() {
CharacterRepository<Player> players = World.getWorld().getPlayerRepository();
CharacterRepository<Npc> npcs = World.getWorld().getNpcRepository();
MobRepository<Player> players = World.getWorld().getPlayerRepository();
MobRepository<Npc> npcs = World.getWorld().getNpcRepository();
for (Player player : players) {
SynchronizationTask task = new PrePlayerSynchronizationTask(player);
@@ -10,7 +10,7 @@ import org.apollo.game.model.Animation;
public final class AnimationBlock extends SynchronizationBlock {
/**
* The animation.
* The {@link Animation}.
*/
private final Animation animation;
@@ -24,7 +24,7 @@ public final class AnimationBlock extends SynchronizationBlock {
}
/**
* Gets the animation.
* Gets the {@link Animation}.
*
* @return The animation.
*/
@@ -53,11 +53,12 @@ public final class AppearanceBlock extends SynchronizationBlock {
/**
* Creates the appearance block.
*
* @param name The player's name.
* @param name The player's username.
* @param appearance The 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 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) {
@@ -11,12 +11,12 @@ import org.apollo.game.model.Player.PrivilegeLevel;
public final class ChatBlock extends SynchronizationBlock {
/**
* The chat event.
* The {@link ChatEvent}.
*/
private final ChatEvent chatEvent;
/**
* The privilege level.
* The {@link PrivilegeLevel}.
*/
private final PrivilegeLevel privilegeLevel;
@@ -2,8 +2,8 @@ package org.apollo.game.sync.block;
/**
* The Force Chat {@link SynchronizationBlock}. This is a block that can be implemented in both player and npc
* synchronization tasks, and will cause the character to shout the specified text. It is not possible to add colour or
* effect (e.g. wave or scroll) to this block.
* synchronization tasks, and will cause the mob to shout the specified text. It is not possible to add colour or effect
* (e.g. wave or scroll) to this block.
*
* @author Major
*/
@@ -17,7 +17,7 @@ public class ForceChatBlock extends SynchronizationBlock {
/**
* Creates a new force chat [@link SynchronizationBlock}.
*
* @param message The message the character will say.
* @param message The message the mob will say.
*/
public ForceChatBlock(String message) {
this.message = message;
@@ -48,8 +48,8 @@ public class ForceMovementBlock extends SynchronizationBlock {
* @param travelDurationY The length of time (in game pulses) the player's movement along the Y axis will last.
* @param direction The direction the player should move.
*/
public ForceMovementBlock(Position initialPosition, Position finalPosition, int travelDurationX,
int travelDurationY, Direction direction) {
ForceMovementBlock(Position initialPosition, Position finalPosition, int travelDurationX, int travelDurationY,
Direction direction) {
this.initialPosition = initialPosition;
this.finalPosition = finalPosition;
this.travelDurationX = travelDurationX;
@@ -1,15 +1,14 @@
package org.apollo.game.sync.block;
/**
* The Hit Update {@link SynchronizationBlock}. This is a simple implementation designed so that you can integrate it
* easily with your combat system. Both npcs and players can implement this block.
* The hit update {@link SynchronizationBlock}. Both npcs and players can implement this block.
*
* @author Major
*/
public class HitUpdateBlock extends SynchronizationBlock {
/**
* The {@link org.apollo.game.model.Mob}'s current health.
* The mob's current health.
*/
private final int currentHealth;
@@ -19,7 +18,7 @@ public class HitUpdateBlock extends SynchronizationBlock {
private final int damage;
/**
* The {@link org.apollo.game.model.Mob}'s maximum health.
* The mob's maximum health.
*/
private final int maximumHealth;
@@ -31,20 +30,20 @@ public class HitUpdateBlock extends SynchronizationBlock {
/**
* Creates a new Hit Update block.
*
* @param hitDamage The damage dealt by the hit.
* @param hitType The type of hit.
* @param currentHealth The current health of the {@link org.apollo.game.model.Mob}.
* @param maximumHealth The maximum health of the {@link org.apollo.game.model.Mob}.
* @param damage The damage dealt by the hit.
* @param type The type of hit.
* @param currentHealth The current health of the mob.
* @param maximumHealth The maximum health of the mob.
*/
public HitUpdateBlock(int hitDamage, int hitType, int currentHealth, int maximumHealth) {
damage = hitDamage;
type = hitType;
HitUpdateBlock(int damage, int type, int currentHealth, int maximumHealth) {
this.damage = damage;
this.type = type;
this.currentHealth = currentHealth;
this.maximumHealth = maximumHealth;
}
/**
* Gets the current health of the {@link org.apollo.game.model.Mob}.
* Gets the current health of the mob.
*
* @return The current health;
*/
@@ -62,7 +61,7 @@ public class HitUpdateBlock extends SynchronizationBlock {
}
/**
* Gets the maximum health of the {@link org.apollo.game.model.Mob}.
* Gets the maximum health of the mob.
*
* @return The maximum health.
*/
@@ -1,36 +0,0 @@
package org.apollo.game.sync.block;
/**
* The InteractingCharacterBlock {@link SynchronizationBlock}.
*
* @note As all Apollo events should be immutable to avoid concurency issues, this uses the index of the character
* rather than the actual character. This should not be changed.
*
* @author Major
*/
public class InteractingCharacterBlock extends SynchronizationBlock {
/**
* The index of the character.
*/
private final int characterIndex;
/**
* Creates the interacting character block.
*
* @param characterIndex The index of the current interacting character.
*/
public InteractingCharacterBlock(int characterIndex) {
this.characterIndex = characterIndex;
}
/**
* Gets the interacting character's current index.
*
* @return The index of the character.
*/
public int getInteractingCharacterIndex() {
return characterIndex;
}
}
@@ -0,0 +1,36 @@
package org.apollo.game.sync.block;
/**
* The interacting mob {@link SynchronizationBlock}.
* <p>
* Note: As all Apollo events should be immutable to avoid concurrency issues, this uses the index of the mob rather
* than the actual mob. This should not be changed.
*
* @author Major
*/
public class InteractingMobBlock extends SynchronizationBlock {
/**
* The index of the mob.
*/
private final int mobIndex;
/**
* Creates the interacting mob block.
*
* @param mobIndex The index of the current interacting mob.
*/
public InteractingMobBlock(int mobIndex) {
this.mobIndex = mobIndex;
}
/**
* Gets the interacting mob's index.
*
* @return The index.
*/
public int getInteractingMobIndex() {
return mobIndex;
}
}
@@ -1,16 +1,16 @@
package org.apollo.game.sync.block;
/**
* The Second Hit Update {@link SynchronizationBlock}. This is believed to be used for when multiple attacks happen at
* once (for example, the dragon-dagger special attack). This block can be implemented by both players and npcs.
* The secondary hit update {@link SynchronizationBlock}. This is used for when multiple attacks happen at once (for
* example, the dragon-dagger special attack). This block can be implemented by both players and npcs.
*
*
* @author Major
*/
public class SecondHitUpdateBlock extends SynchronizationBlock {
public class SecondaryHitUpdateBlock extends SynchronizationBlock {
/**
* The character's current health.
* The mob's current health.
*/
private final int currentHealth;
@@ -20,7 +20,7 @@ public class SecondHitUpdateBlock extends SynchronizationBlock {
private final int damage;
/**
* The character's maximum health.
* The mob's maximum health.
*/
private final int maximumHealth;
@@ -30,22 +30,22 @@ public class SecondHitUpdateBlock extends SynchronizationBlock {
private final int type;
/**
* Creates a new Second Hit Update block.
* Creates a new secondary hit update block.
*
* @param hitDamage The damage dealt by the hit.
* @param hitType The type of hit.
* @param currentHealth The current health of the character.
* @param maximumHealth The maximum health of the character.
* @param damage The damage dealt by the hit.
* @param type The type of hit.
* @param currentHealth The current health of the mob.
* @param maximumHealth The maximum health of the mob.
*/
public SecondHitUpdateBlock(int hitDamage, int hitType, int currentHealth, int maximumHealth) {
damage = hitDamage;
type = hitType;
SecondaryHitUpdateBlock(int damage, int type, int currentHealth, int maximumHealth) {
this.damage = damage;
this.type = type;
this.currentHealth = currentHealth;
this.maximumHealth = maximumHealth;
}
/**
* Gets the current health of the character.
* Gets the current health of the mob.
*
* @return The current health;
*/
@@ -63,7 +63,7 @@ public class SecondHitUpdateBlock extends SynchronizationBlock {
}
/**
* Gets the maximum health of the character.
* Gets the maximum health of the mob.
*
* @return The maximum health.
*/
@@ -63,11 +63,11 @@ public abstract class SynchronizationBlock {
/**
* Creates a new force movement block with the specified parameters.
*
* @param initialPosition The initial position of the player.
* @param finalPosition The final position of the player.
* @param travelDurationX The duration motion along the X axis will occur.
* @param travelDurationY The duration motion along the Y axis will occur.
* @param direction The direction the player will face.
* @param initialPosition The initial {@link Position} of the player.
* @param finalPosition The final {@link Position} of the player
* @param travelDurationX The length of time (in game pulses) the player's movement along the X axis will last.
* @param travelDurationY The length of time (in game pulses) the player's movement along the Y axis will last.
* @param direction The direction the player should move.
* @return The force movement block.
*/
public static SynchronizationBlock createForceMovementBlock(Position initialPosition, Position finalPosition,
@@ -86,13 +86,39 @@ public abstract class SynchronizationBlock {
}
/**
* Creates an interacting character block with the specified character index.
* Creates a new hit or secondary hit update block
*
* @param index The index of the interacting character.
* @return The interacting character block.
* @param damage The damage dealt by the hit.
* @param type The type of hit.
* @param currentHealth The current health of the mob.
* @param maximumHealth The maximum health of the mob.
* @param secondary If the block is a secondary hit or not.
* @return The hit update block.
*/
public static SynchronizationBlock createInteractingCharacterBlock(int index) {
return new InteractingCharacterBlock(index);
public static SynchronizationBlock createHitUpdateBlock(int damage, int type, int currentHealth, int maximumHealth,
boolean secondary) {
return secondary ? new SecondaryHitUpdateBlock(damage, type, currentHealth, maximumHealth)
: new HitUpdateBlock(damage, type, currentHealth, maximumHealth);
}
/**
* Creates an interacting mob block with the specified index.
*
* @param index The index of the mob being interacted with.
* @return The interacting mob block.
*/
public static SynchronizationBlock createInteractingMobBlock(int index) {
return new InteractingMobBlock(index);
}
/**
* Creates a transform block with the specified id.
*
* @param id The id.
* @return The transform block.
*/
public static SynchronizationBlock createTransformBlock(int id) {
return new TransformBlock(id);
}
/**
@@ -11,9 +11,9 @@ import java.util.Map;
public final class SynchronizationBlockSet implements Cloneable {
/**
* The blocks.
* A {@link Map} of {@link SynchronizationBlock}s.
*/
private final Map<Class<? extends SynchronizationBlock>, SynchronizationBlock> blocks = new HashMap<Class<? extends SynchronizationBlock>, SynchronizationBlock>();
private final Map<Class<? extends SynchronizationBlock>, SynchronizationBlock> blocks = new HashMap<>();
/**
* Adds a {@link SynchronizationBlock}.
@@ -18,7 +18,7 @@ public final class TransformBlock extends SynchronizationBlock {
*
* @param id The id.
*/
public TransformBlock(int id) {
TransformBlock(int id) {
this.id = id;
}
@@ -2,4 +2,3 @@
* Contains classes related to synchronization 'blocks'.
*/
package org.apollo.game.sync.block;
@@ -3,4 +3,3 @@
* client's state is updated by the server so it matches the server's state.
*/
package org.apollo.game.sync;
@@ -29,7 +29,7 @@ public final class AddNpcSegment extends SynchronizationSegment {
* Creates the add npc segment.
*
* @param blockSet The block set.
* @param index The characters's index.
* @param index The npcs's index.
* @param position The position.
* @param npcId The id of the npc.
*/
@@ -41,7 +41,7 @@ public final class AddNpcSegment extends SynchronizationSegment {
}
/**
* Gets the character's index.
* Gets the npc's index.
*
* @return The index.
*/
@@ -69,7 +69,7 @@ public final class AddNpcSegment extends SynchronizationSegment {
@Override
public SegmentType getType() {
return SegmentType.ADD_CHARACTER;
return SegmentType.ADD_MOB;
}
}
@@ -4,7 +4,7 @@ import org.apollo.game.model.Position;
import org.apollo.game.sync.block.SynchronizationBlockSet;
/**
* A {@link SynchronizationSegment} which adds a character.
* A {@link SynchronizationSegment} which adds a player.
*
* @author Graham
*/
@@ -21,10 +21,10 @@ public final class AddPlayerSegment extends SynchronizationSegment {
private final Position position;
/**
* Creates the add character segment.
* Creates the add player segment.
*
* @param blockSet The block set.
* @param index The characters's index.
* @param index The player's index.
* @param position The position.
*/
public AddPlayerSegment(SynchronizationBlockSet blockSet, int index, Position position) {
@@ -34,7 +34,7 @@ public final class AddPlayerSegment extends SynchronizationSegment {
}
/**
* Gets the character's index.
* Gets the player's index.
*
* @return The index.
*/
@@ -53,7 +53,7 @@ public final class AddPlayerSegment extends SynchronizationSegment {
@Override
public SegmentType getType() {
return SegmentType.ADD_CHARACTER;
return SegmentType.ADD_MOB;
}
}
@@ -4,7 +4,7 @@ import org.apollo.game.model.Direction;
import org.apollo.game.sync.block.SynchronizationBlockSet;
/**
* A {@link SynchronizationSegment} where the character is moved (or doesn't move!).
* A {@link SynchronizationSegment} where the mob is moved (or doesn't move!).
*
* @author Graham
*/
@@ -3,11 +3,11 @@ package org.apollo.game.sync.seg;
import org.apollo.game.sync.block.SynchronizationBlockSet;
/**
* A {@link SynchronizationSegment} which removes a character.
* A {@link SynchronizationSegment} which removes a mob.
*
* @author Graham
*/
public final class RemoveCharacterSegment extends SynchronizationSegment {
public final class RemoveMobSegment extends SynchronizationSegment {
/**
* An empty {@link SynchronizationBlockSet}.
@@ -15,15 +15,15 @@ public final class RemoveCharacterSegment extends SynchronizationSegment {
private static final SynchronizationBlockSet EMPTY_BLOCK_SET = new SynchronizationBlockSet();
/**
* Creates the remove character segment.
* Creates the remove mob segment.
*/
public RemoveCharacterSegment() {
public RemoveMobSegment() {
super(EMPTY_BLOCK_SET);
}
@Override
public SegmentType getType() {
return SegmentType.REMOVE_CHARACTER;
return SegmentType.REMOVE_MOB;
}
}
@@ -8,9 +8,9 @@ package org.apollo.game.sync.seg;
public enum SegmentType {
/**
* A segment where the character is added.
* A segment where the mob is added.
*/
ADD_CHARACTER,
ADD_MOB,
/**
* A segment without any movement.
@@ -18,9 +18,9 @@ public enum SegmentType {
NO_MOVEMENT,
/**
* A segment where the character is removed.
* A segment where the mob is removed.
*/
REMOVE_CHARACTER,
REMOVE_MOB,
/**
* A segment with movement in two directions.
@@ -28,7 +28,7 @@ public enum SegmentType {
RUN,
/**
* A segment where the character is teleported.
* A segment where the mob is teleported.
*/
TELEPORT,
@@ -4,7 +4,7 @@ import org.apollo.game.model.Position;
import org.apollo.game.sync.block.SynchronizationBlockSet;
/**
* A {@link SynchronizationSegment} where the character is teleported to a new location.
* A {@link SynchronizationSegment} where the mob is teleported to a new location.
*
* @author Graham
*/
@@ -1,7 +1,6 @@
/**
* Contains classes related to synchronization segments. Each segment contains
* multiple blocks and can be used to add, remove, teleport or move a
* character.
* mob.
*/
package org.apollo.game.sync.seg;
@@ -11,9 +11,9 @@ 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.RemoveCharacterSegment;
import org.apollo.game.sync.seg.RemoveMobSegment;
import org.apollo.game.sync.seg.SynchronizationSegment;
import org.apollo.util.CharacterRepository;
import org.apollo.util.MobRepository;
/**
* A {@link SynchronizationTask} which synchronizes npcs with the specified {@link Player}.
@@ -46,15 +46,14 @@ public final class NpcSynchronizationTask extends SynchronizationTask {
public void run() {
SynchronizationBlockSet blockSet = player.getBlockSet();
List<Npc> localNpcs = player.getLocalNpcList();
int oldLocalNpcs = localNpcs.size();
List<SynchronizationSegment> segments = new ArrayList<SynchronizationSegment>();
Iterator<Npc> it = localNpcs.iterator();
for (Iterator<Npc> it = localNpcs.iterator(); it.hasNext();) {
Npc npc = it.next();
for (Npc npc = null; it.hasNext(); npc = it.next()) {
if (!npc.isActive() || npc.isTeleporting()
|| npc.getPosition().getLongestDelta(player.getPosition()) > player.getViewingDistance()) {
it.remove();
segments.add(new RemoveCharacterSegment());
segments.add(new RemoveMobSegment());
} else {
segments.add(new MovementSegment(npc.getBlockSet(), npc.getDirections()));
}
@@ -62,26 +61,24 @@ public final class NpcSynchronizationTask extends SynchronizationTask {
int added = 0;
CharacterRepository<Npc> repository = World.getWorld().getNpcRepository();
MobRepository<Npc> repository = World.getWorld().getNpcRepository();
for (Npc npc : repository) {
if (localNpcs.size() >= 255) {
player.flagExcessiveNpcs();
break;
} else if (added >= NEW_NPCS_PER_CYCLE) {
break;
}
if (npc.getPosition().isWithinDistance(player.getPosition(), player.getViewingDistance())
&& !localNpcs.contains(npc)) {
localNpcs.add(npc);
added++;
blockSet = npc.getBlockSet();
segments.add(new AddNpcSegment(blockSet, npc.getIndex(), npc.getPosition(), npc.getNpcDefinition()
.getId()));
} else if (added < NEW_NPCS_PER_CYCLE) {
if (!localNpcs.contains(npc)
&& npc.getPosition().isWithinDistance(player.getPosition(), player.getViewingDistance())) {
localNpcs.add(npc);
added++;
blockSet = npc.getBlockSet();
segments.add(new AddNpcSegment(blockSet, npc.getIndex(), npc.getPosition(), npc.getId()));
}
continue;
}
break;
}
NpcSynchronizationEvent event = new NpcSynchronizationEvent(player.getPosition(), segments, oldLocalNpcs);
NpcSynchronizationEvent event = new NpcSynchronizationEvent(player.getPosition(), segments, localNpcs.size());
player.send(event);
}
@@ -14,10 +14,10 @@ import org.apollo.game.sync.block.SynchronizationBlock;
import org.apollo.game.sync.block.SynchronizationBlockSet;
import org.apollo.game.sync.seg.AddPlayerSegment;
import org.apollo.game.sync.seg.MovementSegment;
import org.apollo.game.sync.seg.RemoveCharacterSegment;
import org.apollo.game.sync.seg.RemoveMobSegment;
import org.apollo.game.sync.seg.SynchronizationSegment;
import org.apollo.game.sync.seg.TeleportSegment;
import org.apollo.util.CharacterRepository;
import org.apollo.util.MobRepository;
/**
* A {@link SynchronizationTask} which synchronizes the specified {@link Player} .
@@ -67,44 +67,45 @@ public final class PlayerSynchronizationTask extends SynchronizationTask {
List<Player> localPlayers = player.getLocalPlayerList();
int oldLocalPlayers = localPlayers.size();
List<SynchronizationSegment> segments = new ArrayList<SynchronizationSegment>();
Iterator<Player> it = localPlayers.iterator();
for (Iterator<Player> it = localPlayers.iterator(); it.hasNext();) {
Player p = it.next();
if (!p.isActive() || p.isTeleporting()
|| p.getPosition().getLongestDelta(player.getPosition()) > player.getViewingDistance()) {
for (Player local = null; it.hasNext(); local = it.next()) {
if (!local.isActive() || local.isTeleporting()
|| local.getPosition().getLongestDelta(player.getPosition()) > player.getViewingDistance()) {
it.remove();
segments.add(new RemoveCharacterSegment());
segments.add(new RemoveMobSegment());
} else {
segments.add(new MovementSegment(p.getBlockSet(), p.getDirections()));
segments.add(new MovementSegment(local.getBlockSet(), local.getDirections()));
}
}
int added = 0;
CharacterRepository<Player> repository = World.getWorld().getPlayerRepository();
for (Player p : repository) {
MobRepository<Player> repository = World.getWorld().getPlayerRepository();
for (Player global : repository) {
if (localPlayers.size() >= 255) {
player.flagExcessivePlayers();
break;
} else if (added >= NEW_PLAYERS_PER_CYCLE) {
break;
}
// we do not check p.isActive() here, since if they are active they
// must be in the repository
if (p != player && p.getPosition().isWithinDistance(player.getPosition(), player.getViewingDistance())
&& !localPlayers.contains(p)) {
localPlayers.add(p);
added++;
} else if (added < NEW_PLAYERS_PER_CYCLE) {
// we do not check p.isActive() here, since if they are active they
// must be in the repository
if (global != player
&& global.getPosition().isWithinDistance(player.getPosition(), player.getViewingDistance())
&& !localPlayers.contains(global)) {
localPlayers.add(global);
added++;
blockSet = p.getBlockSet();
if (!blockSet.contains(AppearanceBlock.class)) {
// TODO check if client has cached appearance
blockSet = blockSet.clone();
blockSet.add(SynchronizationBlock.createAppearanceBlock(p));
blockSet = global.getBlockSet();
if (!blockSet.contains(AppearanceBlock.class)) {
// TODO check if client has cached appearance
blockSet = blockSet.clone();
blockSet.add(SynchronizationBlock.createAppearanceBlock(global));
}
segments.add(new AddPlayerSegment(blockSet, global.getIndex(), global.getPosition()));
}
segments.add(new AddPlayerSegment(blockSet, p.getIndex(), p.getPosition()));
continue;
}
break;
}
PlayerSynchronizationEvent event = new PlayerSynchronizationEvent(lastKnownRegion, player.getPosition(),
@@ -38,7 +38,7 @@ public final class EquipmentDefinitionParser {
DataInputStream dis = new DataInputStream(is);
int count = dis.readShort() & 0xFFFF;
EquipmentDefinition[] defs = new EquipmentDefinition[count];
EquipmentDefinition[] definitions = new EquipmentDefinition[count];
for (int id = 0; id < count; id++) {
int slot = dis.readByte() & 0xFF;
@@ -53,16 +53,16 @@ public final class EquipmentDefinitionParser {
int ranged = dis.readByte() & 0xFF;
int magic = dis.readByte() & 0xFF;
EquipmentDefinition def = new EquipmentDefinition(id);
def.setLevels(attack, strength, defence, ranged, magic);
def.setSlot(slot);
def.setFlags(twoHanded, fullBody, fullHat, fullMask);
EquipmentDefinition definition = new EquipmentDefinition(id);
definition.setLevels(attack, strength, defence, ranged, magic);
definition.setSlot(slot);
definition.setFlags(twoHanded, fullBody, fullHat, fullMask);
defs[id] = def;
definitions[id] = definition;
}
}
return defs;
return definitions;
}
}
-1
View File
@@ -2,4 +2,3 @@
* Contains classes which deal with input/output.
*/
package org.apollo.io;
@@ -59,7 +59,7 @@ public final class BinaryPlayerLoader implements PlayerLoader {
int height = in.readUnsignedByte();
// read appearance
boolean designedCharacter = in.readBoolean();
boolean designed = in.readBoolean();
int genderIntValue = in.readUnsignedByte();
Gender gender = genderIntValue == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE;
@@ -72,20 +72,20 @@ public final class BinaryPlayerLoader implements PlayerLoader {
colors[i] = in.readUnsignedByte();
}
Player p = new Player(credentials, new Position(x, y, height));
p.setPrivilegeLevel(privilegeLevel);
p.setMembers(members);
p.setDesignedCharacter(designedCharacter);
p.setAppearance(new Appearance(gender, style, colors));
Player player = new Player(credentials, new Position(x, y, height));
player.setPrivilegeLevel(privilegeLevel);
player.setMembers(members);
player.setDesigned(designed);
player.setAppearance(new Appearance(gender, style, colors));
// read inventories
readInventory(in, p.getInventory());
readInventory(in, p.getEquipment());
readInventory(in, p.getBank());
readInventory(in, player.getInventory());
readInventory(in, player.getEquipment());
readInventory(in, player.getBank());
// read skills
int size = in.readUnsignedByte();
SkillSet skills = p.getSkillSet();
SkillSet skills = player.getSkillSet();
skills.stopFiringEvents();
try {
for (int i = 0; i < size; i++) {
@@ -94,10 +94,11 @@ public final class BinaryPlayerLoader implements PlayerLoader {
skills.setSkill(i, new Skill(experience, level, SkillSet.getLevelForExperience(experience)));
}
} finally {
skills.calculateCombatLevel();
skills.startFiringEvents();
}
return new PlayerLoaderResponse(LoginConstants.STATUS_OK, p);
return new PlayerLoaderResponse(LoginConstants.STATUS_OK, player);
} finally {
in.close();
}
@@ -40,7 +40,7 @@ public final class BinaryPlayerSaver implements PlayerSaver {
out.writeByte(position.getHeight());
// write appearance
out.writeBoolean(player.hasDesignedCharacter());
out.writeBoolean(player.hasDesignedAvatar());
Appearance appearance = player.getAppearance();
out.writeByte(appearance.getGender().toInteger());
int[] style = appearance.getStyle();
@@ -26,21 +26,20 @@ public final class BinaryPlayerUtil {
}
/**
* Gets the file for the specified player.
* Gets the save {@link File} for the specified player.
*
* @param name The name of the player.
* @param username The username of the player.
* @return The file.
*/
public static File getFile(String name) {
name = NameUtil.decodeBase37(NameUtil.encodeBase37(name));
return new File(SAVED_GAMES_DIRECTORY, name + ".dat");
public static File getFile(String username) {
username = NameUtil.decodeBase37(NameUtil.encodeBase37(username));
return new File(SAVED_GAMES_DIRECTORY, username + ".dat");
}
/**
* Default private constructor to prevent instantiation.
*/
private BinaryPlayerUtil() {
}
}
@@ -2,4 +2,3 @@
* Contains various player loader/saver implementations.
*/
package org.apollo.io.player.impl;
@@ -2,4 +2,3 @@
* Contains classes which deal with loading and saving player files.
*/
package org.apollo.io.player;
-1
View File
@@ -2,4 +2,3 @@
* Contains classes related to the login service.
*/
package org.apollo.login;
@@ -2,4 +2,3 @@
* Contains codecs for the game protocol.
*/
package org.apollo.net.codec.game;
@@ -2,4 +2,3 @@
* Contains codecs for the handshake protocol.
*/
package org.apollo.net.codec.handshake;
@@ -3,7 +3,7 @@ package org.apollo.net.codec.jaggrab;
import org.jboss.netty.buffer.ChannelBuffer;
/**
* Represents a single JAGGRAB reponse.
* Represents a single JAGGRAB response.
*
* @author Graham
*/
@@ -2,4 +2,3 @@
* Contains codecs for the JAGGRAB protocol.
*/
package org.apollo.net.codec.jaggrab;
@@ -2,4 +2,3 @@
* Contains codecs for the login protocol.
*/
package org.apollo.net.codec.login;
@@ -107,9 +107,8 @@ public final class OnDemandRequest implements Comparable<OnDemandRequest> {
return 1;
} else if (thisPriority == otherPriority) {
return 0;
} else {
return -1;
}
return -1;
}
/**
@@ -17,21 +17,21 @@ public final class UpdateEncoder extends OneToOneEncoder {
@Override
protected Object encode(ChannelHandlerContext ctx, Channel c, Object msg) {
if (msg instanceof OnDemandResponse) {
OnDemandResponse resp = (OnDemandResponse) msg;
OnDemandResponse response = (OnDemandResponse) msg;
FileDescriptor fileDescriptor = resp.getFileDescriptor();
int fileSize = resp.getFileSize();
int chunkId = resp.getChunkId();
ChannelBuffer chunkData = resp.getChunkData();
FileDescriptor descriptor = response.getFileDescriptor();
int fileSize = response.getFileSize();
int chunkId = response.getChunkId();
ChannelBuffer chunkData = response.getChunkData();
ChannelBuffer buf = ChannelBuffers.buffer(6 + chunkData.readableBytes());
buf.writeByte(fileDescriptor.getType() - 1);
buf.writeShort(fileDescriptor.getFile());
buf.writeShort(fileSize);
buf.writeByte(chunkId);
buf.writeBytes(chunkData);
ChannelBuffer buffer = ChannelBuffers.buffer(6 + chunkData.readableBytes());
buffer.writeByte(descriptor.getType() - 1);
buffer.writeShort(descriptor.getFile());
buffer.writeShort(fileSize);
buffer.writeByte(chunkId);
buffer.writeBytes(chunkData);
return buf;
return buffer;
}
return msg;
}
@@ -2,4 +2,3 @@
* Contains codecs for the ondemand (update) protocol.
*/
package org.apollo.net.codec.update;
@@ -2,4 +2,3 @@
* Contains classes which contain meta data about the protocol/various packets.
*/
package org.apollo.net.meta;
-1
View File
@@ -3,4 +3,3 @@
* classes - such as the pipeline factory, handler and codecs.
*/
package org.apollo.net;
@@ -3,4 +3,3 @@
* allowing for portability between various protocol and client releases.
*/
package org.apollo.net.release;
@@ -1,20 +0,0 @@
package org.apollo.net.release.r317;
import org.apollo.game.event.impl.CharacterAnimationResetEvent;
import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketBuilder;
import org.apollo.net.release.EventEncoder;
/**
* An {@link EventEncoder} for the {@link CharacterAnimationResetEvent}.
*
* @author Major
*/
public class CharacterAnimationResetEventEncoder extends EventEncoder<CharacterAnimationResetEvent> {
@Override
public GamePacket encode(CharacterAnimationResetEvent event) {
return new GamePacketBuilder(1).toGamePacket();
}
}

Some files were not shown because too many files have changed in this diff Show More