mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 08:39:17 +00:00
Fix the broken equipment weilding event.
This commit is contained in:
@@ -17,6 +17,7 @@ import org.apollo.util.LanguageUtil;
|
|||||||
*
|
*
|
||||||
* @author Major
|
* @author Major
|
||||||
* @author Graham
|
* @author Graham
|
||||||
|
* @author Ryley Kimmel <ryley.kimmel@live.com>
|
||||||
*/
|
*/
|
||||||
public final class EquipItemHandler extends MessageHandler<ItemOptionMessage> {
|
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++) {
|
for (int id = 0; id < 5; id++) {
|
||||||
int requirement = definition.getLevel(id);
|
int requirement = definition.getLevel(id);
|
||||||
|
|
||||||
if (player.getSkillSet().getSkill(id).getMaximumLevel() < requirement) {
|
if (player.getSkillSet().getMaximumLevel(id) < requirement) {
|
||||||
String skillName = Skill.getName(id);
|
String name = Skill.getName(id);
|
||||||
String article = LanguageUtil.getIndefiniteArticle(skillName);
|
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();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,45 +54,70 @@ public final class EquipItemHandler extends MessageHandler<ItemOptionMessage> {
|
|||||||
Inventory equipment = player.getEquipment();
|
Inventory equipment = player.getEquipment();
|
||||||
|
|
||||||
int equipmentSlot = definition.getSlot();
|
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 weapon = equipment.get(EquipmentConstants.WEAPON);
|
||||||
Item shield = equipment.get(EquipmentConstants.SHIELD);
|
Item shield = equipment.get(EquipmentConstants.SHIELD);
|
||||||
|
|
||||||
if (definition.isTwoHanded()) {
|
if (definition.isTwoHanded()) {
|
||||||
int slotsRequired = weapon != null ? shield != null ? 1 : 0 : 0;
|
int slotsRequired = weapon != null && shield != null ? 1 : 0;
|
||||||
if (inventory.freeSlots() < slotsRequired) {
|
if (inventory.freeSlots() < slotsRequired) {
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the weapon and the shield slots.
|
||||||
equipment.reset(EquipmentConstants.WEAPON);
|
equipment.reset(EquipmentConstants.WEAPON);
|
||||||
equipment.reset(EquipmentConstants.SHIELD);
|
equipment.reset(EquipmentConstants.SHIELD);
|
||||||
|
|
||||||
|
// Set the two-handed weapon and clear it from the inventory.
|
||||||
equipment.set(EquipmentConstants.WEAPON, inventory.reset(inventorySlot));
|
equipment.set(EquipmentConstants.WEAPON, inventory.reset(inventorySlot));
|
||||||
|
|
||||||
|
// Add previous shield or weapon, if present.
|
||||||
if (shield != null) {
|
if (shield != null) {
|
||||||
inventory.add(shield);
|
inventory.add(shield);
|
||||||
}
|
}
|
||||||
if (weapon != null) {
|
if (weapon != null) {
|
||||||
inventory.add(weapon);
|
inventory.add(weapon);
|
||||||
}
|
}
|
||||||
} else if (definition.getSlot() == EquipmentConstants.SHIELD && weapon != null
|
return;
|
||||||
&& EquipmentDefinition.lookup(weapon.getId()).isTwoHanded()) {
|
}
|
||||||
|
|
||||||
|
if (definition.getSlot() == EquipmentConstants.SHIELD && weapon != null && 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));
|
||||||
} else {
|
return;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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