本文整理汇总了C++中ItemInstance::removeQuantity方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemInstance::removeQuantity方法的具体用法?C++ ItemInstance::removeQuantity怎么用?C++ ItemInstance::removeQuantity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemInstance
的用法示例。
在下文中一共展示了ItemInstance::removeQuantity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eraseItems
//----[ eraseItems ]---------------------------------------------------------
int ClientItemsInterface::eraseItems(unsigned int item_type, int quantity) {
for (unsigned int i = 0; (quantity > 0) && (i < items_in_inventory_);) {
ItemInstance* item = inventory_[i].item.dereference();
if (!item) {
repackInventory();
break;
} else {
if (item->getDescription()->type_index == item_type) {
quantity = item->removeQuantity(quantity);
update_inventory_ = true;
equipment_changed_ = equipment_changed_ || inventory_[i].equipped;
inventory_dirty_bits_.set(i);
// check to see if this item was destroyed by removing
// the given quantity.
if (quantity >= 0) {
GlobalDatabaseManager::singleton()
->itemOnAvatarErased(item->getUniqueID());
GlobalItemManager::singleton()->releaseItem(&inventory_[i].item);
shiftDownToEraseInInventory(i);
}
// If the quantity has been consumed, we're done!
if (quantity <= 0) return 0;
} else {
++i;
}
}
}
return quantity;
}
示例2: consumeItem
//----[ consumeItem ]--------------------------------------------------------
bool ClientItemsInterface::consumeItem(unsigned int index,
Magic::MagicIndex* magic_index) {
assert(magic_index);
if (!inventoryItemIsValid(index)) return false;
ItemInstance* item = inventory_[index].item.dereferenceAssumingValid(); // guaranteed OK
const Item::ItemServerDescription* description
= item->getDescription();
if (description->consumable_magic ==
Magic::INVALID_MAGIC_INDEX) return false;
*magic_index = description->consumable_magic;
if (item->removeQuantity(1) >= 0) {
// this item has been fully consumed
GlobalDatabaseManager::singleton()->itemOnAvatarErased(item->getUniqueID());
GlobalItemManager::singleton()->releaseItem(&inventory_[index].item);
shiftDownToEraseInInventory(index);
} else {
// item is still available
update_inventory_ = true;
inventory_dirty_bits_.set(index);
}
todo("karl","if equipped consumable and consumed, change equipment");
return true;
}
示例3: changeEquipped
//----[ changeEquipped ]-----------------------------------------------------
bool ClientItemsInterface::changeEquipped(unsigned int item_index) {
if (!inventoryItemIsValid(item_index)) return false;
ItemInstance* item = inventory_[item_index].item.dereference();
int quantity = item->getQuantity();
if (!canHoldItems(1) && quantity > 1) return false;
equipment_changed_ = true;
inventory_[item_index].equipped = !inventory_[item_index].equipped;
update_inventory_ = true;
inventory_dirty_bits_.set(item_index);
if (quantity > 1) {
int quantity_to_remove = quantity - 1;
item->removeQuantity(quantity_to_remove);
ItemPointer new_item;
bool succeeded = false;
if (GlobalItemManager::singleton()->acquireNewItem(
quantity_to_remove,
item->getDescription()->type_index,
&new_item)) {
unsigned int new_index;
if (giveItem(&new_item, &new_index)) {
succeeded = true;
}
}
if (!succeeded) {
// put the quantity back since this new item doesn't exist
item->addQuantity(quantity_to_remove);
// make the item unequipped
inventory_[item_index].equipped = false;
}
}
return true;
}