From 0491eee97debdb3822cf0034733e567980ab18f9 Mon Sep 17 00:00:00 2001 From: Fabien_HENON Date: Wed, 20 Jul 2011 20:33:52 +0200 Subject: [PATCH] Changed: #1304: Implementation of the "guild" parameter for the "recv_item" action --- .../guild_manager/guild.cpp | 6 +- .../guild_manager/guild.h | 2 +- .../mission_manager/mission_action.cpp | 326 ++++++++++++------ 3 files changed, 220 insertions(+), 114 deletions(-) diff --git a/code/ryzom/server/src/entities_game_service/guild_manager/guild.cpp b/code/ryzom/server/src/entities_game_service/guild_manager/guild.cpp index 3a05ef309..df9082c6b 100644 --- a/code/ryzom/server/src/entities_game_service/guild_manager/guild.cpp +++ b/code/ryzom/server/src/entities_game_service/guild_manager/guild.cpp @@ -904,10 +904,12 @@ bool CGuild::canAccessToGuildInventory( CCharacter * user ) } //---------------------------------------------------------------------------- -void CGuild::putItem( CGameItemPtr item ) +bool CGuild::putItem( CGameItemPtr item ) { - if (_Inventory->insertItem(item, INVENTORIES::INSERT_IN_FIRST_FREE_SLOT, true) != CInventoryBase::ior_ok) + CInventoryBase::TInventoryOpResult res = _Inventory->insertItem(item, INVENTORIES::INSERT_IN_FIRST_FREE_SLOT, true); + if (res != CInventoryBase::ior_ok) item.deleteItem(); + return res == CInventoryBase::ior_ok; } //---------------------------------------------------------------------------- diff --git a/code/ryzom/server/src/entities_game_service/guild_manager/guild.h b/code/ryzom/server/src/entities_game_service/guild_manager/guild.h index 64378b717..449debe53 100644 --- a/code/ryzom/server/src/entities_game_service/guild_manager/guild.h +++ b/code/ryzom/server/src/entities_game_service/guild_manager/guild.h @@ -235,7 +235,7 @@ public: return _Inventory->getItem(slot); } /// add an item in the guild inventory (item can be deleted if not inserted : do not use it anymore in any case!) - void putItem( CGameItemPtr item ); + bool putItem( CGameItemPtr item ); /// return the inventory (const) const NLMISC::CSmartPtr& getInventory() const { return _Inventory; } diff --git a/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp b/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp index a73e2d714..61646a74b 100644 --- a/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp +++ b/code/ryzom/server/src/entities_game_service/mission_manager/mission_action.cpp @@ -617,7 +617,7 @@ class CMissionActionRecvItem : public IMissionAction } } } - else if ( !_Group ) + else if ( !_Group && !_Guild) { CCharacter * user = PlayerManager.getChar( entities[0] ); CTeam * team = TeamManager.getRealTeam(user->getTeamId()); @@ -628,141 +628,245 @@ class CMissionActionRecvItem : public IMissionAction } } - - // check free room space in inventory - // NB : in case of group, fail happens only if none in the group have enough free space - sint16 neededSlotCount = 0; - uint32 neededBulk = 0; - CSheetId sheet = ( _SheetId != CSheetId::Unknown )?_SheetId:_Item.getSheetId(); - CGameItemPtr itemTmp = GameItemManager.createItem(sheet, _Quality, true, true); - if (itemTmp != NULL) + // If the case we want to give the item to the guild + if (_Guild) { - neededSlotCount = (sint16) ceil( (float)_Quantity / itemTmp->getMaxStackSize() ); - neededBulk = _Quantity * itemTmp->getStackBulk(); - itemTmp.deleteItem(); + if (entities.size() == 0) + return; + + CCharacter * user = PlayerManager.getChar( entities[0] ); + if (!user) + { + LOGMISSIONACTION("recv_fame : Invalid user"); + return; + } + + CGuild * guild = CGuildManager::getInstance()->getGuildFromId(user->getGuildId()); + if (!guild) + { + LOGMISSIONACTION("recv_fame : Invalid guild id '" + NLMISC::toString(user->getGuildId()) + "'"); + return; + } + + SM_STATIC_PARAMS_3(params, STRING_MANAGER::item, STRING_MANAGER::integer, STRING_MANAGER::integer); + if ( _SheetId != CSheetId::Unknown ) + { + const CStaticItem * form = CSheets::getForm( _SheetId ); + if ( !form ) + { + LOGMISSIONACTION("sheetId '" + _SheetId.toString() + "' is unknown"); + return; + } + if (form->Family != ITEMFAMILY::MISSION_ITEM) + return; + + uint quantity = _Quantity; + while (quantity > 0) + { + CGameItemPtr item = user->createItem(_Quality, quantity, _SheetId); + if (item == NULL) + break; + const uint32 stackSize = item->getStackSize(); + + if (!guild->putItem(item)) + { + CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( instance->getTemplateId() ); + if ( templ ) + { + if ( templ->Tags.FailIfInventoryIsFull ) + { + instance->setProcessingState(CMission::ActionFailed); + return; + } + } + } + // from here item maybe NULL (because of autostack) + + quantity -= stackSize; + } + params[2].Int = _Quality; + } + else + { + const CStaticItem * form = CSheets::getForm( _Item.getSheetId() ); + if ( !form ) + { + LOGMISSIONACTION("sheetId '" + _Item.getSheetId().toString() + "' is unknown"); + return; + } + uint quantity = _Quantity; + while (quantity > 0) + { + CGameItemPtr item = _Item.createItem(quantity); + if (item == NULL) + break; + + const uint32 stackSize = item->getStackSize(); + if (!guild->putItem(item)) + { + CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( instance->getTemplateId() ); + if ( templ ) + { + if ( templ->Tags.FailIfInventoryIsFull ) + { + instance->setProcessingState(CMission::ActionFailed); + return; + } + } + } + // from here item maybe NULL (because of autostack) + + quantity -= stackSize; + } + params[2].Int = _Item.getQuality(); + } + + params[0].SheetId = _SheetId; + params[1].Int = _Quantity; + + for ( uint i = 0; i < entities.size(); i++ ) + { + CCharacter * user = PlayerManager.getChar( entities[i] ); + if ( user ) + PHRASE_UTILITIES::sendDynamicSystemMessage(user->getEntityRowId(),"MIS_GUILD_RECV_ITEM", params); + } } else { - LOGMISSIONACTION("can't get static item from sheet " + sheet.toString()); - return; - } - - - bool fail = true; - for ( uint i = 0; i < entities.size(); i++ ) - { - CCharacter * user = PlayerManager.getChar( entities[i] ); - if ( user ) + // check free room space in inventory + // NB : in case of group, fail happens only if none in the group have enough free space + sint16 neededSlotCount = 0; + uint32 neededBulk = 0; + CSheetId sheet = ( _SheetId != CSheetId::Unknown )?_SheetId:_Item.getSheetId(); + CGameItemPtr itemTmp = GameItemManager.createItem(sheet, _Quality, true, true); + if (itemTmp != NULL) { - CInventoryPtr invBag = user->getInventory( INVENTORIES::bag ); - sint16 freeSlotcount = invBag->getFreeSlotCount(); - uint32 maxBulk = invBag->getMaxBulk(); - - CInventoryPtr invTemp = user->getInventory( INVENTORIES::temporary ); - if( invTemp ) - { - freeSlotcount -= invTemp->getUsedSlotCount(); - maxBulk -= invTemp->getInventoryBulk(); - } - - if( (neededSlotCount <= freeSlotcount) && ( neededBulk + invBag->getInventoryBulk() <= maxBulk) ) - { - fail = false; - break; - } + neededSlotCount = (sint16) ceil( (float)_Quantity / itemTmp->getMaxStackSize() ); + neededBulk = _Quantity * itemTmp->getStackBulk(); + itemTmp.deleteItem(); } - } - if( fail ) - { - CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( instance->getTemplateId() ); - if ( templ ) + else { - if ( templ->Tags.FailIfInventoryIsFull ) - { - instance->setProcessingState(CMission::ActionFailed); - return; - } + LOGMISSIONACTION("can't get static item from sheet " + sheet.toString()); + return; } - } - for ( uint i = 0; i < entities.size(); i++ ) - { - CCharacter * user = PlayerManager.getChar( entities[i] ); - if ( user ) + bool fail = true; + for ( uint i = 0; i < entities.size(); i++ ) { - SM_STATIC_PARAMS_3(params, STRING_MANAGER::item, STRING_MANAGER::integer, STRING_MANAGER::integer); - if ( _SheetId != CSheetId::Unknown ) + CCharacter * user = PlayerManager.getChar( entities[i] ); + if ( user ) { - const CStaticItem * form = CSheets::getForm( _SheetId ); - if ( !form ) + CInventoryPtr invBag = user->getInventory( INVENTORIES::bag ); + sint16 freeSlotcount = invBag->getFreeSlotCount(); + uint32 maxBulk = invBag->getMaxBulk(); + + CInventoryPtr invTemp = user->getInventory( INVENTORIES::temporary ); + if( invTemp ) { - LOGMISSIONACTION("sheetId '" + _SheetId.toString() + "' is unknown"); + freeSlotcount -= invTemp->getUsedSlotCount(); + maxBulk -= invTemp->getInventoryBulk(); + } + + if( (neededSlotCount <= freeSlotcount) && ( neededBulk + invBag->getInventoryBulk() <= maxBulk) ) + { + fail = false; + break; + } + } + } + if( fail ) + { + CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( instance->getTemplateId() ); + if ( templ ) + { + if ( templ->Tags.FailIfInventoryIsFull ) + { + instance->setProcessingState(CMission::ActionFailed); return; } - if (form->Family != ITEMFAMILY::MISSION_ITEM && !user->enterTempInventoryMode(TEMP_INV_MODE::MissionReward)) - continue; + } + } - uint quantity = _Quantity; - while (quantity > 0) + for ( uint i = 0; i < entities.size(); i++ ) + { + CCharacter * user = PlayerManager.getChar( entities[i] ); + if ( user ) + { + SM_STATIC_PARAMS_3(params, STRING_MANAGER::item, STRING_MANAGER::integer, STRING_MANAGER::integer); + if ( _SheetId != CSheetId::Unknown ) { - CGameItemPtr item = user->createItem(_Quality, quantity, _SheetId); - if (item == NULL) - break; - const uint32 stackSize = item->getStackSize(); - - if( form->Family != ITEMFAMILY::MISSION_ITEM ) + const CStaticItem * form = CSheets::getForm( _SheetId ); + if ( !form ) { + LOGMISSIONACTION("sheetId '" + _SheetId.toString() + "' is unknown"); + return; + } + if (form->Family != ITEMFAMILY::MISSION_ITEM && !user->enterTempInventoryMode(TEMP_INV_MODE::MissionReward)) + continue; + + uint quantity = _Quantity; + while (quantity > 0) + { + CGameItemPtr item = user->createItem(_Quality, quantity, _SheetId); + if (item == NULL) + break; + const uint32 stackSize = item->getStackSize(); + + if( form->Family != ITEMFAMILY::MISSION_ITEM ) + { + if (!user->addItemToInventory(INVENTORIES::temporary, item)) + { + item.deleteItem(); + break; + } + } + else + { + if (!user->addItemToInventory(INVENTORIES::bag, item)) + { + item.deleteItem(); + break; + } + } + // from here item maybe NULL (because of autostack) + + quantity -= stackSize; + } + params[2].Int = _Quality; + } + else + { + const CStaticItem * form = CSheets::getForm( _Item.getSheetId() ); + if ( !form ) + { + LOGMISSIONACTION("sheetId '" + _Item.getSheetId().toString() + "' is unknown"); + return; + } + uint quantity = _Quantity; + while (quantity > 0) + { + CGameItemPtr item = _Item.createItem(quantity); + if (item == NULL) + break; + + const uint32 stackSize = item->getStackSize(); if (!user->addItemToInventory(INVENTORIES::temporary, item)) { item.deleteItem(); break; } - } - else - { - if (!user->addItemToInventory(INVENTORIES::bag, item)) - { - item.deleteItem(); - break; - } - } - // from here item maybe NULL (because of autostack) + // from here item maybe NULL (because of autostack) - quantity -= stackSize; + quantity -= stackSize; + } + params[2].Int = _Item.getQuality(); } - params[2].Int = _Quality; + + params[0].SheetId = _SheetId; + params[1].Int = _Quantity; + PHRASE_UTILITIES::sendDynamicSystemMessage(user->getEntityRowId(),"MIS_RECV_ITEM", params); } - else - { - const CStaticItem * form = CSheets::getForm( _Item.getSheetId() ); - if ( !form ) - { - LOGMISSIONACTION("sheetId '" + _Item.getSheetId().toString() + "' is unknown"); - return; - } - uint quantity = _Quantity; - while (quantity > 0) - { - CGameItemPtr item = _Item.createItem(quantity); - if (item == NULL) - break; - - const uint32 stackSize = item->getStackSize(); - if (!user->addItemToInventory(INVENTORIES::temporary, item)) - { - item.deleteItem(); - break; - } - // from here item maybe NULL (because of autostack) - - quantity -= stackSize; - } - params[2].Int = _Item.getQuality(); - } - - params[0].SheetId = _SheetId; - params[1].Int = _Quantity; - PHRASE_UTILITIES::sendDynamicSystemMessage(user->getEntityRowId(),"MIS_RECV_ITEM", params); } } };