@SuppressWarnings("unchecked")
public boolean preCheck(final Entity entity, final Player player) {
final StendhalRPZone zone = player.getZone();
if (parent != null) {
final EntitySlot rpslot = (EntitySlot) parent.getSlot(slot);
rpslot.clearErrorMessage();
if (!rpslot.isReachableForThrowingThingsIntoBy(player)) {
player.sendPrivateText(rpslot.getErrorMessage());
logger.debug("Unreachable slot");
return false;
}
if (rpslot.isFull()) {
boolean isStackable = false;
// is the entity stackable
if (entity instanceof Stackable<?>) {
final Stackable<?> stackEntity = (Stackable<?>) entity;
// now check if it can be stacked on top of another item
final Iterator<RPObject> it = rpslot.iterator();
while (it.hasNext()) {
final RPObject object = it.next();
if (object instanceof Stackable<?>) {
// found another stackable
@SuppressWarnings("rawtypes")
final Stackable other = (Stackable<?>) object;
if (other.isStackable(stackEntity)) {
// other is the same type...merge them
isStackable = true;
}
}
}
}
if (!isStackable) {
// entity cannot be stacked on top of another...
// so the equip is invalid
player.sendPrivateText("There is no space in there.");
return false;
}
}
// check if someone tried to put an item into itself (maybe
// through various levels of indirection)
if (rpslot.hasAsAncestor(entity)) {
logger.warn("tried to put item " + entity.getID()
+ " into itself, equip rejected");
return false;
}
if (entity instanceof Item) {
Item item = (Item) entity;
if (item.isBound() && rpslot.isTargetBoundCheckRequired()) {
player.sendPrivateText("You cannot put this special quest reward there because it can only be used by you.");
return false;
}
// check if an item that is sent to a trade slot is not damaged
if (item.getDeterioration() > 0 && rpslot.getName().equals("trade")) {
player.sendPrivateText("You must not trade a damaged item with other players.");
return false;
}
}