Minor definition updates.

This commit is contained in:
Major-
2013-11-03 04:28:53 +00:00
parent 275b16ddc9
commit 918c356e40
15 changed files with 455 additions and 431 deletions
@@ -25,7 +25,7 @@ public final class EquipEventHandler extends EventHandler<EquipEvent> {
int inventorySlot = event.getSlot(); int inventorySlot = event.getSlot();
Item equipping = player.getInventory().get(inventorySlot); Item equipping = player.getInventory().get(inventorySlot);
int equippingId = equipping.getId(); int equippingId = equipping.getId();
EquipmentDefinition equippingDef = EquipmentDefinition.forId(equippingId); EquipmentDefinition equippingDef = EquipmentDefinition.lookup(equippingId);
if (equippingDef == null) { if (equippingDef == null) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
@@ -84,7 +84,7 @@ public final class EquipEventHandler extends EventHandler<EquipEvent> {
} }
return; return;
} else if (equippingDef.getSlot() == EquipmentConstants.SHIELD && weapon != null } else if (equippingDef.getSlot() == EquipmentConstants.SHIELD && weapon != null
&& EquipmentDefinition.forId(weapon.getId()).isTwoHanded()) { && EquipmentDefinition.lookup(weapon.getId()).isTwoHanded()) {
equipment.set(EquipmentConstants.SHIELD, inventory.reset(inventorySlot)); equipment.set(EquipmentConstants.SHIELD, inventory.reset(inventorySlot));
inventory.add(equipment.reset(EquipmentConstants.WEAPON)); inventory.add(equipment.reset(EquipmentConstants.WEAPON));
return; return;
@@ -28,7 +28,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.forId(id).isStackable()) { if (inventory.freeSlots() == 0 && !ItemDefinition.lookup(id).isStackable()) {
inventory.forceCapacityExceeded(); inventory.forceCapacityExceeded();
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
+1 -1
View File
@@ -341,7 +341,7 @@ public final class Inventory implements Cloneable {
* @return The amount that was removed. * @return The amount that was removed.
*/ */
public int remove(int id, int amount) { public int remove(int id, int amount) {
ItemDefinition def = ItemDefinition.forId(id); ItemDefinition def = ItemDefinition.lookup(id);
boolean stackable = isStackable(def); boolean stackable = isStackable(def);
if (stackable) { if (stackable) {
for (int slot = 0; slot < capacity; slot++) { for (int slot = 0; slot < capacity; slot++) {
+1 -1
View File
@@ -67,7 +67,7 @@ public final class Item {
* @return The definition. * @return The definition.
*/ */
public ItemDefinition getDefinition() { public ItemDefinition getDefinition() {
return ItemDefinition.forId(id); return ItemDefinition.lookup(id);
} }
@Override @Override
+1 -1
View File
@@ -22,7 +22,7 @@ public class Npc extends Character {
* @param position The position. * @param position The position.
*/ */
public Npc(int id, Position position) { public Npc(int id, Position position) {
this(NpcDefinition.forId(id), position); this(NpcDefinition.lookup(id), position);
} }
/** /**
@@ -35,15 +35,6 @@ public final class EquipmentDefinition {
} }
} }
public int count() {
return definitions.size();
}
/**
* The array of skill requirement levels.
*/
private int[] levels = { 1, 1, 1, 1, 1, 1, 1 };
/** /**
* Gets an equipment definition by its id. * Gets an equipment definition by its id.
* *
@@ -51,7 +42,7 @@ public final class EquipmentDefinition {
* @return {@code null} if the item is not equipment, the definition otherwise. * @return {@code null} if the item is not equipment, the definition otherwise.
* @throws IndexOutOfBoundsException If the id is out of bounds. * @throws IndexOutOfBoundsException If the id is out of bounds.
*/ */
public static EquipmentDefinition forId(int id) { public static EquipmentDefinition lookup(int id) {
if (id < 0 || id >= ItemDefinition.count()) { if (id < 0 || id >= ItemDefinition.count()) {
throw new IndexOutOfBoundsException(EquipmentDefinition.class.getName() + " lookup index " + id throw new IndexOutOfBoundsException(EquipmentDefinition.class.getName() + " lookup index " + id
+ " out of bounds."); + " out of bounds.");
@@ -64,6 +55,11 @@ public final class EquipmentDefinition {
*/ */
private final int id; private final int id;
/**
* The array of skill requirement levels.
*/
private int[] levels = { 1, 1, 1, 1, 1, 1, 1 };
/** /**
* The slot this equipment goes into. * The slot this equipment goes into.
*/ */
@@ -83,24 +79,37 @@ public final class EquipmentDefinition {
this.id = id; this.id = id;
} }
public int count() {
return definitions.size();
}
/** /**
* Gets the minimum attack level. * Gets the minimum attack level required to equip this item.
* *
* @return The minimum attack level. * @return The level.
*/ */
public int getAttackLevel() { public int getAttackLevel() {
return levels[Skill.ATTACK]; return levels[Skill.ATTACK];
} }
/** /**
* Gets the minimum defence level. * Gets the minimum defence level required to equip this item.
* *
* @return The minimum defence level. * @return The level.
*/ */
public int getDefenceLevel() { public int getDefenceLevel() {
return levels[Skill.DEFENCE]; return levels[Skill.DEFENCE];
} }
/**
* Gets the minimum hitpoints level required to equip this item.
*
* @return The level.
*/
public int getHitpointsLevel() {
return levels[Skill.HITPOINTS];
}
/** /**
* Gets the id. * Gets the id.
* *
@@ -111,30 +120,40 @@ public final class EquipmentDefinition {
} }
/** /**
* Gets the level for a specific skill by its id. * Gets the minimum level required to equip this item for a specific skill.
* *
* @param skill The skill id. * @param skill The skill id.
* @return The level.
*/ */
public int getLevel(int skill) { public int getLevel(int skill) {
if (skill < Skill.ATTACK || skill > Skill.MAGIC) { if (skill < Skill.ATTACK || skill > Skill.MAGIC) {
throw new IllegalArgumentException("Skill id out of bounds for an equipment definition."); throw new IllegalArgumentException("Skill id out of bounds.");
} }
return levels[skill]; return levels[skill];
} }
/** /**
* Gets the minimum magic level. * Gets the minimum magic level required to equip this item.
* *
* @return The minimum magic level. * @return The level.
*/ */
public int getMagicLevel() { public int getMagicLevel() {
return levels[Skill.MAGIC]; return levels[Skill.MAGIC];
} }
/** /**
* Gets the minimum ranged level. * Gets the minimum prayer level required to equip this item.
* *
* @return The minimum ranged level. * @return The level.
*/
public int getPrayerLevel() {
return levels[Skill.PRAYER];
}
/**
* Gets the minimum ranged level required to equip this item.
*
* @return The level.
*/ */
public int getRangedLevel() { public int getRangedLevel() {
return levels[Skill.RANGED]; return levels[Skill.RANGED];
@@ -150,9 +169,9 @@ public final class EquipmentDefinition {
} }
/** /**
* Gets the minimum strength level. * Gets the minimum strength level required to equip this item.
* *
* @return The minimum strength level. * @return The level.
*/ */
public int getStrengthLevel() { public int getStrengthLevel() {
return levels[Skill.STRENGTH]; return levels[Skill.STRENGTH];
@@ -219,10 +238,27 @@ public final class EquipmentDefinition {
* @param magic The required magic level. * @param magic The required magic level.
*/ */
public void setLevels(int attack, int strength, int defence, int ranged, int magic) { public void setLevels(int attack, int strength, int defence, int ranged, int magic) {
setLevels(attack, strength, defence, 1, ranged, 1, magic);
}
/**
* Sets the required levels.
*
* @param attack The required attack level.
* @param strength The required strength level.
* @param defence The required defence level.
* @param hitpoints The required hitpoints level.
* @param ranged The required ranged level.
* @param prayer The required prayer level.
* @param magic The required magic level.
*/
public void setLevels(int attack, int strength, int defence, int hitpoints, int ranged, int prayer, int magic) {
levels[Skill.ATTACK] = attack; levels[Skill.ATTACK] = attack;
levels[Skill.STRENGTH] = strength; levels[Skill.STRENGTH] = strength;
levels[Skill.DEFENCE] = defence; levels[Skill.DEFENCE] = defence;
levels[Skill.HITPOINTS] = hitpoints;
levels[Skill.RANGED] = ranged; levels[Skill.RANGED] = ranged;
levels[Skill.PRAYER] = prayer;
levels[Skill.MAGIC] = magic; levels[Skill.MAGIC] = magic;
} }
+238 -238
View File
@@ -28,31 +28,12 @@ public final class ItemDefinition {
private static final BiMap<Integer, Integer> notesInverse = notes.inverse(); private static final BiMap<Integer, Integer> notesInverse = notes.inverse();
/** /**
* Converts an item id to a noted id. * Gets the total number of items.
* *
* @param id The item id. * @return The total number of items.
* @return The noted id.
*/ */
public static int itemToNote(int id) { public static int count() {
Integer entry = notes.get(id); return definitions.length;
if (entry == null) {
return id;
}
return entry;
}
/**
* Converts a noted id to the normal item id.
*
* @param id The note id.
* @return The item id.
*/
public static int noteToItem(int id) {
Integer entry = notesInverse.get(id);
if (entry == null) {
return id;
}
return entry;
} }
/** /**
@@ -76,12 +57,17 @@ public final class ItemDefinition {
} }
/** /**
* Gets the total number of items. * Converts an item id to a noted id.
* *
* @return The total number of items. * @param id The item id.
* @return The noted id.
*/ */
public static int count() { public static int itemToNote(int id) {
return definitions.length; Integer entry = notes.get(id);
if (entry == null) {
return id;
}
return entry;
} }
/** /**
@@ -91,7 +77,7 @@ public final class ItemDefinition {
* @return The definition. * @return The definition.
* @throws IndexOutOfBoundsException If the id is out of bounds. * @throws IndexOutOfBoundsException If the id is out of bounds.
*/ */
public static ItemDefinition forId(int id) { public static ItemDefinition lookup(int id) {
if (id < 0 || id >= definitions.length) { if (id < 0 || id >= definitions.length) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
@@ -99,60 +85,74 @@ public final class ItemDefinition {
} }
/** /**
* The item's id. * Converts a noted id to the normal item id.
*
* @param id The note id.
* @return The item id.
*/ */
private final int id; public static int noteToItem(int id) {
Integer entry = notesInverse.get(id);
/** if (entry == null) {
* The name of the item. return id;
*/ }
private String name; return entry;
}
/** /**
* The description of the item. * The description of the item.
*/ */
private String description; private String description;
/**
* A flag indicating if this item is stackable.
*/
private boolean stackable;
/**
* The value of the item.
*/
private int value;
/**
* A flag indicating if this item is members only.
*/
private boolean members;
/**
* This item's team.
*/
private int team;
/** /**
* The ground actions array. * The ground actions array.
*/ */
private String[] groundActions = new String[5]; private String[] groundActions = new String[5];
/**
* The item's id.
*/
private final int id;
/** /**
* The inventory actions array. * The inventory actions array.
*/ */
private String[] inventoryActions = new String[5]; private String[] inventoryActions = new String[5];
/** /**
* The id of the item to copy note info from. * A flag indicating if this item is members only.
*/ */
private int noteInfoId = -1; private boolean members;
/**
* The name of the item.
*/
private String name;
/** /**
* The id of the item to copy note graphics from. * The id of the item to copy note graphics from.
*/ */
private int noteGraphicId = -1; private int noteGraphicId = -1;
/**
* The id of the item to copy note info from.
*/
private int noteInfoId = -1;
/**
* A flag indicating if this item is stackable.
*/
private boolean stackable;
/**
* This item's team.
*/
private int team;
/**
* The value of the item.
*/
private int value;
/** /**
* Creates an item definition with the default values. * Creates an item definition with the default values.
* *
@@ -163,21 +163,26 @@ public final class ItemDefinition {
} }
/** /**
* Gets the note info id. * Gets the description of this item.
* *
* @return The note info id. * @return The item's description.
*/ */
public int getNoteInfoId() { public String getDescription() {
return noteInfoId; return description;
} }
/** /**
* Gets the note graphic id. * Gets a ground action.
* *
* @return The note graphic id. * @param id The id.
* @return The action.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/ */
public int getNoteGraphicId() { public String getGroundAction(int id) {
return noteGraphicId; if (id < 0 || id >= groundActions.length) {
throw new IndexOutOfBoundsException();
}
return groundActions[id];
} }
/** /**
@@ -190,12 +195,144 @@ public final class ItemDefinition {
} }
/** /**
* Sets the note info id. * Gets an inventory action.
* *
* @param noteInfoId The note info id. * @param id The id.
* @return The action.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/ */
public void setNoteInfoId(int noteInfoId) { public String getInventoryAction(int id) {
this.noteInfoId = noteInfoId; if (id < 0 || id >= inventoryActions.length) {
throw new IndexOutOfBoundsException();
}
return inventoryActions[id];
}
/**
* Gets the name of this item.
*
* @return The name of this item, or {@code null} if it has no name.
*/
public String getName() {
return name;
}
/**
* Gets the note graphic id.
*
* @return The note graphic id.
*/
public int getNoteGraphicId() {
return noteGraphicId;
}
/**
* Gets the note info id.
*
* @return The note info id.
*/
public int getNoteInfoId() {
return noteInfoId;
}
/**
* Gets this item's team.
*
* @return The team.
*/
public int getTeam() {
return team;
}
/**
* Gets the value of this item.
*
* @return The value of this item.
*/
public int getValue() {
return value;
}
/**
* Checks if this item is members only.
*
* @return {@code true} if so, {@code false} if not.
*/
public boolean isMembersOnly() {
return members;
}
/**
* Checks if this item is a note.
*
* @return {@code true} if so, {@code false} otherwise.
*/
public boolean isNote() {
return noteGraphicId != -1 && noteInfoId != -1;
}
/**
* Checks if the item specified by this definition is stackable.
*
* @return {@code true} if so, {@code false} if not.
*/
public boolean isStackable() {
return stackable;
}
/**
* Sets the description of this item.
*
* @param description The item's description.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Sets a ground action.
*
* @param id The id.
* @param action The action.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/
public void setGroundAction(int id, String action) {
if (id < 0 || id >= groundActions.length) {
throw new IndexOutOfBoundsException();
}
groundActions[id] = action;
}
/**
* Sets an inventory action.
*
* @param id The id.
* @param action The action.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/
public void setInventoryAction(int id, String action) {
if (id < 0 || id >= inventoryActions.length) {
throw new IndexOutOfBoundsException();
}
inventoryActions[id] = action;
}
/**
* Sets the members only flag.
*
* @param members The members only flag.
*/
public void setMembersOnly(boolean members) {
this.members = members;
}
/**
* Sets the name of this item.
*
* @param name The item's name.
*/
public void setName(String name) {
this.name = name;
} }
/** /**
@@ -208,12 +345,39 @@ public final class ItemDefinition {
} }
/** /**
* Checks if this item is a note. * Sets the note info id.
* *
* @return {@code true} if so, {@code false} otherwise. * @param noteInfoId The note info id.
*/ */
public boolean isNote() { public void setNoteInfoId(int noteInfoId) {
return noteGraphicId != -1 && noteInfoId != -1; this.noteInfoId = noteInfoId;
}
/**
* Sets the stackable flag.
*
* @param stackable The stackable flag.
*/
public void setStackable(boolean stackable) {
this.stackable = stackable;
}
/**
* Sets this items team.
*
* @param team The team.
*/
public void setTeam(int team) {
this.team = team;
}
/**
* Sets the value of this item.
*
* @param value The value of this item.
*/
public void setValue(int value) {
this.value = value;
} }
/** /**
@@ -227,7 +391,7 @@ public final class ItemDefinition {
return; // already converted TODO better way of checking? return; // already converted TODO better way of checking?
} }
ItemDefinition infoDef = forId(noteInfoId); ItemDefinition infoDef = lookup(noteInfoId);
name = infoDef.name; name = infoDef.name;
members = infoDef.members; members = infoDef.members;
value = infoDef.value; value = infoDef.value;
@@ -246,168 +410,4 @@ public final class ItemDefinition {
} }
} }
/**
* Sets the name of this item.
*
* @param name The item's name.
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the name of this item.
*
* @return The name of this item, or {@code null} if it has no name.
*/
public String getName() {
return name;
}
/**
* Sets the description of this item.
*
* @param description The item's description.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Gets the description of this item.
*
* @return The item's description.
*/
public String getDescription() {
return description;
}
/**
* Sets the stackable flag.
*
* @param stackable The stackable flag.
*/
public void setStackable(boolean stackable) {
this.stackable = stackable;
}
/**
* Checks if the item specified by this definition is stackable.
*
* @return {@code true} if so, {@code false} if not.
*/
public boolean isStackable() {
return stackable;
}
/**
* Sets the value of this item.
*
* @param value The value of this item.
*/
public void setValue(int value) {
this.value = value;
}
/**
* Gets the value of this item.
*
* @return The value of this item.
*/
public int getValue() {
return value;
}
/**
* Sets the members only flag.
*
* @param members The members only flag.
*/
public void setMembersOnly(boolean members) {
this.members = members;
}
/**
* Checks if this item is members only.
*
* @return {@code true} if so, {@code false} if not.
*/
public boolean isMembersOnly() {
return members;
}
/**
* Sets a ground action.
*
* @param id The id.
* @param action The action.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/
public void setGroundAction(int id, String action) {
if (id < 0 || id >= groundActions.length) {
throw new IndexOutOfBoundsException();
}
groundActions[id] = action;
}
/**
* Gets a ground action.
*
* @param id The id.
* @return The action.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/
public String getGroundAction(int id) {
if (id < 0 || id >= groundActions.length) {
throw new IndexOutOfBoundsException();
}
return groundActions[id];
}
/**
* Sets an inventory action.
*
* @param id The id.
* @param action The action.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/
public void setInventoryAction(int id, String action) {
if (id < 0 || id >= inventoryActions.length) {
throw new IndexOutOfBoundsException();
}
inventoryActions[id] = action;
}
/**
* Gets an inventory action.
*
* @param id The id.
* @return The action.
* @throws IndexOutOfBoundsException If the id is out of bounds.
*/
public String getInventoryAction(int id) {
if (id < 0 || id >= inventoryActions.length) {
throw new IndexOutOfBoundsException();
}
return inventoryActions[id];
}
/**
* Sets this items team.
*
* @param team The team.
*/
public void setTeam(int team) {
this.team = team;
}
/**
* Gets this item's team.
*
* @return The team.
*/
public int getTeam() {
return team;
}
} }
+109 -109
View File
@@ -12,6 +12,15 @@ public final class NpcDefinition {
*/ */
private static NpcDefinition[] definitions; private static NpcDefinition[] definitions;
/**
* Gets the total number of NPCs.
*
* @return The total number of NPCs.
*/
public static int count() {
return definitions.length;
}
/** /**
* Initialises the class with the specified set of definitions. * Initialises the class with the specified set of definitions.
* *
@@ -28,15 +37,6 @@ public final class NpcDefinition {
} }
} }
/**
* Gets the total number of NPCs.
*
* @return The total number of NPCs.
*/
public static int count() {
return definitions.length;
}
/** /**
* Gets the NPC definition for the specified id. * Gets the NPC definition for the specified id.
* *
@@ -44,7 +44,7 @@ public final class NpcDefinition {
* @return The definition. * @return The definition.
* @throws IndexOutOfBoundsException If the id is out of bounds. * @throws IndexOutOfBoundsException If the id is out of bounds.
*/ */
public static NpcDefinition forId(int id) { public static NpcDefinition lookup(int id) {
if (id < 0 || id >= definitions.length) { if (id < 0 || id >= definitions.length) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
@@ -52,20 +52,30 @@ public final class NpcDefinition {
} }
/** /**
* The NPC id. * The combat level of the NPC.
*/ */
private final int id; private int combatLevel = -1;
/**
* The name of the NPC.
*/
private String name;
/** /**
* The description of the NPC. * The description of the NPC.
*/ */
private String description; private String description;
/**
* The NPC id.
*/
private final int id;
/**
* An array of interaction options.
*/
private String[] interactions = new String[5];
/**
* The name of the NPC.
*/
private String name;
/** /**
* The NPC's size, in tiles. * The NPC's size, in tiles.
*/ */
@@ -76,16 +86,6 @@ public final class NpcDefinition {
*/ */
private int standAnim = -1, walkAnim = -1, walkBackAnim = -1, walkLeftAnim = -1, walkRightAnim = -1; private int standAnim = -1, walkAnim = -1, walkBackAnim = -1, walkLeftAnim = -1, walkRightAnim = -1;
/**
* An array of interaction options.
*/
private String[] interactions = new String[5];
/**
* The combat level of the NPC.
*/
private int combatLevel = -1;
/** /**
* Creates a new NPC definition. * Creates a new NPC definition.
* *
@@ -95,6 +95,24 @@ public final class NpcDefinition {
this.id = id; this.id = id;
} }
/**
* Gets the NPC's combat level.
*
* @return The combat level, or -1 if it doesn't have one.
*/
public int getCombatLevel() {
return combatLevel;
}
/**
* Gets the description of the NPC.
*
* @return The description.
*/
public String getDescription() {
return description;
}
/** /**
* Gets the NPC id. * Gets the NPC id.
* *
@@ -104,6 +122,29 @@ public final class NpcDefinition {
return id; return id;
} }
/**
* Gets an interaction option.
*
* @param slot The slot of the option.
* @return The option, or {@code null} if there isn't any at the specified slot.
* @throws IndexOutOfBoundsException If the slot is out of bounds.
*/
public String getInteraction(int slot) {
if (slot < 0 || slot >= interactions.length) {
throw new IndexOutOfBoundsException();
}
return interactions[slot];
}
/**
* Gets the array of interaction options.
*
* @return The interaction options.
*/
public String[] getInteractions() {
return interactions;
}
/** /**
* Gets the name of the NPC. * Gets the name of the NPC.
* *
@@ -113,15 +154,6 @@ public final class NpcDefinition {
return name; return name;
} }
/**
* Gets the description of the NPC.
*
* @return The description.
*/
public String getDescription() {
return description;
}
/** /**
* Gets the NPC's size, in tiles. * Gets the NPC's size, in tiles.
* *
@@ -177,35 +209,26 @@ public final class NpcDefinition {
} }
/** /**
* Gets an interaction option. * Checks if the NPC has a combat level.
* *
* @param slot The slot of the option. * @return {@code true} if so, {@code false} if not.
* @return The option, or {@code null} if there isn't any at the specified slot. */
public boolean hasCombatLevel() {
return combatLevel != -1;
}
/**
* Checks if there is an interaction option present.
*
* @param slot The slot to check.
* @return {@code true} if so, {@code false} if not.
* @throws IndexOutOfBoundsException If the slot is out of bounds. * @throws IndexOutOfBoundsException If the slot is out of bounds.
*/ */
public String getInteraction(int slot) { public boolean hasInteraction(int slot) {
if (slot < 0 || slot >= interactions.length) { if (slot < 0 || slot >= interactions.length) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
return interactions[slot]; return interactions[slot] != null;
}
/**
* Gets the array of interaction options.
*
* @return The interaction options.
*/
public String[] getInteractions() {
return interactions;
}
/**
* Gets the NPC's combat level.
*
* @return The combat level, or -1 if it doesn't have one.
*/
public int getCombatLevel() {
return combatLevel;
} }
/** /**
@@ -254,35 +277,12 @@ public final class NpcDefinition {
} }
/** /**
* Checks if there is an interaction option present. * Sets the NPC's combat level.
* *
* @param slot The slot to check. * @param combatLevel The combat level.
* @return {@code true} if so, {@code false} if not.
* @throws IndexOutOfBoundsException If the slot is out of bounds.
*/ */
public boolean hasInteraction(int slot) { public void setCombatLevel(int combatLevel) {
if (slot < 0 || slot >= interactions.length) { this.combatLevel = combatLevel;
throw new IndexOutOfBoundsException();
}
return interactions[slot] != null;
}
/**
* Checks if the NPC has a combat level.
*
* @return {@code true} if so, {@code false} if not.
*/
public boolean hasCombatLevel() {
return combatLevel != -1;
}
/**
* Sets the name of the NPC.
*
* @param name The name.
*/
public void setName(String name) {
this.name = name;
} }
/** /**
@@ -294,6 +294,29 @@ public final class NpcDefinition {
this.description = description; this.description = description;
} }
/**
* Sets an interaction option.
*
* @param slot The slot of the option.
* @param interaction The interaction options.
* @throws IndexOutOfBoundsException If the slot is out of bounds.
*/
public void setInteraction(int slot, String interaction) {
if (slot < 0 || slot >= interactions.length) {
throw new IndexOutOfBoundsException();
}
interactions[slot] = interaction;
}
/**
* Sets the name of the NPC.
*
* @param name The name.
*/
public void setName(String name) {
this.name = name;
}
/** /**
* Sets the size of the NPC, in tiles. * Sets the size of the NPC, in tiles.
* *
@@ -336,27 +359,4 @@ public final class NpcDefinition {
this.walkRightAnim = walkRightAnim; this.walkRightAnim = walkRightAnim;
} }
/**
* Sets an interaction option.
*
* @param slot The slot of the option.
* @param interaction The interaction options.
* @throws IndexOutOfBoundsException If the slot is out of bounds.
*/
public void setInteraction(int slot, String interaction) {
if (slot < 0 || slot >= interactions.length) {
throw new IndexOutOfBoundsException();
}
interactions[slot] = interaction;
}
/**
* Sets the NPC's combat level.
*
* @param combatLevel The combat level.
*/
public void setCombatLevel(int combatLevel) {
this.combatLevel = combatLevel;
}
} }
@@ -9,6 +9,11 @@ import org.apollo.game.model.obj.GameObject;
*/ */
public final class ObjectDefinition { public final class ObjectDefinition {
/**
* The array of game object definitions.
*/
private static ObjectDefinition[] definitions;
/** /**
* Gets the total number of objects. * Gets the total number of objects.
* *
@@ -57,56 +62,51 @@ public final class ObjectDefinition {
return definitions[id]; return definitions[id];
} }
/**
* The object's menu actions.
*/
private String[] menuActions;
/** /**
* The object's description. * The object's description.
*/ */
private String description; private String description;
/**
* Denotes whether this object has actions associated with it or not.
*/
private boolean interactive;
/**
* The object's id.
*/
private final int id;
/**
* The object's name.
*/
private String name;
/**
* Denotes whether this object is impenetrable or not.
*/
private boolean impenetrable;
/**
* Denotes whether the object can be walked over or not.
*/
private boolean solid;
/** /**
* This object's height. * This object's height.
*/ */
private int height; private int height;
/**
* The object's id.
*/
private final int id;
/**
* Denotes whether this object is impenetrable or not.
*/
private boolean impenetrable;
/**
* Denotes whether this object has actions associated with it or not.
*/
private boolean interactive;
/**
* The object's menu actions.
*/
private String[] menuActions;
/**
* The object's name.
*/
private String name;
/**
* Denotes whether the object can be walked over or not.
*/
private boolean solid;
/** /**
* This object's width. * This object's width.
*/ */
private int width; private int width;
/**
* The array of game object definitions.
*/
private static ObjectDefinition[] definitions;
/** /**
* Creates a new object definition. * Creates a new object definition.
* *
@@ -1,12 +0,0 @@
package org.apollo.game.model.def;
import org.apollo.game.model.obj.StaticObject;
/**
* Represents a type of {@link StaticObject}.
*
* @author Graham
*/
public final class StaticObjectDefinition {
}
@@ -120,7 +120,7 @@ public final class BankUtils {
int newId = player.isWithdrawingNotes() ? ItemDefinition.itemToNote(item.getId()) : item.getId(); int newId = player.isWithdrawingNotes() ? ItemDefinition.itemToNote(item.getId()) : item.getId();
if (inventory.freeSlots() == 0 && !(inventory.contains(newId) && ItemDefinition.forId(newId).isStackable())) { if (inventory.freeSlots() == 0 && !(inventory.contains(newId) && ItemDefinition.lookup(newId).isStackable())) {
inventory.forceCapacityExceeded(); inventory.forceCapacityExceeded();
return true; return true;
} }
@@ -153,7 +153,7 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder<Player
} }
if (chest != null) { if (chest != null) {
EquipmentDefinition def = EquipmentDefinition.forId(chest.getId()); EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId());
if (def != null && !def.isFullBody()) { if (def != null && !def.isFullBody()) {
playerProperties.put(DataType.SHORT, 0x100 + style[3]); playerProperties.put(DataType.SHORT, 0x100 + style[3]);
} else { } else {
@@ -170,7 +170,7 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder<Player
} }
if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { if ((helm = equipment.get(EquipmentConstants.HAT)) != null) {
EquipmentDefinition def = EquipmentDefinition.forId(helm.getId()); EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId());
if (def != null && !def.isFullHat() && !def.isFullMask()) { if (def != null && !def.isFullHat() && !def.isFullMask()) {
playerProperties.put(DataType.SHORT, 0x100 + style[0]); playerProperties.put(DataType.SHORT, 0x100 + style[0]);
} else { } else {
@@ -194,7 +194,7 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder<Player
EquipmentDefinition def = null; EquipmentDefinition def = null;
if (helm != null) { if (helm != null) {
def = EquipmentDefinition.forId(helm.getId()); def = EquipmentDefinition.lookup(helm.getId());
} }
if (def != null && (def.isFullHat() || def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { if (def != null && (def.isFullHat() || def.isFullMask()) || appearance.getGender() == Gender.FEMALE) {
playerProperties.put(DataType.BYTE, 0); playerProperties.put(DataType.BYTE, 0);
@@ -154,7 +154,7 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder<Player
} }
if (chest != null) { if (chest != null) {
EquipmentDefinition def = EquipmentDefinition.forId(chest.getId()); EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId());
if (def != null && !def.isFullBody()) { if (def != null && !def.isFullBody()) {
playerProperties.put(DataType.SHORT, 0x100 + style[3]); playerProperties.put(DataType.SHORT, 0x100 + style[3]);
} else { } else {
@@ -171,7 +171,7 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder<Player
} }
if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { if ((helm = equipment.get(EquipmentConstants.HAT)) != null) {
EquipmentDefinition def = EquipmentDefinition.forId(helm.getId()); EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId());
if (def != null && !def.isFullHat() && !def.isFullMask()) { if (def != null && !def.isFullHat() && !def.isFullMask()) {
playerProperties.put(DataType.SHORT, 0x100 + style[0]); playerProperties.put(DataType.SHORT, 0x100 + style[0]);
} else { } else {
@@ -195,7 +195,7 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder<Player
EquipmentDefinition def = null; EquipmentDefinition def = null;
if (helm != null) { if (helm != null) {
def = EquipmentDefinition.forId(helm.getId()); def = EquipmentDefinition.lookup(helm.getId());
} }
if (def != null && (def.isFullHat() || def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { if (def != null && (def.isFullHat() || def.isFullMask()) || appearance.getGender() == Gender.FEMALE) {
playerProperties.put(DataType.BYTE, 0); playerProperties.put(DataType.BYTE, 0);
+1 -1
View File
@@ -42,7 +42,7 @@ public final class EquipmentUpdater {
os.writeShort(defs.length); os.writeShort(defs.length);
for (int id = 0; id < defs.length; id++) { for (int id = 0; id < defs.length; id++) {
ItemDefinition def = ItemDefinition.forId(id); ItemDefinition def = ItemDefinition.lookup(id);
int type = getWeaponType(def); int type = getWeaponType(def);
os.writeByte(type); os.writeByte(type);
if (type != -1) { if (type != -1) {
+1 -1
View File
@@ -46,7 +46,7 @@ public final class NoteUpdater {
Map<Integer, Integer> itemToNote = new HashMap<Integer, Integer>(); Map<Integer, Integer> itemToNote = new HashMap<Integer, Integer>();
for (int id = 0; id < defs.length; id++) { for (int id = 0; id < defs.length; id++) {
ItemDefinition def = ItemDefinition.forId(id); ItemDefinition def = ItemDefinition.lookup(id);
if (def.isNote()) { if (def.isNote()) {
itemToNote.put(def.getNoteInfoId(), def.getId()); itemToNote.put(def.getNoteInfoId(), def.getId());
} }