本文整理汇总了C++中CGameItemPtr::setInventory方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameItemPtr::setInventory方法的具体用法?C++ CGameItemPtr::setInventory怎么用?C++ CGameItemPtr::setInventory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGameItemPtr
的用法示例。
在下文中一共展示了CGameItemPtr::setInventory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doInsertItem
//.........这里部分代码省略.........
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;
if (_Items[slotModif] == NULL)
{
// set stack size before we add the item to the inventory to avoid the callback onItemStackSizeChanged()
// which update weight and bulk
item->setStackSize(sizeModif);
// update weight and bulk "manually"
updateWeightAndBulk(item, sizeModif);
// put the item in the inventory
_Items[slotModif] = item;
item->setInventory(CInventoryPtr(this), slotModif);
--_FreeSlotCount;
onItemChanged(slotModif, INVENTORIES::itc_inserted);
bInserted = true;
}
else
{
// callbacks are called in setStackSize (inventory onItemStackSizeChanged)
_Items[slotModif]->setStackSize(_Items[slotModif]->getStackSize()+sizeModif);
}
}
INVENTORIES::TInventoryChangeFlags flagInvChg(INVENTORIES::ic_total_bulk);
flagInvChg.setEnumValue(INVENTORIES::ic_total_weight);
flagInvChg.setEnumValue(INVENTORIES::ic_item_list);
onInventoryChanged(flagInvChg);
// If the item is not inserted into the inventory it has no more reason to exist because
// it was fully splitted into all the stacks of the inventory
if (!bInserted)
{
item.deleteItem();
item = NULL;
}
}
else
{
H_AUTO(NoneStackableItem);
// check that we still have a free slot
if (getFreeSlotCount() == 0)
return ior_no_free_slot;
if (slot == INVENTORIES::INSERT_IN_FIRST_FREE_SLOT)
slot = getFirstFreeSlot();
// delete any item on this slot
if (_Items[slot] != NULL)
{
deleteItem(slot);
}
_Items[slot] = item;
item->setInventory(CInventoryPtr(this), slot);
updateWeightAndBulk(item, item->getStackSize());
--_FreeSlotCount;
// callback all the views : 2 messages :
// * item inserted
// * inventory change bulk, weight and list
INVENTORIES::TInventoryChangeFlags flagInvChg(INVENTORIES::ic_total_bulk);
flagInvChg.setEnumValue(INVENTORIES::ic_total_weight);
flagInvChg.setEnumValue(INVENTORIES::ic_item_list);
INVENTORIES::TItemChangeFlags flagItemChg(INVENTORIES::itc_inserted);
TViewCont::iterator first(_InventoryViews.begin()), last(_InventoryViews.end());
for (; first!= last; ++first)
{
CInventoryViewPtr view = *first;
view->onInventoryChanged(flagInvChg);
view->onItemChanged(slot, flagItemChg);
}
}
return ior_ok;
}