//----------------------------------------------------------------------------- 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; }
//----------------------------------------------- // createInGameItem //----------------------------------------------- CGameItemPtr CGameItemManager::createInGameItem( uint16 quality, uint32 quantity, const NLMISC::CSheetId &sheet, const CEntityId &creatorId , const std::string * phraseId) { H_AUTO(GIM_createInGameItem); static const CSheetId preorderSheetId("pre_order.sitem"); if ( quantity == 0 || quality ==0 ) return NULL; // static const CSheetId idSheetStack("stack.sitem"); const CStaticItem* form = CSheets::getForm( sheet ); if (!form) { nlwarning("<CCharacter::createInGameItem> Cannot find form of item %s", sheet.toString().c_str()); return NULL; } CGameItemPtr item; CGameItemPtr sellingItem; // if item can be sold, get it in the sold items list if ( form->Family != ITEMFAMILY::RAW_MATERIAL && form->Family != ITEMFAMILY::HARVEST_TOOL && form->Family != ITEMFAMILY::CRAFTING_TOOL && form->Family != ITEMFAMILY::CRYSTALLIZED_SPELL && form->Family != ITEMFAMILY::ITEM_SAP_RECHARGE && form->Family != ITEMFAMILY::FOOD ) { vector< CGameItemPtr >::const_iterator it; const vector< CGameItemPtr >::const_iterator itEnd = CStaticItems::getStaticItems().end(); for( it = CStaticItems::getStaticItems().begin(); it != itEnd; ++it ) { if( (*it)->getSheetId() == sheet ) { sellingItem = *it; break; } } } switch( form->Family ) { case ITEMFAMILY::CRAFTING_TOOL: case ITEMFAMILY::HARVEST_TOOL: case ITEMFAMILY::RAW_MATERIAL: case ITEMFAMILY::TELEPORT: case ITEMFAMILY::CRYSTALLIZED_SPELL: case ITEMFAMILY::ITEM_SAP_RECHARGE: case ITEMFAMILY::MISSION_ITEM: case ITEMFAMILY::PET_ANIMAL_TICKET: case ITEMFAMILY::HANDLED_ITEM: case ITEMFAMILY::CONSUMABLE: case ITEMFAMILY::XP_CATALYSER: case ITEMFAMILY::SCROLL: case ITEMFAMILY::FOOD: case ITEMFAMILY::SCROLL_R2: case ITEMFAMILY::GENERIC_ITEM: { item = GameItemManager.createItem( const_cast< CSheetId& > ( sheet ), quality, true, true, creatorId); } break; default: { if( sellingItem != NULL ) { item = sellingItem->getItemCopy(); item->quality( quality ); if ( phraseId ) item->setPhraseId(*phraseId); } else if (sheet == preorderSheetId) { item = GameItemManager.createItem(sheet, quality, true, form->DropOrSell, creatorId); } } if( item == NULL) { nlwarning("<CCharacter::createInGameItem> Error while creating item : NULL pointer"); return NULL; } } quantity = min(quantity, item->getMaxStackSize()); item->setStackSize(quantity); return item; } // createInGameItem //