mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Merge branch 'master' of bitbucket.org:Major-/apollo.
This commit is contained in:
+2
-1
@@ -4,4 +4,5 @@
|
||||
/target
|
||||
*.iml
|
||||
/data/fs
|
||||
/data/savedGames
|
||||
/data/savedGames
|
||||
/bin/
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.apollo.util.LanguageUtil;
|
||||
*
|
||||
* @author Major
|
||||
* @author Graham
|
||||
* @author Ryley Kimmel <ryley.kimmel@live.com>
|
||||
*/
|
||||
public final class EquipItemHandler extends MessageHandler<ItemOptionMessage> {
|
||||
|
||||
@@ -39,11 +40,11 @@ public final class EquipItemHandler extends MessageHandler<ItemOptionMessage> {
|
||||
for (int id = 0; id < 5; id++) {
|
||||
int requirement = definition.getLevel(id);
|
||||
|
||||
if (player.getSkillSet().getSkill(id).getMaximumLevel() < requirement) {
|
||||
String skillName = Skill.getName(id);
|
||||
String article = LanguageUtil.getIndefiniteArticle(skillName);
|
||||
if (player.getSkillSet().getMaximumLevel(id) < requirement) {
|
||||
String name = Skill.getName(id);
|
||||
String article = LanguageUtil.getIndefiniteArticle(name);
|
||||
|
||||
player.sendMessage("You need " + article + " " + skillName + " level of " + requirement + " to equip this item.");
|
||||
player.sendMessage("You need " + article + " " + name + " level of " + requirement + " to equip this item.");
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
@@ -53,45 +54,70 @@ public final class EquipItemHandler extends MessageHandler<ItemOptionMessage> {
|
||||
Inventory equipment = player.getEquipment();
|
||||
|
||||
int equipmentSlot = definition.getSlot();
|
||||
Item currentlyEquipped = equipment.get(equipmentSlot);
|
||||
|
||||
if (equipping.getDefinition().isStackable() && (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) {
|
||||
equipment.set(definition.getSlot(), equipping);
|
||||
inventory.reset(inventorySlot);
|
||||
return;
|
||||
}
|
||||
|
||||
Item weapon = equipment.get(EquipmentConstants.WEAPON);
|
||||
Item shield = equipment.get(EquipmentConstants.SHIELD);
|
||||
|
||||
if (definition.isTwoHanded()) {
|
||||
int slotsRequired = weapon != null ? shield != null ? 1 : 0 : 0;
|
||||
int slotsRequired = weapon != null && shield != null ? 1 : 0;
|
||||
if (inventory.freeSlots() < slotsRequired) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the weapon and the shield slots.
|
||||
equipment.reset(EquipmentConstants.WEAPON);
|
||||
equipment.reset(EquipmentConstants.SHIELD);
|
||||
|
||||
// Set the two-handed weapon and clear it from the inventory.
|
||||
equipment.set(EquipmentConstants.WEAPON, inventory.reset(inventorySlot));
|
||||
|
||||
// Add previous shield or weapon, if present.
|
||||
if (shield != null) {
|
||||
inventory.add(shield);
|
||||
}
|
||||
if (weapon != null) {
|
||||
inventory.add(weapon);
|
||||
}
|
||||
} else if (definition.getSlot() == EquipmentConstants.SHIELD && weapon != null
|
||||
&& EquipmentDefinition.lookup(weapon.getId()).isTwoHanded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (definition.getSlot() == EquipmentConstants.SHIELD && weapon != null && EquipmentDefinition.lookup(weapon.getId()).isTwoHanded()) {
|
||||
equipment.set(EquipmentConstants.SHIELD, inventory.reset(inventorySlot));
|
||||
inventory.add(equipment.reset(EquipmentConstants.WEAPON));
|
||||
} else {
|
||||
Item previous = equipment.reset(equipmentSlot);
|
||||
inventory.remove(equipping); // no need for fancy stuff here as we know the item isn't stackable.
|
||||
equipment.set(equipmentSlot, equipping);
|
||||
if (previous != null) {
|
||||
inventory.add(previous);
|
||||
return;
|
||||
}
|
||||
|
||||
Item current = equipment.get(equipmentSlot);
|
||||
|
||||
if (current != null && current.getId() == equipping.getId() && current.getDefinition().isStackable()) {
|
||||
long total = (long) current.getAmount() + equipping.getAmount();
|
||||
|
||||
// If the total has not over flown and we can add to the existing stack, do so.
|
||||
if (total <= Integer.MAX_VALUE && !equipment.add(inventory.reset(inventorySlot)).isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int remaining = (int) (total - Integer.MAX_VALUE);
|
||||
int removed = equipping.getAmount() - remaining;
|
||||
|
||||
if (remaining == equipping.getAmount()) {
|
||||
equipment.set(equipmentSlot, equipping);
|
||||
inventory.set(inventorySlot, current);
|
||||
return;
|
||||
}
|
||||
|
||||
inventory.remove(equipping.getId(), removed);
|
||||
equipment.add(equipping.getId(), removed);
|
||||
return;
|
||||
}
|
||||
|
||||
Item previous = equipment.reset(equipmentSlot);
|
||||
inventory.remove(equipping);
|
||||
equipment.set(equipmentSlot, equipping);
|
||||
|
||||
if (previous != null) {
|
||||
inventory.set(inventorySlot, previous);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user