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(); }
@Override public boolean useItem(Playable playable, ItemInstance item, boolean ctrl) { if (!playable.isPlayer()) return false; Player activeChar = playable.getPlayer(); if (!activeChar.isQuestContinuationPossible(true)) return false; Map<Integer, Long> items = new HashMap<Integer, Long>(); long count = 0; do { count++; getGroupItem(activeChar, _dropmats, items); getGroupItem(activeChar, _dropacc, items); getGroupItem(activeChar, _dropevents, items); getGroupItem(activeChar, _dropench, items); } while (ctrl && item.getCount() > count && activeChar.isQuestContinuationPossible(false)); activeChar.getInventory().destroyItem(item, count); // FIXME [G1ta0] item-API activeChar.sendPacket(SystemMessage2.removeItems(item.getItemId(), count)); for (Entry<Integer, Long> e : items.entrySet()) activeChar.sendPacket(SystemMessage2.obtainItems(e.getKey(), e.getValue(), 0)); 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; }