本文整理汇总了C++中ItemInstance::getQuantity方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemInstance::getQuantity方法的具体用法?C++ ItemInstance::getQuantity怎么用?C++ ItemInstance::getQuantity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemInstance
的用法示例。
在下文中一共展示了ItemInstance::getQuantity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hasEquipped
//----[ hasEquipped ]--------------------------------------------------------
bool ClientItemsInterface::hasEquipped(unsigned int item_type, int quantity) {
for (unsigned int i = 0; i < items_in_inventory_; ++i) {
if (inventory_[i].equipped == false) continue;
ItemInstance* item = inventory_[i].item.dereference();
if (!item) {
repackInventory();
return false;
} else {
if (item->getDescription()->type_index == item_type) {
quantity -= item->getQuantity();
if (quantity <= 0) return true;
}
}
}
return false;
}
示例2: isCarryingNew
//----[ isCarryingNew ]------------------------------------------------------
bool ClientItemsInterface::isCarryingNew(unsigned int item_type,
int quantity,
ItemIDType oldest_id) {
for (unsigned int i = 0; i < items_in_inventory_; ++i) {
ItemInstance* item = inventory_[i].item.dereference();
if (!item) {
repackInventory();
return false;
} else {
if (item->getDescription()->type_index == item_type &&
item->getUniqueID() >= oldest_id) { // consider only new items
quantity -= item->getQuantity();
if (quantity <= 0) return true;
}
}
}
return false;
}
示例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;
}