本文整理汇总了C++中CGameItemPtr类的典型用法代码示例。如果您正苦于以下问题:C++ CGameItemPtr类的具体用法?C++ CGameItemPtr怎么用?C++ CGameItemPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CGameItemPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: H_AUTO
//---------------------------------------------------
// createItem :
//
//---------------------------------------------------
//CGameItemPtr CGameItemManager::createItem( CEntityId& id, CSheetId& sheetId, uint16 quality, sint16 slot, bool destroyable, bool dropable , const CEntityId &creatorId )
CGameItemPtr CGameItemManager::createItem( const CSheetId& sheetId, uint16 quality, bool destroyable, bool dropable , const CEntityId &creatorId )
{
H_AUTO(GIM_createItem1);
// test if the item already exists
// map<CEntityId,CGameItemPtr>::iterator itIt = _Items.find( id );
// if( itIt != _Items.end() )
// {
// nlwarning("<CGameItemManager::createItem> The item %s already exists",id.toString().c_str());
// return NULL;
// }
// MALKAV 22/01/03 : get owner, if owner not found, returns before creating the item and display a simple warning
// CGameItemPtr ownerItem = NULL;
// if( owner != CEntityId::Unknown )
// {
// ownerItem = getItem( owner );
// BOMB_IF(ownerItem == NULL ,"Bad owner found for item",return NULL);
// }
//
// create a new item
// CGameItemPtr item = getNewItem( id, sheetId, quality, destroyable, dropable );
CGameItemPtr item = getNewItem(sheetId, quality, destroyable, dropable );
if( item != NULL )
{
// nldebug("<CGameItemManager::createItem> create item %s with owner %s",id.toString().c_str(), owner.toString().c_str());
// (*item)->Owner = owner;
(*item)->setCreator( creatorId );
// insert the item in the map
// _Items.insert( make_pair(id,item) );
// _Items.insert( item );
// insert the item in the children of the owner
// MALKAV 22/01/03 : test the owner existence sooner and use a warning instead of an nlerror to keep going
// if( owner != CEntityId::Unknown )
// {
// CGameItemPtr ownerItem = getItem( owner );
// if( ownerItem!=NULL )
// {
// (*ownerItem)->addChild( item, slot );
// }
// else
// {
// nlerror("<CGameItemManager::createItem> Can't find the owner item %s",owner.toString().c_str());
// }
// }
}
else
{
// nlwarning("<CGameItemManager::createItem> Can't create the item %s with invalid sheet '%s'", id.toString().c_str(), sheetId.toString().c_str());
nlwarning("<CGameItemManager::createItem> Can't create an item with invalid sheet '%s'", sheetId.toString().c_str());
}
log_Item_Create(item->getItemId(), item->getSheetId(), item->getStackSize(), item->quality());
return item;
} // createItem //
示例2: nlassert
// ****************************************************************************
CGameItemPtr CRefInventory::removeItem(uint32 slot, uint32 quantity, TInventoryOpResult * res)
{
nlassert(slot < _Items.size());
CGameItemPtr ret = _Items[slot];
if (_Items[slot] != NULL)
{
// unlink the item
_Items[slot]->setRefInventory(CInventoryPtr(NULL), INVENTORIES::INVALID_INVENTORY_SLOT);
CGameItemPtr item = _Items[slot];
_Items[slot] = NULL;
++_FreeSlotCount;
updateWeightAndBulk(ret, -sint32(ret->getStackSize()));
// callbacks for derived class
onItemChanged(slot, INVENTORIES::itc_removed);
// callback views
INVENTORIES::TInventoryChangeFlags flagInvChg(INVENTORIES::ic_total_bulk);
flagInvChg.setEnumValue(INVENTORIES::ic_total_weight);
flagInvChg.setEnumValue(INVENTORIES::ic_item_list);
TViewCont::iterator first(_InventoryViews.begin()), last(_InventoryViews.end());
for (; first != last; ++first)
{
CInventoryViewPtr view = *first;
view->onInventoryChanged(flagInvChg);
view->onItemChanged(slot, INVENTORIES::itc_removed);
}
}
if (res != NULL)
*res = ior_ok;
return ret;
}
示例3: buildNpcSpecificItems
//----------------------------------------------------------------------------
// CGameItemManager::buildNpcSpecificItems
//----------------------------------------------------------------------------
void CGameItemManager::buildNpcSpecificItems()
{
if (EGSLight)
return;
for( CAllStaticItems::const_iterator it = CSheets::getItemMapForm().begin(); it != CSheets::getItemMapForm().end(); ++it )
{
// only keep npc items
// if( (*it).first.toString().substr(0,4) != "npc_" ) //obsolete, now we want be able to have all non craftable item
if( (*it).first.toString().substr(0,2) == "ic" )
{
continue;
}
CGameItemPtr item;
// item.newItem( CEntityId::Unknown, (*it).first, 1, 0, false,false );
item.newItem( it->first, 1, false,false );
_NpcSpecificItems.push_back(item);
#ifdef NL_DEBUG
nldebug("built npc item item %s", (*it).first.toString().c_str());
#endif
}
} // CGameItemManager //
示例4: log_Item_Move
// ****************************************************************************
CInventoryBase::TInventoryOpResult CInventoryBase::moveItem(
CInventoryBase* srcInv, uint32 srcSlot,
CInventoryBase* dstInv, uint32 dstSlot,
uint32 quantity, bool bestEffort )
{
CGameItemPtr srcItem = srcInv->getItem( srcSlot );
if (srcItem == NULL)
return ior_error;
log_Item_Move(srcItem->getItemId(), srcInv->getInventoryId(), dstInv->getInventoryId());
// Try to move it
nlctassert( INVENTORIES::REMOVE_MAX_STACK_QUANTITY == UINT_MAX ); // default arg must be compatible
TInventoryOpResult res;
CGameItemPtr removedItem = srcInv->removeItem( srcSlot, quantity, &res );
if (res != ior_ok)
return res;
// if there was no item to remove, just return ok
if (removedItem == NULL)
return ior_ok;
res = dstInv->insertItem( removedItem, dstSlot, true );
if (res != ior_ok)
{
// In case of failure, put it back (assume the stack was compliant with the boundaries of the inventory (bulk, weight...)
srcInv->insertItem( removedItem, srcSlot, true );
return res;
}
return ior_ok;
}
示例5: createSystemCraftedItem
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// create a system crafted item
static CGameItemPtr createSystemCraftedItem( uint16 quantity, const NLMISC::CSheetId& sheet )
{
if (quantity == 0) return NULL;
// if quantity > 1, check if item is stackable and check stack quantity
if (quantity > 1)
{
const CStaticItem* form = CSheets::getForm( sheet );
if( form )
{
if( form->Stackable < quantity )
{
quantity = (uint16) form->Stackable;
}
}
else
{
nlwarning("<CFaberActionCommon::createACraftedItem> can't found form for item %s", sheet.toString().c_str());
}
}
if (quantity > 1)
{
CSheetId idSheetStack("stack.sitem");
CGameItemPtr stackItem = GameItemManager.createItem( idSheetStack, (uint16)1, CEntityId::Unknown, (sint16)0, false, CEntityId::Unknown );
if( stackItem == NULL )
{
nlwarning("<CFaberActionCommon::createACraftedItem> Error while creating stack bag %s -> returned a NULL pointer", idSheetStack.toString().c_str() );
return NULL;
}
else
{
uint32 hp = 0;
uint32 hpmax = 0;
for( int q = 0; q < quantity; ++q )
{
CGameItemPtr itemTmp = GameItemManager.createItem( const_cast< CSheetId& > ( sheet ), 1, const_cast<NLMISC::CEntityId&>(stackItem->getId()), (sint16)-1, true, CEntityId::Unknown );
if (!hp && itemTmp != NULL)
{
hp = itemTmp->hp();
hpmax = itemTmp->standardHP();
}
}
return stackItem;
}
}
else // do not create a stack, as there is only one object
{
CGameItemPtr item = GameItemManager.createItem( const_cast< CSheetId& > ( sheet ), (uint16)1, CEntityId::Unknown, (sint16)0, true, CEntityId::Unknown );
if( item == NULL)
{
nlwarning("<CFaberActionCommon::createACraftedItem> Error while creating item %s -> returned a NULL pointer", sheet.toString().c_str() );
return NULL;
}
return item;
}
} // createSystemCraftedItem //
示例6: getNamedItemRef
//-----------------------------------------------------------------------------
CGameItemPtr CNamedItems::createNamedItem(const std::string & name, uint32 quantity)
{
if (quantity == 0)
return NULL;
CGameItemPtr itemSrc = getNamedItemRef(name);
if( itemSrc == NULL )
return NULL;
CGameItemPtr item = itemSrc->getItemCopy();
return item;
}
示例7: itemSheetId
//---------------------------------------------------
// getNewItem :
//
//---------------------------------------------------
//CGameItemPtr CGameItemManager::getNewItem( CEntityId& id, CSheetId& sheetId, uint16 quality, bool destroyable , bool dropable)
CGameItemPtr CGameItemManager::getNewItem( const CSheetId& sheetId, uint16 quality, bool destroyable , bool dropable)
{
CAllStaticItems::iterator itForm = CSheets::getItemMapFormNoConst().find( sheetId );
if( itForm != CSheets::getItemMapFormNoConst().end() )
{
// get the slot count
// sint16 slotCount = 0;
//nldebug("<CGameItemManager::getNewItem> Family type: %s", ITEMFAMILY::toString( (*itForm).second.Family ).c_str() );
// if( ( (*itForm).second.Family == ITEMFAMILY::BAG ) || ( (*itForm).second.Family == ITEMFAMILY::STACK ) )
// {
// slotCount = (*itForm).second.SlotCount;
// }
// create the item
CGameItemPtr item;
// item.newItem( id, sheetId, quality, slotCount, destroyable, dropable );
item.newItem( sheetId, quality, destroyable, dropable );
// if( item!=NULL )
// {
// init the dynamic values from sheet -> DONE in CGameItemCreator
//(*item).Quality = (*itForm).second.Quality;
//(*item).HP = (*itForm).second.HitPoints;
// if this item contains sub items we create them
// if( (*itForm).second.Family == ITEMFAMILY::CORPSE || (*itForm).second.Family == ITEMFAMILY::CARRION )
// {
// create the content
/* for (uint i=0; i < (*itForm).second.Content.size(); i++)
{
CSheetId itemSheetId( (*itForm).second.Content[i] );
createItem( itemSheetId, quality, id, -1, destroyable,dropable );
}
*/
// if the item is a corpse, we push it to list and erase the olds one if we reached max corpse count
// if( (*itForm).second.Family == ITEMFAMILY::CORPSE )
// {
// _Corpses.push( item );
// if( _Corpses.size() > CorpseMaxCount )
// {
// CGameItemPtr itemTmp = _Corpses.front();
// destroyItem( itemTmp );
// _Corpses.pop();
// }
// }
// }
// }
return item;
}
return NULL;
} // getNewItem //
示例8:
//---------------------------------------------------
void CCharacterVersionAdapter::adaptToVersion14(CCharacter &character) const
{
// parse all inventories and set items to max Hp when current Hp == 0
const uint sizeInv = INVENTORIES::NUM_INVENTORY;
for ( uint i = 0; i < sizeInv ; ++i )
if (character._Inventory[i] != NULL)
{
CInventoryPtr childSrc = character._Inventory[i];
for ( uint j = 0; j < childSrc->getSlotCount(); j++ )
{
CGameItemPtr item = childSrc->getItem(j);
if (item != NULL)
{
if (item->getSheetId() != CSheetId("stack.sitem") )
{
if (item->durability() == 0 && item->maxDurability() > 0)
{
nlinfo("player %s, patching item %s HP, new value= %u",
character.getId().toString().c_str(), item->getSheetId().toString().c_str(), item->maxDurability());
item->addHp(item->maxDurability());
}
}
}
}
}
}
示例9: getItem
// ****************************************************************************
void CInventoryBase::onItemStackSizeChanged(uint32 slot, uint32 previousStackSize)
{
CGameItemPtr item = getItem(slot);
sint32 deltaSize = item->getStackSize() - previousStackSize;
updateWeightAndBulk(item, deltaSize);
// callback all the views
TViewCont::iterator first(_InventoryViews.begin()), last(_InventoryViews.end());
for (; first!= last; ++first)
{
CInventoryViewPtr view = *first;
view->onItemStackSizeChanged(slot, previousStackSize);
}
}
示例10: updateWeightAndBulk
// ****************************************************************************
void CInventoryBase::updateWeightAndBulk(const CGameItemPtr &item, sint32 deltaQt)
{
const CStaticItem *form = item->getStaticForm();
if (form != NULL)
{
_InventoryBulk = uint32(max(sint32(0), sint32(_InventoryBulk + form->Bulk*deltaQt)));
_InventoryWeight = uint32(max(sint32(0), sint32(_InventoryWeight + item->weight()*deltaQt)));
if (_InventoryWeight > getMaxWeight())
{
nlwarning("Inventory '%s' : weight is overload", INVENTORIES::toString(_InventoryId).c_str());
}
if (_InventoryBulk > getMaxBulk())
{
nlwarning("Inventory '%s' : bulk is overload", INVENTORIES::toString(_InventoryId).c_str());
}
}
}
示例11: doInsertItem
// ****************************************************************************
CInventoryBase::TInventoryOpResult CRefInventory::doInsertItem(CGameItemPtr &item, uint32 slot, bool autoStack, bool ignoreWeightAndBulk)
{
nlassert(item != NULL);
nlassert(item->getRefInventory() == NULL);
nlassert(slot < _Items.size() || slot == INVENTORIES::INVALID_INVENTORY_SLOT);
if (!ignoreWeightAndBulk)
{
if (item->getStackWeight() + getInventoryWeight() > getMaxWeight())
return ior_overweight;
if (item->getStackBulk() + getInventoryBulk() > getMaxBulk())
return ior_overbulk;
}
// 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();
// remove any item referenced here
removeItem(slot);
// insert and link the new item
_Items[slot] = item;
item->setRefInventory(CInventoryPtr(this), slot);
updateWeightAndBulk(item, item->getStackSize());
--_FreeSlotCount;
// callbacks for derived class
onItemChanged(slot, INVENTORIES::itc_inserted);
// callback views
/*TViewCont::iterator first(_InventoryViews.begin()), last(_InventoryViews.end());
for (; first != last; ++first)
{
CInventoryViewPtr view = *first;
view->onItemChanged(slot, itc_inserted);
}*/
return ior_ok;
}
示例12: setItemParam
void CMissionItem::setItemParam(CGameItemPtr item)
{
const CStaticRolemasterPhrase * phrase = NULL;
if ( _SPhraseId != CSheetId::Unknown )
{
phrase = CSheets::getSRolemasterPhrase(_SPhraseId);
if (phrase == NULL)
{
nlwarning("<CMissionItem setItemParam> Invalid sheet %s",_SPhraseId.toString().c_str());
return;
}
}
// if ( item->getSheetId() == CSheetId("stack.sitem") )
// {
// const uint size = item->getChildren().size();
// for (uint i = 0; i < size; i++ )
// {
// if ( item->getChildren()[i] != NULL )
// {
// if( phrase != 0 )
// item->applyEnchantment(phrase->Bricks);
// item->getChildren()[i]->setCraftParameters(_Params);
// if ( _NoDrop )
// {
// item->getChildren()[i]->destroyable(false);
// item->getChildren()[i]->dropable(false);
// }
// }
// }
// }
// else
{
if( phrase != 0 )
item->applyEnchantment(phrase->Bricks);
item->setCraftParameters(_Params);
if (_NoDrop)
{
item->destroyable(false);
item->dropable(false);
}
}
}// CMissionItem::setItemParam
示例13: isExchangeAllowed
bool CInterShardExchangeValidator::isExchangeAllowed(const CGameItemPtr& theItem, TShardId shardId0, TShardId shardId1) const
{
// allow all exchanges between characters from the same shard
if (shardId0==shardId1) return true;
// allow all exchanges of plot items
if ( theItem->getStaticForm()->Family == ITEMFAMILY::SCROLL_R2 ) return true;
// determine the maximum level for items exchanged between the 2 shards
TLevelCap levelLimit= std::min(getLevelCap(shardId0),getLevelCap(shardId1));
// if item is too high level then refuse
if (theItem->quality()>levelLimit) return false;
// if item is flagged as non-shardExchangeable then refuse
if (theItem->getStaticForm()->ShardExchangeable==false) return false;
// if item is named (and not a plot item) then refuse
if (!theItem->getPhraseId().empty()) return false;
// we've found no reason to refuse so return true
return true;
}
示例14: getMaxSlot
// ****************************************************************************
void CInventoryBase::dumpInventory(NLMISC::CLog & log, bool dumpItems) const
{
// inventory description
log.displayNL("Inventory: %s", INVENTORIES::toString(_InventoryId).c_str());
log.displayRawNL("Slots: max=%u, count=%u, free=%u", getMaxSlot(), _SlotCount, _FreeSlotCount);
log.displayRawNL("Weight: %u", _InventoryWeight);
log.displayRawNL("Bulk: %u", _InventoryBulk);
log.displayRawNL("Nb views: %u", _InventoryViews.size());
log.displayNL("(DEBUG) _Items.size() = %u", _Items.size());
if (dumpItems)
{
for (uint i = 0; i < _Items.size(); i++)
{
CGameItemPtr item = _Items[i];
if (item == NULL)
continue;
// short display of the item description
log.displayRawNL( "%u: ", i );
item->displayInLog( log );
}
}
}
示例15: H_AUTO
// ****************************************************************************
void CCharacterInvView::onItemChanged(uint32 slot, INVENTORIES::TItemChangeFlags changeFlags)
{
H_AUTO(OnItemChange);
if ( changeFlags.checkEnumValue(INVENTORIES::itc_inserted)
|| changeFlags.checkEnumValue(INVENTORIES::itc_lock_state)
|| changeFlags.checkEnumValue(INVENTORIES::itc_enchant)
|| changeFlags.checkEnumValue(INVENTORIES::itc_worned)
)
{
const CGameItemPtr item = getInventory()->getItem(slot);
nlassert(item != NULL);
updateClientSlot(slot, item);
}
else if (changeFlags.checkEnumValue(INVENTORIES::itc_removed))
{
// Cleanup the item in player inventory
updateClientSlot(slot, NULL);
}
else if (changeFlags.checkEnumValue(INVENTORIES::itc_hp))
{
const CGameItemPtr item = getInventory()->getItem(slot);
nlassert(item != NULL);
// get new worn state
ITEM_WORN_STATE::TItemWornState wornState = item->getItemWornState();
item->computeItemWornState();
// if states differs send a message
if (wornState != item->getItemWornState())
{
if (getCharacter() != NULL)
{
string msgName = ITEM_WORN_STATE::getMessageForState(item->getItemWornState());
if ( !msgName.empty())
{
SM_STATIC_PARAMS_1(params, STRING_MANAGER::item);
params[0].SheetId = item->getSheetId();
CCharacter::sendDynamicSystemMessage( getCharacter()->getEntityRowId(), msgName, params);
}
}
}
// send slot update to the client
updateClientSlot(slot, item);
}
if (changeFlags.checkEnumValue(INVENTORIES::itc_info_version))
{
getCharacter()->_InventoryUpdater.syncInfoVersion(getInventory()->getInventoryId(), slot);
}
}