Cleanup and improve comments.

This commit is contained in:
Major-
2014-03-09 20:46:02 +00:00
parent 2b08bb6678
commit 41f224d8e2
33 changed files with 189 additions and 213 deletions
+2 -3
View File
@@ -248,9 +248,8 @@ POISON_IVY_BERRIES = Ingredient.new(6018)
YEW_ROOTS = Ingredient.new(6049) YEW_ROOTS = Ingredient.new(6049)
MAGIC_ROOTS = Ingredient.new(6051) MAGIC_ROOTS = Ingredient.new(6051)
# Grinded ingredients # Ground ingredients
UNICORN_HORN_DUST = append_ground(235, 237) UNICORN_HORN_DUST = append_ground(235, 237)
DRAGON_SCALE_DUST = append_ground(241, 243) DRAGON_SCALE_DUST = append_ground(241, 243)
CHOCOLATE_DUST = append_ground(1975, 1973) CHOCOLATE_DUST = append_ground(1975, 1973)
CRUSHED_NEST = append_ground(6693, 5075) # CRUSHED_NEST = append_ground(6693, 5075)
GROUND_MUD_RUNE = append_ground(9594, 4698)
+1 -1
View File
@@ -83,4 +83,4 @@ def append_convert(button, level, elements, experience, reward)
end end
append_convert 1159, 15, { EARTH => 2, WATER => 2, NATURE => 1 }, 25, 1963 # Bones to bananas append_convert 1159, 15, { EARTH => 2, WATER => 2, NATURE => 1 }, 25, 1963 # Bones to bananas
append_convert 15877, 60, { NATURE => 2, WATER => 4, EARTH => 4 }, 35.5, 6883 # Bones to peaches #append_convert 15877, 60, { NATURE => 2, WATER => 4, EARTH => 4 }, 35.5, 6883 # Bones to peaches
@@ -49,7 +49,7 @@ public final class BankEventHandler extends EventHandler<ItemActionEvent> {
private void deposit(EventHandlerContext ctx, Player player, ItemActionEvent event) { private void deposit(EventHandlerContext ctx, Player player, ItemActionEvent event) {
int amount = optionToAmount(event.getOption()); int amount = optionToAmount(event.getOption());
if (amount == -1) { if (amount == -1) {
player.getInterfaceSet().openEnterAmountDialog( player.getInterfaceSet().openEnterAmountDialogue(
new BankDepositEnterAmountListener(player, event.getSlot(), event.getId())); new BankDepositEnterAmountListener(player, event.getSlot(), event.getId()));
} else if (!BankUtils.deposit(player, event.getSlot(), event.getId(), amount)) { } else if (!BankUtils.deposit(player, event.getSlot(), event.getId(), amount)) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
@@ -58,14 +58,12 @@ public final class BankEventHandler extends EventHandler<ItemActionEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) { public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
if (!player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) {
return; if (event.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) {
} deposit(ctx, player, event);
} else if (event.getInterfaceId() == BankConstants.BANK_INVENTORY_ID) {
if (event.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) { withdraw(ctx, player, event);
deposit(ctx, player, event); }
} else if (event.getInterfaceId() == BankConstants.BANK_INVENTORY_ID) {
withdraw(ctx, player, event);
} }
} }
@@ -79,7 +77,7 @@ public final class BankEventHandler extends EventHandler<ItemActionEvent> {
private void withdraw(EventHandlerContext ctx, Player player, ItemActionEvent event) { private void withdraw(EventHandlerContext ctx, Player player, ItemActionEvent event) {
int amount = optionToAmount(event.getOption()); int amount = optionToAmount(event.getOption());
if (amount == -1) { if (amount == -1) {
player.getInterfaceSet().openEnterAmountDialog( player.getInterfaceSet().openEnterAmountDialogue(
new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId())); new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId()));
} else if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) { } else if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
@@ -16,15 +16,13 @@ public final class CommandEventHandler extends EventHandler<CommandEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, CommandEvent event) { public void handle(EventHandlerContext ctx, Player player, CommandEvent event) {
String str = event.getCommand(); String[] components = event.getCommand().split(" ");
String[] components = str.split(" ");
String name = components[0]; String name = components[0];
String[] arguments = new String[components.length - 1]; String[] arguments = new String[components.length - 1];
System.arraycopy(components, 1, arguments, 0, arguments.length); System.arraycopy(components, 1, arguments, 0, arguments.length);
Command command = new Command(name, arguments);
Command command = new Command(name, arguments);
World.getWorld().getCommandDispatcher().dispatch(player, command); World.getWorld().getCommandDispatcher().dispatch(player, command);
} }
@@ -16,7 +16,7 @@ public final class PlayerDesignEventHandler extends EventHandler<PlayerDesignEve
@Override @Override
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) { public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
player.setAppearance(event.getAppearance()); player.setAppearance(event.getAppearance());
player.setDesigned(true); player.setNew(true);
player.send(new CloseInterfaceEvent()); player.send(new CloseInterfaceEvent());
} }
@@ -16,7 +16,7 @@ public final class PlayerDesignVerificationHandler extends EventHandler<PlayerDe
@Override @Override
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) { public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
if (!valid(event.getAppearance()) || player.hasDesignedAvatar()) { if (!valid(event.getAppearance()) || player.isNewPlayer()) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
} }
} }
@@ -6,7 +6,6 @@ import org.apollo.game.event.impl.ItemActionEvent;
import org.apollo.game.model.Inventory; import org.apollo.game.model.Inventory;
import org.apollo.game.model.Item; import org.apollo.game.model.Item;
import org.apollo.game.model.Player; import org.apollo.game.model.Player;
import org.apollo.game.model.def.ItemDefinition;
import org.apollo.game.model.inv.SynchronizationInventoryListener; import org.apollo.game.model.inv.SynchronizationInventoryListener;
/** /**
@@ -27,7 +26,7 @@ public final class RemoveEventHandler extends EventHandler<ItemActionEvent> {
Item item = equipment.get(slot); Item item = equipment.get(slot);
int id = item.getId(); int id = item.getId();
if (inventory.freeSlots() == 0 && !ItemDefinition.lookup(id).isStackable()) { if (inventory.freeSlots() == 0 && !item.getDefinition().isStackable()) {
inventory.forceCapacityExceeded(); inventory.forceCapacityExceeded();
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
@@ -39,7 +39,7 @@ public final class SwitchItemEventHandler extends EventHandler<SwitchItemEvent>
if (event.getOldSlot() >= 0 && event.getNewSlot() >= 0 && event.getOldSlot() < inventory.capacity() if (event.getOldSlot() >= 0 && event.getNewSlot() >= 0 && event.getOldSlot() < inventory.capacity()
&& event.getNewSlot() < inventory.capacity()) { && event.getNewSlot() < inventory.capacity()) {
// events must be fired for it to work if a sidebar inv overlay is used // events must be fired for it to work if a sidebar inventory overlay is used
inventory.swap(insertPermitted ? event.isInserting() : false, event.getOldSlot(), event.getNewSlot()); inventory.swap(insertPermitted ? event.isInserting() : false, event.getOldSlot(), event.getNewSlot());
} }
} }
@@ -12,17 +12,17 @@ import org.apollo.game.event.Event;
public abstract class NpcActionEvent extends Event { public abstract class NpcActionEvent extends Event {
/** /**
* The option number . * The option number.
*/ */
private final int option; private final int option;
/** /**
* The npc index. * The index of the clicked npc.
*/ */
private final int index; private final int index;
/** /**
* Creates a new npc action event. * Creates an npc action event.
* *
* @param option The option number. * @param option The option number.
* @param index The index of the npc. * @param index The index of the npc.
+1 -1
View File
@@ -1,4 +1,4 @@
/** /**
* Contains login listeners. * Contains login and logout listeners.
*/ */
package org.apollo.game.login; package org.apollo.game.login;
+2 -4
View File
@@ -40,11 +40,9 @@ public final class Appearance {
public Appearance(Gender gender, int[] style, int[] colors) { public Appearance(Gender gender, int[] style, int[] colors) {
if (gender == null || style == null || colors == null) { if (gender == null || style == null || colors == null) {
throw new NullPointerException("No arguments can be null."); throw new NullPointerException("No arguments can be null.");
} } else if (style.length != 7) {
if (style.length != 7) {
throw new IllegalArgumentException("The style array must have 7 elements."); throw new IllegalArgumentException("The style array must have 7 elements.");
} } else if (colors.length != 5) {
if (colors.length != 5) {
throw new IllegalArgumentException("The colors array must have 5 elements."); throw new IllegalArgumentException("The colors array must have 5 elements.");
} }
this.gender = gender; this.gender = gender;
+18 -18
View File
@@ -7,16 +7,16 @@ package org.apollo.game.model;
*/ */
public enum Direction { public enum Direction {
/**
* East movement.
*/
EAST(4),
/** /**
* No movement. * No movement.
*/ */
NONE(-1), NONE(-1),
/**
* North west movement.
*/
NORTH_WEST(0),
/** /**
* North movement. * North movement.
*/ */
@@ -28,9 +28,19 @@ public enum Direction {
NORTH_EAST(2), 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. * South movement.
@@ -40,17 +50,7 @@ public enum Direction {
/** /**
* South east movement. * South east movement.
*/ */
SOUTH_EAST(7), SOUTH_EAST(7);
/**
* South west movement.
*/
SOUTH_WEST(5),
/**
* West movement.
*/
WEST(3);
/** /**
* An empty direction array. * An empty direction array.
+3 -9
View File
@@ -1,13 +1,11 @@
package org.apollo.game.model; package org.apollo.game.model;
import java.io.Serializable;
/** /**
* Represents an in-game entity, such as a mob, object, projectile etc. * Represents an in-game entity, such as a mob, object, projectile etc.
* *
* @author Major * @author Major
*/ */
public abstract class Entity implements Serializable { public abstract class Entity {
/** /**
* Represents a type of {@link Entity}. * Represents a type of {@link Entity}.
@@ -40,12 +38,8 @@ public abstract class Entity implements Serializable {
* A projectile (e.g. an arrow). * A projectile (e.g. an arrow).
*/ */
PROJECTILE; PROJECTILE;
}
/** }
* The generated serial UID.
*/
private static final long serialVersionUID = 5968243763380631014L;
/** /**
* The position of this entity. * The position of this entity.
@@ -64,7 +58,7 @@ public abstract class Entity implements Serializable {
/** /**
* Gets the {@link EntityType} of this entity. * Gets the {@link EntityType} of this entity.
* *
* @return The type. * @return The entity type.
*/ */
public abstract EntityType getEntityType(); public abstract EntityType getEntityType();
@@ -8,59 +8,59 @@ package org.apollo.game.model;
public final class EquipmentConstants { public final class EquipmentConstants {
/** /**
* The amulet slot. * The hat slot.
*/ */
public static final int AMULET = 2; public static final int HAT = 0;
/**
* The arrows slot.
*/
public static final int ARROWS = 13;
/** /**
* The cape slot. * The cape slot.
*/ */
public static final int CAPE = 1; 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. * The chest slot.
*/ */
public static final int CHEST = 4; 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. * The shield slot.
*/ */
public static final int SHIELD = 5; 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; * Default private constructor to prevent instantiation;
+3 -3
View File
@@ -62,7 +62,7 @@ public final class Graphic {
/** /**
* Gets the graphic's delay. * Gets the graphic's delay.
* *
* @return The graphic's delay. * @return The delay.
*/ */
public int getDelay() { public int getDelay() {
return delay; return delay;
@@ -71,7 +71,7 @@ public final class Graphic {
/** /**
* Gets the graphic's height. * Gets the graphic's height.
* *
* @return The graphic's height. * @return The height.
*/ */
public int getHeight() { public int getHeight() {
return height; return height;
@@ -80,7 +80,7 @@ public final class Graphic {
/** /**
* Gets the graphic's id. * Gets the graphic's id.
* *
* @return The graphic's id. * @return The id.
*/ */
public int getId() { public int getId() {
return id; return id;
+17 -22
View File
@@ -89,12 +89,10 @@ public final class Inventory implements Cloneable {
public Inventory(int capacity, StackMode mode) { public Inventory(int capacity, StackMode mode) {
if (capacity < 0) { if (capacity < 0) {
throw new IllegalArgumentException("Capacity cannot be negative."); throw new IllegalArgumentException("Capacity cannot be negative.");
} } else if (mode == null) {
if (mode == null) {
throw new NullPointerException("Stacking mode cannot be null."); throw new NullPointerException("Stacking mode cannot be null.");
} }
this.capacity = capacity; items = new Item[this.capacity = capacity];
items = new Item[capacity];
this.mode = mode; this.mode = mode;
} }
@@ -117,10 +115,7 @@ public final class Inventory implements Cloneable {
*/ */
public int add(int id, int amount) { public int add(int id, int amount) {
Item item = add(new Item(id, amount)); Item item = add(new Item(id, amount));
if (item != null) { return item != null ? item.getAmount() : 0;
return item.getAmount();
}
return 0;
} }
/** /**
@@ -140,8 +135,7 @@ public final class Inventory implements Cloneable {
Item other = items[slot]; Item other = items[slot];
if (other != null && other.getId() == id) { if (other != null && other.getId() == id) {
long total = item.getAmount() + other.getAmount(); long total = item.getAmount() + other.getAmount();
int amount; int amount, remaining;
int remaining;
if (total > Integer.MAX_VALUE) { if (total > Integer.MAX_VALUE) {
amount = (int) (total - Integer.MAX_VALUE); amount = (int) (total - Integer.MAX_VALUE);
remaining = (int) (total - amount); remaining = (int) (total - amount);
@@ -335,18 +329,18 @@ public final class Inventory implements Cloneable {
} }
/** /**
* Checks if the item specified by the definition should be stacked. * Checks if the item with the specified {@link ItemDefinition} should be stacked.
* *
* @param def The definition. * @param definition The item definition.
* @return {@code true} if the item should be stacked, {@code false} otherwise. * @return {@code true} if the item should be stacked, {@code false} otherwise.
*/ */
private boolean isStackable(ItemDefinition def) { private boolean isStackable(ItemDefinition definition) {
if (mode == StackMode.STACK_ALWAYS) { if (mode == StackMode.STACK_ALWAYS) {
return true; return true;
} else if (mode == StackMode.STACK_STACKABLE_ITEMS) { } else if (mode == StackMode.STACK_STACKABLE_ITEMS) {
return def.isStackable(); return definition.isStackable();
} }
return false; // will be STACK_NEVER return false;
} }
/** /**
@@ -378,9 +372,8 @@ public final class Inventory implements Cloneable {
*/ */
private void notifyItemUpdated(int slot) { private void notifyItemUpdated(int slot) {
if (firingEvents) { if (firingEvents) {
Item item = items[slot];
for (InventoryListener listener : listeners) { for (InventoryListener listener : listeners) {
listener.itemUpdated(this, slot, item); listener.itemUpdated(this, slot, items[slot]);
} }
} }
} }
@@ -539,11 +532,12 @@ public final class Inventory implements Cloneable {
public void shift() { public void shift() {
Item[] old = items; Item[] old = items;
items = new Item[capacity]; items = new Item[capacity];
for (int i = 0, pos = 0; i < items.length; i++) { for (int slot = 0, pos = 0; slot < items.length; slot++) {
if (old[i] != null) { if (old[slot] != null) {
items[pos++] = old[i]; items[pos++] = old[slot];
} }
} }
if (firingEvents) { if (firingEvents) {
notifyItemsUpdated(); notifyItemsUpdated();
} }
@@ -602,6 +596,7 @@ public final class Inventory implements Cloneable {
public void swap(boolean insert, int oldSlot, int newSlot) { public void swap(boolean insert, int oldSlot, int newSlot) {
checkBounds(oldSlot); checkBounds(oldSlot);
checkBounds(newSlot); checkBounds(newSlot);
if (insert) { if (insert) {
if (newSlot > oldSlot) { if (newSlot > oldSlot) {
for (int slot = oldSlot; slot < newSlot; slot++) { for (int slot = oldSlot; slot < newSlot; slot++) {
@@ -614,9 +609,9 @@ public final class Inventory implements Cloneable {
} }
forceRefresh(); forceRefresh();
} else { } else {
Item tmp = items[oldSlot]; Item item = items[oldSlot];
items[oldSlot] = items[newSlot]; items[oldSlot] = items[newSlot];
items[newSlot] = tmp; items[newSlot] = item;
notifyItemUpdated(oldSlot); notifyItemUpdated(oldSlot);
notifyItemUpdated(newSlot); notifyItemUpdated(newSlot);
} }
+8 -2
View File
@@ -14,6 +14,11 @@ public final class Item {
*/ */
private final int amount; private final int amount;
/**
* The item definition.
*/
private final ItemDefinition definition;
/** /**
* The item's id. * The item's id.
*/ */
@@ -41,6 +46,7 @@ public final class Item {
} }
this.id = id; this.id = id;
this.amount = amount; this.amount = amount;
this.definition = ItemDefinition.lookup(id);
} }
/** /**
@@ -53,12 +59,12 @@ public final class Item {
} }
/** /**
* Gets the {@link ItemDefinition} which describes this item. * Gets the {@link ItemDefinition} that describes this item.
* *
* @return The definition. * @return The definition.
*/ */
public ItemDefinition getDefinition() { public ItemDefinition getDefinition() {
return ItemDefinition.lookup(id); return definition;
} }
/** /**
+3 -9
View File
@@ -17,11 +17,6 @@ import org.apollo.game.sync.block.SynchronizationBlockSet;
*/ */
public abstract class Mob extends Entity { public abstract class Mob extends Entity {
/**
* The generated serial uid.
*/
private static final long serialVersionUID = 8342608309450355638L;
/** /**
* This mob's current action. * This mob's current action.
*/ */
@@ -33,7 +28,7 @@ public abstract class Mob extends Entity {
protected transient SynchronizationBlockSet blockSet = new SynchronizationBlockSet(); protected transient SynchronizationBlockSet blockSet = new SynchronizationBlockSet();
/** /**
* This mob's npc definition. A player only uses this if they are appearing as an npc in-game. * This mob's npc definition. A player only uses this if they are appearing as an npc.
*/ */
protected NpcDefinition definition; protected NpcDefinition definition;
@@ -424,7 +419,7 @@ public abstract class Mob extends Entity {
this.position = position; this.position = position;
teleporting = true; teleporting = true;
walkingQueue.clear(); walkingQueue.clear();
stopAction(); // TODO do it on any movement is a must... walking queue perhaps? stopAction();
} }
/** /**
@@ -433,8 +428,7 @@ public abstract class Mob extends Entity {
* @param position The position to face. * @param position The position to face.
*/ */
public final void turnTo(Position position) { public final void turnTo(Position position) {
blockSet.add(SynchronizationBlock.createTurnToPositionBlock(position)); blockSet.add(SynchronizationBlock.createTurnToPositionBlock(this.facingPosition = position));
this.facingPosition = position;
} }
} }
-1
View File
@@ -8,7 +8,6 @@ import org.apollo.game.sync.block.SynchronizationBlock;
* *
* @author Major * @author Major
*/ */
@SuppressWarnings("serial")
public final class Npc extends Mob { public final class Npc extends Mob {
/** /**
+47 -51
View File
@@ -17,8 +17,10 @@ import org.apollo.game.event.impl.SwitchTabInterfaceEvent;
import org.apollo.game.event.impl.UpdateRunEnergyEvent; import org.apollo.game.event.impl.UpdateRunEnergyEvent;
import org.apollo.game.model.Inventory.StackMode; import org.apollo.game.model.Inventory.StackMode;
import org.apollo.game.model.inter.InterfaceConstants; import org.apollo.game.model.inter.InterfaceConstants;
import org.apollo.game.model.inter.InterfaceListener;
import org.apollo.game.model.inter.InterfaceSet; import org.apollo.game.model.inter.InterfaceSet;
import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inter.bank.BankConstants;
import org.apollo.game.model.inter.bank.BankInterfaceListener;
import org.apollo.game.model.inv.AppearanceInventoryListener; import org.apollo.game.model.inv.AppearanceInventoryListener;
import org.apollo.game.model.inv.FullInventoryListener; import org.apollo.game.model.inv.FullInventoryListener;
import org.apollo.game.model.inv.InventoryListener; import org.apollo.game.model.inv.InventoryListener;
@@ -27,7 +29,6 @@ import org.apollo.game.model.settings.PrivacyState;
import org.apollo.game.model.settings.PrivilegeLevel; import org.apollo.game.model.settings.PrivilegeLevel;
import org.apollo.game.model.settings.ScreenBrightness; import org.apollo.game.model.settings.ScreenBrightness;
import org.apollo.game.model.skill.LevelUpSkillListener; import org.apollo.game.model.skill.LevelUpSkillListener;
import org.apollo.game.model.skill.SkillListener;
import org.apollo.game.model.skill.SynchronizationSkillListener; import org.apollo.game.model.skill.SynchronizationSkillListener;
import org.apollo.game.sync.block.SynchronizationBlock; import org.apollo.game.sync.block.SynchronizationBlock;
import org.apollo.net.session.GameSession; import org.apollo.net.session.GameSession;
@@ -41,11 +42,6 @@ import org.apollo.util.Point;
*/ */
public final class Player extends Mob { public final class Player extends Mob {
/**
* The generated serial uid.
*/
private static final long serialVersionUID = -5865532568677077237L;
/** /**
* The player's appearance. * The player's appearance.
*/ */
@@ -64,7 +60,7 @@ public final class Player extends Mob {
/** /**
* A deque of this player's mouse clicks. * A deque of this player's mouse clicks.
*/ */
private transient Deque<Point> clicks = new ArrayDeque<Point>(); private transient Deque<Point> clicks = new ArrayDeque<>();
/** /**
* The version of the client this player is using. This is not the same as the release number, instead denoting the * The version of the client this player is using. This is not the same as the release number, instead denoting the
@@ -77,11 +73,6 @@ public final class Player extends Mob {
*/ */
private PlayerCredentials credentials; private PlayerCredentials credentials;
/**
* A flag indicating if the player has designed their avatar.
*/
private boolean designedAvatar = false;
/** /**
* A flag which indicates there are npcs that couldn't be added. * A flag which indicates there are npcs that couldn't be added.
*/ */
@@ -132,6 +123,11 @@ public final class Player extends Mob {
*/ */
private transient boolean members = false; private transient boolean members = false;
/**
* A flag indicating if the player is new.
*/
private boolean newPlayer = false;
/** /**
* This player's prayer icon. * This player's prayer icon.
*/ */
@@ -200,8 +196,8 @@ public final class Player extends Mob {
*/ */
public Player(PlayerCredentials credentials, Position position) { public Player(PlayerCredentials credentials, Position position) {
super(position); super(position);
init();
this.credentials = credentials; this.credentials = credentials;
init();
} }
/** /**
@@ -477,15 +473,6 @@ public final class Player extends Mob {
return worldId; return worldId;
} }
/**
* Checks if the player has designed their avatar.
*
* @return A flag indicating if the player has designed their avatar.
*/
public boolean hasDesignedAvatar() {
return designedAvatar;
}
/** /**
* Indicates whether or not the player with the specified username is on this player's ignore list. * Indicates whether or not the player with the specified username is on this player's ignore list.
* *
@@ -535,22 +522,17 @@ public final class Player extends Mob {
* Initialises the player's inventories. * Initialises the player's inventories.
*/ */
private void initInventories() { private void initInventories() {
// inventory full listeners
InventoryListener fullInventoryListener = new FullInventoryListener(this, InventoryListener fullInventoryListener = new FullInventoryListener(this,
FullInventoryListener.FULL_INVENTORY_MESSAGE); FullInventoryListener.FULL_INVENTORY_MESSAGE);
InventoryListener fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE); InventoryListener fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE);
// equipment appearance listener
InventoryListener appearanceListener = new AppearanceInventoryListener(this); InventoryListener appearanceListener = new AppearanceInventoryListener(this);
// synchronization listeners
InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this, InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this,
SynchronizationInventoryListener.INVENTORY_ID); SynchronizationInventoryListener.INVENTORY_ID);
InventoryListener syncBankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID); InventoryListener syncBankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID);
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this, InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this,
SynchronizationInventoryListener.EQUIPMENT_ID); SynchronizationInventoryListener.EQUIPMENT_ID);
// add the listeners
inventory.addListener(syncInventoryListener); inventory.addListener(syncInventoryListener);
inventory.addListener(fullInventoryListener); inventory.addListener(fullInventoryListener);
bank.addListener(syncBankListener); bank.addListener(syncBankListener);
@@ -563,17 +545,8 @@ public final class Player extends Mob {
* Initialises the player's skills. * Initialises the player's skills.
*/ */
private void initSkills() { private void initSkills() {
SkillSet skills = getSkillSet(); skillSet.addListener(new SynchronizationSkillListener(this));
skillSet.addListener(new LevelUpSkillListener(this));
// synchronization listener
SkillListener syncListener = new SynchronizationSkillListener(this);
// level up listener
SkillListener levelUpListener = new LevelUpSkillListener(this);
// add the listeners
skills.addListener(syncListener);
skills.addListener(levelUpListener);
} }
/** /**
@@ -603,6 +576,15 @@ public final class Player extends Mob {
return members; return members;
} }
/**
* Checks if this player has logged in before.
*
* @return A flag indicating if the player is new.
*/
public boolean isNewPlayer() {
return newPlayer;
}
/** /**
* Gets whether the player is running or not. * Gets whether the player is running or not.
* *
@@ -637,6 +619,22 @@ public final class Player extends Mob {
return filteringMessages; return filteringMessages;
} }
/**
* Opens this player's bank.
*/
public void openBank() {
InventoryListener invListener = new SynchronizationInventoryListener(this, BankConstants.SIDEBAR_INVENTORY_ID);
InventoryListener bankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID);
inventory.addListener(invListener);
bank.addListener(bankListener);
inventory.forceRefresh();
bank.forceRefresh();
InterfaceListener interListener = new BankInterfaceListener(this, invListener, bankListener);
interfaceSet.openWindowWithSidebar(interListener, BankConstants.BANK_WINDOW_ID, BankConstants.SIDEBAR_ID);
}
/** /**
* Removes the specified username from this player's friend list. * Removes the specified username from this player's friend list.
* *
@@ -694,8 +692,7 @@ public final class Player extends Mob {
private void sendInitialEvents() { private void sendInitialEvents() {
send(new IdAssignmentEvent(index, members)); // TODO should this be sent when we reconnect? send(new IdAssignmentEvent(index, members)); // TODO should this be sent when we reconnect?
sendMessage("Welcome to RuneScape."); sendMessage("Welcome to RuneScape.");
if (!newPlayer) {
if (!designedAvatar) {
interfaceSet.openWindow(InterfaceConstants.AVATAR_DESIGN); interfaceSet.openWindow(InterfaceConstants.AVATAR_DESIGN);
} }
@@ -794,15 +791,6 @@ public final class Player extends Mob {
this.clientVersion = clientVersion; this.clientVersion = clientVersion;
} }
/**
* Sets the design flag.
*
* @param designedAvatar A flag indicating if the player has designed their avatar.
*/
public void setDesigned(boolean designedAvatar) {
this.designedAvatar = designedAvatar;
}
/** /**
* Sets the friend {@link PrivacyState}. * Sets the friend {@link PrivacyState}.
* *
@@ -857,6 +845,15 @@ public final class Player extends Mob {
this.members = members; this.members = members;
} }
/**
* Sets the new player flag.
*
* @param newPlayer A flag indicating if the player has played before.
*/
public void setNew(boolean newPlayer) {
this.newPlayer = newPlayer;
}
/** /**
* Sets the player's prayer icon. * Sets the player's prayer icon.
* *
@@ -890,8 +887,7 @@ public final class Player extends Mob {
* @param runEnergy The energy. * @param runEnergy The energy.
*/ */
public void setRunEnergy(int runEnergy) { public void setRunEnergy(int runEnergy) {
this.runEnergy = runEnergy; send(new UpdateRunEnergyEvent(this.runEnergy = runEnergy));
send(new UpdateRunEnergyEvent(runEnergy));
} }
/** /**
+3 -5
View File
@@ -80,7 +80,7 @@ public final class SkillSet {
/** /**
* A list of skill listeners. * A list of skill listeners.
*/ */
private final List<SkillListener> listeners = new ArrayList<SkillListener>(); private final List<SkillListener> listeners = new ArrayList<>();
/** /**
* The skills. * The skills.
@@ -102,7 +102,6 @@ public final class SkillSet {
*/ */
public void addExperience(int id, double experience) { public void addExperience(int id, double experience) {
checkBounds(id); checkBounds(id);
Skill old = skills[id]; Skill old = skills[id];
double newExperience = old.getExperience() + experience; double newExperience = old.getExperience() + experience;
@@ -218,14 +217,13 @@ public final class SkillSet {
*/ */
public void normalize() { public void normalize() {
for (int id = 0; id < skills.length; id++) { for (int id = 0; id < skills.length; id++) {
int current = skills[id].getCurrentLevel(); int current = skills[id].getCurrentLevel(), max = skills[id].getMaximumLevel();
int max = skills[id].getMaximumLevel();
if (current == max) { if (current == max) {
continue; continue;
} }
current += current < max ? 1 : -1;
current += current < max ? 1 : -1;
setSkill(id, new Skill(skills[id].getExperience(), current, max)); setSkill(id, new Skill(skills[id].getExperience(), current, max));
} }
} }
+1 -1
View File
@@ -33,7 +33,7 @@ public final class SlottedItem {
* *
* @return The amount. * @return The amount.
*/ */
public int getamount() { public int getAmount() {
return item.getAmount(); return item.getAmount();
} }
+6 -9
View File
@@ -43,6 +43,7 @@ public final class WalkingQueue {
public String toString() { public String toString() {
return Point.class.getName() + " [direction=" + direction + ", position=" + position + "]"; return Point.class.getName() + " [direction=" + direction + ", position=" + position + "]";
} }
} }
/** /**
@@ -58,12 +59,12 @@ public final class WalkingQueue {
/** /**
* The old queue of directions. * The old queue of directions.
*/ */
private final Deque<Point> oldPoints = new ArrayDeque<Point>(); private final Deque<Point> oldPoints = new ArrayDeque<>();
/** /**
* The queue of directions. * The queue of directions.
*/ */
private final Deque<Point> points = new ArrayDeque<Point>(); private final Deque<Point> points = new ArrayDeque<>();
/** /**
* Flag indicating if this queue (only) should be ran. * Flag indicating if this queue (only) should be ran.
@@ -100,7 +101,7 @@ public final class WalkingQueue {
return true; return true;
} }
Queue<Position> travelBackQueue = new ArrayDeque<Position>(); Queue<Position> travelBackQueue = new ArrayDeque<>();
Point oldPoint; Point oldPoint;
while ((oldPoint = oldPoints.pollLast()) != null) { while ((oldPoint = oldPoints.pollLast()) != null) {
@@ -159,11 +160,9 @@ public final class WalkingQueue {
* @param step The step to add. * @param step The step to add.
*/ */
public void addStep(Position step) { public void addStep(Position step) {
int x = step.getX(), y = step.getY();
Point last = getLast(); Point last = getLast();
int x = step.getX();
int y = step.getY();
int deltaX = x - last.position.getX(); int deltaX = x - last.position.getX();
int deltaY = y - last.position.getY(); int deltaY = y - last.position.getY();
@@ -212,9 +211,7 @@ public final class WalkingQueue {
*/ */
public void pulse() { public void pulse() {
Position position = mob.getPosition(); Position position = mob.getPosition();
Direction first = Direction.NONE, second = Direction.NONE;
Direction first = Direction.NONE;
Direction second = Direction.NONE;
Point next = points.poll(); Point next = points.poll();
if (next != null) { if (next != null) {
+5 -4
View File
@@ -62,6 +62,7 @@ public final class World {
* Indicates the world is full. * Indicates the world is full.
*/ */
WORLD_FULL; WORLD_FULL;
} }
/** /**
@@ -233,8 +234,9 @@ public final class World {
*/ */
public void init(int release, IndexedFileSystem fs, PluginManager manager) throws Exception { public void init(int release, IndexedFileSystem fs, PluginManager manager) throws Exception {
this.releaseNumber = release; this.releaseNumber = release;
ItemDefinitionDecoder itemDefParser = new ItemDefinitionDecoder(fs);
ItemDefinition[] itemDefs = itemDefParser.decode(); ItemDefinitionDecoder itemDefDecoder = new ItemDefinitionDecoder(fs);
ItemDefinition[] itemDefs = itemDefDecoder.decode();
ItemDefinition.init(itemDefs); ItemDefinition.init(itemDefs);
logger.info("Loaded " + itemDefs.length + " item definitions."); logger.info("Loaded " + itemDefs.length + " item definitions.");
@@ -339,8 +341,7 @@ public final class World {
return RegistrationStatus.OK; return RegistrationStatus.OK;
} }
logger.warning("Failed to register player (server full): " + player + " [count=" + playerRepository.size() logger.warning("Failed to register player: " + player + " [count=" + playerRepository.size() + "]");
+ "]");
return RegistrationStatus.WORLD_FULL; return RegistrationStatus.WORLD_FULL;
} }
@@ -10,7 +10,7 @@ public final class WorldConstants {
/** /**
* The maximum number of npcs. * The maximum number of npcs.
*/ */
public static final int MAXIMUM_NPCS = 2000; public static final int MAXIMUM_NPCS = 32768;
/** /**
* The maximum number of players. * The maximum number of players.
@@ -174,13 +174,12 @@ public final class InterfaceSet {
} }
/** /**
* Opens the enter amount dialog. * Opens the enter amount dialogue.
* *
* @param listener The enter amount listener. * @param listener The enter amount listener.
*/ */
public void openEnterAmountDialog(EnterAmountListener listener) { public void openEnterAmountDialogue(EnterAmountListener listener) {
amountListener = listener; amountListener = listener;
player.send(new EnterAmountEvent()); player.send(new EnterAmountEvent());
} }
@@ -204,7 +203,6 @@ public final class InterfaceSet {
this.listener = listener; this.listener = listener;
interfaces.put(InterfaceType.WINDOW, windowId); interfaces.put(InterfaceType.WINDOW, windowId);
player.send(new OpenInterfaceEvent(windowId)); player.send(new OpenInterfaceEvent(windowId));
} }
@@ -35,7 +35,7 @@ public final class SynchronizationInventoryListener extends InventoryAdapter {
private final Player player; private final Player player;
/** /**
* Creates the syncrhonization inventory listener. * Creates the synchronization inventory listener.
* *
* @param player The player. * @param player The player.
* @param interfaceId The interface id. * @param interfaceId The interface id.
@@ -10,7 +10,6 @@ import org.apollo.game.model.def.ObjectDefinition;
* @author Chris Fletcher * @author Chris Fletcher
* @author Major * @author Major
*/ */
@SuppressWarnings("serial")
public final class GameObject extends Entity { public final class GameObject extends Entity {
/** /**
@@ -29,7 +28,7 @@ public final class GameObject extends Entity {
private final int type; private final int type;
/** /**
* Creates a new static object. * Creates a game object.
* *
* @param id The object's id. * @param id The object's id.
* @param position The position. * @param position The position.
@@ -93,7 +93,7 @@ public final class BinaryPlayerLoader implements PlayerLoader {
player.setRunEnergy(runEnergy); player.setRunEnergy(runEnergy);
player.setScreenBrightness(brightness); player.setScreenBrightness(brightness);
player.setDesigned(designed); player.setNew(designed);
player.setAppearance(new Appearance(gender, style, colors)); player.setAppearance(new Appearance(gender, style, colors));
// read inventories // read inventories
@@ -49,7 +49,7 @@ public final class BinaryPlayerSaver implements PlayerSaver {
out.writeByte(position.getHeight()); out.writeByte(position.getHeight());
// write appearance // write appearance
out.writeBoolean(player.hasDesignedAvatar()); out.writeBoolean(player.isNewPlayer());
Appearance appearance = player.getAppearance(); Appearance appearance = player.getAppearance();
out.writeByte(appearance.getGender().toInteger()); out.writeByte(appearance.getGender().toInteger());
int[] style = appearance.getStyle(); int[] style = appearance.getStyle();
@@ -5,6 +5,7 @@ import org.apollo.net.codec.game.DataTransformation;
import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketBuilder; import org.apollo.net.codec.game.GamePacketBuilder;
import org.apollo.net.meta.PacketType;
import org.apollo.net.release.EventEncoder; import org.apollo.net.release.EventEncoder;
/** /**
@@ -16,7 +17,7 @@ public final class SetPlayerActionEventEncoder extends EventEncoder<SetPlayerAct
@Override @Override
public GamePacket encode(SetPlayerActionEvent event) { public GamePacket encode(SetPlayerActionEvent event) {
GamePacketBuilder builder = new GamePacketBuilder(104); GamePacketBuilder builder = new GamePacketBuilder(104, PacketType.VARIABLE_BYTE);
builder.put(DataType.BYTE, DataTransformation.NEGATE, event.getSlot()); builder.put(DataType.BYTE, DataTransformation.NEGATE, event.getSlot());
builder.put(DataType.BYTE, DataTransformation.ADD, event.isPrimaryAction() ? 0 : 1); builder.put(DataType.BYTE, DataTransformation.ADD, event.isPrimaryAction() ? 0 : 1);
builder.putString(event.getText()); builder.putString(event.getText());
@@ -5,6 +5,7 @@ import org.apollo.net.codec.game.DataTransformation;
import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketBuilder; import org.apollo.net.codec.game.GamePacketBuilder;
import org.apollo.net.meta.PacketType;
import org.apollo.net.release.EventEncoder; import org.apollo.net.release.EventEncoder;
/** /**
@@ -16,7 +17,7 @@ public final class SetPlayerActionEventEncoder extends EventEncoder<SetPlayerAct
@Override @Override
public GamePacket encode(SetPlayerActionEvent event) { public GamePacket encode(SetPlayerActionEvent event) {
GamePacketBuilder builder = new GamePacketBuilder(157); GamePacketBuilder builder = new GamePacketBuilder(157, PacketType.VARIABLE_BYTE);
builder.put(DataType.BYTE, DataTransformation.NEGATE, event.getSlot()); builder.put(DataType.BYTE, DataTransformation.NEGATE, event.getSlot());
builder.putString(event.getText()); builder.putString(event.getText());
builder.put(DataType.BYTE, event.isPrimaryAction() ? 0 : 1); builder.put(DataType.BYTE, event.isPrimaryAction() ? 0 : 1);
@@ -30,7 +30,12 @@ public final class RubyPluginEnvironment implements PluginEnvironment {
@Override @Override
public void parse(InputStream is, String name) { public void parse(InputStream is, String name) {
container.runScriptlet(is, name); try {
container.runScriptlet(is, name);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error parsing scriptlet " + name + ".");
}
} }
/** /**