本文整理汇总了C++中ItemInstance::addQuantity方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemInstance::addQuantity方法的具体用法?C++ ItemInstance::addQuantity怎么用?C++ ItemInstance::addQuantity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemInstance
的用法示例。
在下文中一共展示了ItemInstance::addQuantity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}