本文整理汇总了C++中P_CHAR::giveItemBonus方法的典型用法代码示例。如果您正苦于以下问题:C++ P_CHAR::giveItemBonus方法的具体用法?C++ P_CHAR::giveItemBonus怎么用?C++ P_CHAR::giveItemBonus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类P_CHAR
的用法示例。
在下文中一共展示了P_CHAR::giveItemBonus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: equipItem
// Tries to equip an item
// if that fails it tries to put the item in the users backpack
// if *that* fails it puts it at the characters feet
// That works for NPCs as well
void equipItem( P_CHAR wearer, P_ITEM item )
{
tile_st tile = TileCache::instance()->getTile( item->id() );
// User cannot wear the item
if( tile.layer == 0 )
{
if( wearer->objectType() == enPlayer )
{
P_PLAYER pp = dynamic_cast<P_PLAYER>(wearer);
if( pp->socket() )
pp->socket()->sysMessage( tr( "You cannot wear that item.") );
}
item->toBackpack( wearer );
return;
}
cBaseChar::ItemContainer container = wearer->content();
cBaseChar::ItemContainer::const_iterator it(container.begin());
for( ; it != container.end(); ++it )
{
P_ITEM equip = *it;
// Unequip the item and free the layer that way
if( equip && ( equip->layer() == tile.layer ) )
equip->toBackpack( wearer );
wearer->removeItemBonus( equip );
}
// *finally* equip the item
wearer->addItem( static_cast<cBaseChar::enLayer>(item->layer()), item );
// Add the item bonuses
wearer->giveItemBonus( item );
}