Changed: #1304: Implementation of the "guild" parameter for the "recv_item" action

--HG--
branch : gsoc2011-guildmissions
This commit is contained in:
Fabien_HENON 2011-07-20 20:33:52 +02:00
parent cb6b4ac917
commit 5ac224b5af
3 changed files with 220 additions and 114 deletions

View file

@ -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;
}
//----------------------------------------------------------------------------

View file

@ -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<CGuildInventory>& getInventory() const { return _Inventory; }

View file

@ -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,7 +628,111 @@ class CMissionActionRecvItem : public IMissionAction
}
}
// If the case we want to give the item to the guild
if (_Guild)
{
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
{
// 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;
@ -647,7 +751,6 @@ class CMissionActionRecvItem : public IMissionAction
return;
}
bool fail = true;
for ( uint i = 0; i < entities.size(); i++ )
{
@ -765,6 +868,7 @@ class CMissionActionRecvItem : public IMissionAction
PHRASE_UTILITIES::sendDynamicSystemMessage(user->getEntityRowId(),"MIS_RECV_ITEM", params);
}
}
}
};
CMissionItem _Item;
uint16 _Quality;