*/
boolean dropItems(final Player player, final String itemName, int itemCount) {
boolean result = false;
// parse the quest state into a list of still missing items
final ItemCollection itemsTodo = new ItemCollection();
itemsTodo.addFromQuestStateString(player.getQuest(questSlot));
if (player.drop(itemName, itemCount)) {
if (itemsTodo.removeItem(itemName, itemCount)) {
result = true;
}
} else {
/*
* handle the cases the player has part of the items or all divided
* in different slots
*/
final List<Item> items = player.getAllEquipped(itemName);
if (items != null) {
for (final Item item : items) {
final int quantity = item.getQuantity();
final int n = Math.min(itemCount, quantity);
if (player.drop(itemName, n)) {
itemCount -= n;
if (itemsTodo.removeItem(itemName, n)) {
result = true;
}
}
if (itemCount == 0) {
result = true;
break;
}
}
}
}
// update the quest state if some items are handed over
if (result) {
player.setQuest(questSlot, itemsTodo.toStringForQuestState());
}
return result;
}