本文整理汇总了C++中CGameItemPtr::deleteItem方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameItemPtr::deleteItem方法的具体用法?C++ CGameItemPtr::deleteItem怎么用?C++ CGameItemPtr::deleteItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGameItemPtr
的用法示例。
在下文中一共展示了CGameItemPtr::deleteItem方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deleteItem
/// Delete the nth item from this inventory
// ****************************************************************************
void CInventoryBase::deleteItem(uint32 slot)
{
nlassert(slot < _Items.size());
if (_Items[slot] != NULL)
{
// unlink the item
CGameItemPtr item = removeItem(slot,_Items[slot]->getStackSize());
// delete it
item.deleteItem();
}
}
示例2: preOrderSheet
//---------------------------------------------------
void CCharacterVersionAdapter::adaptToVersion17(CCharacter &character) const
{
// only for pre-order players
CPlayer * p = PlayerManager.getPlayer( PlayerManager.getPlayerId( character.getId() ) );
if (p != NULL && p->isPreOrder())
{
INVENTORIES::TInventory inventories[] =
{
INVENTORIES::bag,
INVENTORIES::pet_animal1,
INVENTORIES::pet_animal2,
INVENTORIES::pet_animal3,
INVENTORIES::pet_animal4,
INVENTORIES::player_room
};
CSheetId preOrderSheet("pre_order.sitem");
BOMB_IF(preOrderSheet == CSheetId::Unknown, "cannot find pre_order.sitem!", return);
// restore pre-order item hp to the max if any
bool foundPreOrderItem = false;
for (uint i = 0; i < sizeof(inventories)/sizeof(inventories[0]); ++i)
{
CInventoryPtr inv = character.getInventory(inventories[i]);
if (inv == NULL)
continue;
for (uint slot = 0; slot < inv->getSlotCount(); ++slot)
{
CGameItemPtr item = inv->getItem(slot);
if (item == NULL)
continue;
if (item->getSheetId() == preOrderSheet)
{
foundPreOrderItem = true;
item->addHp(item->maxDurability());
}
}
}
// give a new pre-order item to players who lost it
if (!foundPreOrderItem)
{
CGameItemPtr item = character.createItem(10, 1, preOrderSheet);
BOMB_IF(item == NULL, "cannot create pre_order.sitem!", return);
if (!character.addItemToInventory(INVENTORIES::bag, item))
if (!character.addItemToInventory(INVENTORIES::temporary, item))
item.deleteItem();
}
示例3: 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 //
示例4: 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;
}