/** * Check if a player is doing a quest for the given drop. * * @param player * @param drop * @return */ private static boolean hasQuestForDrop(Player player, QuestDrop drop) { int questId = drop.getQuestId(); QuestState qs = player.getQuestStateList().getQuestState(questId); if (qs == null || qs.getStatus() != QuestStatus.START) return false; QuestTemplate template = questsData.getQuestById(questId); CollectItems collectItems = template.getCollectItems(); if (collectItems == null) return true; for (CollectItem collectItem : collectItems.getCollectItem()) { int collectItemId = collectItem.getItemId(); int dropItemId = drop.getItemId(); if (collectItemId != dropItemId) continue; long count = player.getInventory().getItemCountByItemId(collectItemId); if (collectItem.getCount() > count) return true; } return false; }
public static boolean collectItemCheck(QuestCookie env, boolean removeItem) { Player player = env.getPlayer(); int id = env.getQuestId(); QuestState qs = player.getQuestStateList().getQuestState(id); if (qs == null) return false; QuestTemplate template = questsData.getQuestById(env.getQuestId()); CollectItems collectItems = template.getCollectItems(); if (collectItems == null) return true; for (CollectItem collectItem : collectItems.getCollectItem()) { int itemId = collectItem.getItemId(); long count = itemId == ItemId.KINAH.value() ? player.getInventory().getKinahCount() : player.getInventory().getItemCountByItemId(itemId); if (collectItem.getCount() > count) return false; } if (removeItem) { BonusTemplate bonusTemplate = bonusData.getBonusInfoByQuestId(id); List<SimpleCheckItemBonus> appliedBonuses = null; if (bonusTemplate != null) { List<AbstractInventoryBonus> bi = bonusTemplate.getItemBonuses(); int checks = 0; for (int i = 0; i < bi.size(); i++) { AbstractInventoryBonus bonus = bi.get(i); if (!(bonus instanceof SimpleCheckItemBonus)) continue; checks++; SimpleCheckItemBonus scb = (SimpleCheckItemBonus) bonus; HandlerResult result = QuestEngine.getInstance().onBonusApply(env, i, bonus); if (result == HandlerResult.UNKNOWN) { if (scb.canApply(player, env.getQuestId())) { if (appliedBonuses == null) appliedBonuses = new ArrayList<SimpleCheckItemBonus>(); appliedBonuses.add(scb); } } else if (result == HandlerResult.SUCCESS) { if (appliedBonuses == null) appliedBonuses = new ArrayList<SimpleCheckItemBonus>(); appliedBonuses.add(scb); } } // If check constraints added (like in redeems), returns no bonus if (checks > 0 && appliedBonuses == null) return false; } for (CollectItem collectItem : collectItems.getCollectItem()) { if (collectItem.getItemId() == 182400001) player.getInventory().decreaseKinah(collectItem.getCount()); else { boolean removeResult = player .getInventory() .removeFromBagByItemId(collectItem.getItemId(), collectItem.getCount()); if (!removeResult) return false; } } if (appliedBonuses != null) { for (AbstractInventoryBonus bonus : appliedBonuses) { // TODO: we can not check if the inventory is full // when called from the script bonus.apply(player, null); } } } return true; }