mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Add consistency to events and handlers.
This commit is contained in:
@@ -83,10 +83,8 @@ public final class BankEventHandler extends EventHandler<ItemActionEvent> {
|
|||||||
if (amount == -1) {
|
if (amount == -1) {
|
||||||
player.getInterfaceSet().openEnterAmountDialog(
|
player.getInterfaceSet().openEnterAmountDialog(
|
||||||
new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId()));
|
new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId()));
|
||||||
} else {
|
} else if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) {
|
||||||
if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) {
|
ctx.breakHandlerChain();
|
||||||
ctx.breakHandlerChain();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
|||||||
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 equippingDefinition = EquipmentDefinition.lookup(equippingId);
|
EquipmentDefinition definition = EquipmentDefinition.lookup(equippingId);
|
||||||
|
|
||||||
if (equippingDefinition == null) {
|
if (definition == null) {
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int id = 0; id < 5; id++) {
|
for (int id = 0; id < 5; id++) {
|
||||||
int requirement = equippingDefinition.getLevel(id);
|
int requirement = definition.getLevel(id);
|
||||||
|
|
||||||
if (player.getSkillSet().getSkill(id).getMaximumLevel() < requirement) {
|
if (player.getSkillSet().getSkill(id).getMaximumLevel() < requirement) {
|
||||||
String skillName = Skill.getName(id);
|
String skillName = Skill.getName(id);
|
||||||
@@ -50,12 +50,12 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
|||||||
Inventory inventory = player.getInventory();
|
Inventory inventory = player.getInventory();
|
||||||
Inventory equipment = player.getEquipment();
|
Inventory equipment = player.getEquipment();
|
||||||
|
|
||||||
int equipmentSlot = equippingDefinition.getSlot();
|
int equipmentSlot = definition.getSlot();
|
||||||
Item currentlyEquipped = equipment.get(equipmentSlot);
|
Item currentlyEquipped = equipment.get(equipmentSlot);
|
||||||
|
|
||||||
if (equipping.getDefinition().isStackable()
|
if (equipping.getDefinition().isStackable()
|
||||||
&& (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) {
|
&& (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) {
|
||||||
equipment.set(equippingDefinition.getSlot(), equipping);
|
equipment.set(definition.getSlot(), equipping);
|
||||||
inventory.reset(inventorySlot);
|
inventory.reset(inventorySlot);
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
@@ -64,7 +64,7 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
|||||||
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 (equippingDefinition.isTwoHanded()) {
|
if (definition.isTwoHanded()) {
|
||||||
int slotsRequired = weapon != null ? shield != null ? 1 : 0 : 0;
|
int slotsRequired = weapon != null ? shield != null ? 1 : 0 : 0;
|
||||||
if (inventory.freeSlots() < slotsRequired) {
|
if (inventory.freeSlots() < slotsRequired) {
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
@@ -82,7 +82,7 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
|||||||
inventory.add(weapon);
|
inventory.add(weapon);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (equippingDefinition.getSlot() == EquipmentConstants.SHIELD && weapon != null
|
} else if (definition.getSlot() == EquipmentConstants.SHIELD && weapon != null
|
||||||
&& EquipmentDefinition.lookup(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));
|
||||||
@@ -90,13 +90,11 @@ public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Item previous = equipment.reset(equipmentSlot);
|
Item previous = equipment.reset(equipmentSlot);
|
||||||
inventory.remove(equipping); // no need for fancy stuff here as we
|
inventory.remove(equipping); // no need for fancy stuff here as we know the item isn't stackable.
|
||||||
// know the item isn't stackable.
|
|
||||||
equipment.set(equipmentSlot, equipping);
|
equipment.set(equipmentSlot, equipping);
|
||||||
if (previous != null) {
|
if (previous != null) {
|
||||||
inventory.add(previous);
|
inventory.add(previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,10 @@ public final class ItemVerificationHandler extends EventHandler<InventoryItemEve
|
|||||||
case SynchronizationInventoryListener.INVENTORY_ID:
|
case SynchronizationInventoryListener.INVENTORY_ID:
|
||||||
case BankConstants.SIDEBAR_INVENTORY_ID:
|
case BankConstants.SIDEBAR_INVENTORY_ID:
|
||||||
return player.getInventory();
|
return player.getInventory();
|
||||||
|
|
||||||
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
||||||
return player.getEquipment();
|
return player.getEquipment();
|
||||||
|
|
||||||
case BankConstants.BANK_INVENTORY_ID:
|
case BankConstants.BANK_INVENTORY_ID:
|
||||||
return player.getBank();
|
return player.getBank();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("unknown interface id: " + interfaceId);
|
throw new IllegalArgumentException("unknown interface id: " + interfaceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,9 +41,8 @@ public final class PlayerDesignVerificationHandler extends EventHandler<PlayerDe
|
|||||||
return validMaleStyle(appearance);
|
return validMaleStyle(appearance);
|
||||||
} else if (gender == Gender.FEMALE) {
|
} else if (gender == Gender.FEMALE) {
|
||||||
return validFemaleStyle(appearance);
|
return validFemaleStyle(appearance);
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("player can only be either male or female");
|
|
||||||
}
|
}
|
||||||
|
throw new IllegalArgumentException("player can only be either male or female");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ public final class RemoveEventHandler extends EventHandler<ItemActionEvent> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||||
|
|
||||||
if (event.getOption() == 1 && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) {
|
if (event.getOption() == 1 && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) {
|
||||||
Inventory inventory = player.getInventory();
|
Inventory inventory = player.getInventory();
|
||||||
Inventory equipment = player.getEquipment();
|
Inventory equipment = player.getEquipment();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package org.apollo.game.event.impl;
|
|||||||
*
|
*
|
||||||
* @author Major
|
* @author Major
|
||||||
*/
|
*/
|
||||||
public class FirstNpcActionEvent extends NpcActionEvent {
|
public final class FirstNpcActionEvent extends NpcActionEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new first npc action event.
|
* Creates a new first npc action event.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.apollo.game.event.Event;
|
|||||||
*
|
*
|
||||||
* @author Major
|
* @author Major
|
||||||
*/
|
*/
|
||||||
public class NpcActionEvent extends Event {
|
public abstract class NpcActionEvent extends Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The action number .
|
* The action number .
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package org.apollo.game.event.impl;
|
|||||||
*
|
*
|
||||||
* @author Major
|
* @author Major
|
||||||
*/
|
*/
|
||||||
public class SecondNpcActionEvent extends NpcActionEvent {
|
public final class SecondNpcActionEvent extends NpcActionEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new second npc action event.
|
* Creates a new second npc action event.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package org.apollo.game.event.impl;
|
|||||||
*
|
*
|
||||||
* @author Major
|
* @author Major
|
||||||
*/
|
*/
|
||||||
public class ThirdNpcActionEvent extends NpcActionEvent {
|
public final class ThirdNpcActionEvent extends NpcActionEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new third npc action event.
|
* Creates a new third npc action event.
|
||||||
|
|||||||
Reference in New Issue
Block a user