本文整理汇总了C++中CGameItemPtr::getInventory方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameItemPtr::getInventory方法的具体用法?C++ CGameItemPtr::getInventory怎么用?C++ CGameItemPtr::getInventory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGameItemPtr
的用法示例。
在下文中一共展示了CGameItemPtr::getInventory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: destroyItem
//---------------------------------------------------
// destroyItem :
//
//---------------------------------------------------
void CGameItemManager::destroyItem( CGameItemPtr &ptr )
{
H_AUTO(GIM_destroyItem);
if (ptr == NULL)
return;
// used to know if we modified the content of a bag on the ground
CGameItemPtr modifiedBag = NULL;
// Remove the item from it's inventory (if any)
if (ptr->getInventory() != NULL)
{
ptr->getInventory()->removeItem(ptr->getInventorySlot());
}
if (ptr->getRefInventory() != NULL)
{
ptr->getRefInventory()->removeItem(ptr->getRefInventorySlot());
}
ptr.deleteItem();
} // destroyItem //
示例2: doInsertItem
// ****************************************************************************
CInventoryBase::TInventoryOpResult CInventoryBase::doInsertItem(CGameItemPtr &item, uint32 slot, bool autoStack, bool ignoreWeightAndBulk)
{
H_AUTO(doInsertItem);
nlassert(item != NULL);
nlassert(item->getInventory() == NULL);
nlassert(slot < _Items.size() || slot == INVENTORIES::INSERT_IN_FIRST_FREE_SLOT);
if (!ignoreWeightAndBulk)
{
if (item->getStackWeight() + getInventoryWeight() > getMaxWeight())
return ior_overweight;
if (item->getStackBulk() + getInventoryBulk() > getMaxBulk())
return ior_overbulk;
}
if (autoStack)
{
H_AUTO(AutoStack);
// If slot provided check we can stack if we can't find an empty slot
if (slot != INVENTORIES::INSERT_IN_FIRST_FREE_SLOT)
if (canStackItem(item, slot) != ior_ok)
slot = INVENTORIES::INSERT_IN_FIRST_FREE_SLOT;
uint32 slotBegin = slot;
uint32 slotSearch;
uint32 itemStackSize = item->getStackSize();
// get first compatible stack
if (slot == INVENTORIES::INSERT_IN_FIRST_FREE_SLOT)
slotBegin = 0;
slotSearch = slotBegin;
// Modification to do : (slot to put item, stack size to put)
vector< pair<uint32,uint32> > Modifs;
// If slot provided is NULL directly insert item in it
if (_Items[slotBegin] == NULL)
{
Modifs.push_back(make_pair(slotBegin, itemStackSize));
}
else
{
// do the following until all items in the stack are transfered to stacks (and empty slot)
while (1)
{
// Search for a compatible stack (not null slot, not full slot)
bool bFound = false;
do
{
if ( (_Items[slotSearch] != NULL)
&& (_Items[slotSearch]->getStackSize() < _Items[slotSearch]->getMaxStackSize())
&& (CGameItem::areStackable(item, _Items[slotSearch]))) // no check on stack size here
{
bFound = true;
break;
}
slotSearch++;
if (slotSearch == getSlotCount()) slotSearch = 0;
}
while (slotSearch != slotBegin);
if (bFound)
{
// We found a slot with an existing stack that is compatible
// Try to put as much as we can into this stack
if (itemStackSize > _Items[slotSearch]->getMaxStackSize() - _Items[slotSearch]->getStackSize())
{
uint32 sizePut = _Items[slotSearch]->getMaxStackSize() - _Items[slotSearch]->getStackSize();
itemStackSize -= sizePut;
Modifs.push_back(make_pair(slotSearch, sizePut));
slotSearch++;
if (slotSearch == getSlotCount()) slotSearch = 0;
if (slotSearch != slotBegin)
continue; // if we have not finished the loop try the next slot
}
else
{
Modifs.push_back(make_pair(slotSearch, itemStackSize));
break; // finished
}
}
// Can't insert item in an already existing stack
if (getFreeSlotCount() == 0)
return ior_no_free_slot; // No more empty slot in this inventory !!!
slotSearch = getFirstFreeSlot();
Modifs.push_back(make_pair(slotSearch, itemStackSize));
break; // finished
}
}
// Apply all modifs to the inventory
bool bInserted = false;
for (uint32 i = 0; i < Modifs.size(); ++i)
{
uint32 slotModif = Modifs[i].first;
uint32 sizeModif = Modifs[i].second;
//.........这里部分代码省略.........