public void giveItems(int itemId, long count, Element element, int power) { Player player = getPlayer(); if (player == null) { return; } if (count <= 0) { count = 1; } // Get template of item ItemTemplate template = ItemHolder.getInstance().getTemplate(itemId); if (template == null) { return; } for (int i = 0; i < count; i++) { ItemInstance item = ItemFunctions.createItem(itemId); if (element != Element.NONE) { item.setAttributeElement(element, power); } // Add items to player's inventory player.getInventory().addItem(item); } player.sendPacket(SystemMessage2.obtainItems(template.getItemId(), count, 0)); player.sendChanges(); }
/** * Destroy element used by quest when quest is exited * * @param repeatable * @return QuestState */ public QuestState exitCurrentQuest(boolean repeatable) { Player player = getPlayer(); if (player == null) { return this; } removePlayerOnKillListener(); // Clean drops for (int itemId : _quest.getItems()) { // Get [item from] / [presence of the item in] the inventory of the player ItemInstance item = player.getInventory().getItemByItemId(itemId); if ((item == null) || (itemId == 57)) { continue; } long count = item.getCount(); // If player has the item in inventory, destroy it (if not gold) player.getInventory().destroyItemByItemId(itemId, count); player.getWarehouse().destroyItemByItemId(itemId, count); // TODO [G1ta0] analyze this } // If quest is repeatable, delete quest from list of quest of the player and from database // (quest CAN be created again => repeatable) if (repeatable) { player.removeQuestState(_quest.getName()); Quest.deleteQuestInDb(this); _vars.clear(); } else { // Otherwise, delete variables for quest and update database (quest CANNOT be created // again => not repeatable) for (String var : _vars.keySet()) { if (var != null) { unset(var); } } setState(Quest.COMPLETED); Quest.updateQuestInDb(this); // FIXME: оно вроде не нужно? } if (isCompleted()) { // WorldStatisticsManager.getInstance().updateStat(player, CategoryType.QUESTS_COMPLETED,0, // 1); } player.sendPacket(new QuestList(player)); return this; }
public long getSumQuestItemsCount(int... itemIds) { Player player = getPlayer(); if (player == null) { return 0; } long count = 0; for (int itemId : itemIds) { count += player.getInventory().getCountOf(itemId); } return count; }
public boolean checkQuestItemsCount(int... itemIds) { Player player = getPlayer(); if (player == null) { return false; } for (int itemId : itemIds) { if (player.getInventory().getCountOf(itemId) <= 0) { return false; } } return true; }
/** * Удаляет указанные предметы из инвентаря игрока, и обновляет инвентарь * * @param itemId : id удаляемого предмета * @param count : число удаляемых предметов<br> * Если count передать -1, то будут удалены все указанные предметы. * @return Количество удаленных предметов */ public long takeItems(int itemId, long count) { Player player = getPlayer(); if (player == null) { return 0; } // Get object item from player's inventory list ItemInstance item = player.getInventory().getItemByItemId(itemId); if (item == null) { return 0; } // Tests on count value in order not to have negative value if ((count < 0) || (count > item.getCount())) { count = item.getCount(); } // Destroy the quantity of items wanted player.getInventory().destroyItemByItemId(itemId, count); // Send message of destruction to client player.sendPacket(SystemMessage2.removeItems(itemId, count)); return count; }
/** * Return the quantity of one sort of item hold by the player * * @param itemId : ID of the item wanted to be count * @return int */ public long getQuestItemsCount(int itemId) { Player player = getPlayer(); return player == null ? 0 : player.getInventory().getCountOf(itemId); }
public boolean hasQuestItems(int itemId) { return _player.getInventory().getItemByItemId(itemId) != null; }