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

--HG--
branch : gsoc2011-guildmissions
hg/feature/gsoc2012-fabien
Fabien_HENON 14 years ago
parent 5ac224b5af
commit 757f393db1

@ -975,7 +975,7 @@ class CMissionActionRecvNamedItem : public IMissionAction
} }
} }
} }
else if ( !_Group ) else if ( !_Group && !_Guild)
{ {
CCharacter * user = PlayerManager.getChar( entities[0] ); CCharacter * user = PlayerManager.getChar( entities[0] );
CTeam * team = TeamManager.getRealTeam(user->getTeamId()); CTeam * team = TeamManager.getRealTeam(user->getTeamId());
@ -986,41 +986,34 @@ class CMissionActionRecvNamedItem : public IMissionAction
} }
} }
// check free room space in inventory // If the case we want to give the item to the guild
// NB : in case of group, fail happens only if noone in the group have enough free space if (_Guild)
CGameItemPtr itemTmp = CNamedItems::getInstance().createNamedItem(_NamedItem, _Quantity);
if( itemTmp != NULL )
{ {
sint16 neededSlotCount = (sint16) ceil( (float)_Quantity / itemTmp->getMaxStackSize() ); if (entities.size() == 0)
uint32 neededBulk = _Quantity * itemTmp->getStackBulk(); return;
itemTmp.deleteItem();
CCharacter * user = PlayerManager.getChar( entities[0] );
bool fail = true; if (!user)
for ( uint i = 0; i < entities.size(); i++ )
{ {
CCharacter * user = PlayerManager.getChar( entities[i] ); LOGMISSIONACTION("recv_fame : Invalid user");
if ( user ) return;
{ }
CInventoryPtr invBag = user->getInventory( INVENTORIES::bag );
sint16 freeSlotcount = invBag->getFreeSlotCount();
uint32 maxBulk = invBag->getMaxBulk();
CInventoryPtr invTemp = user->getInventory( INVENTORIES::temporary ); CGuild * guild = CGuildManager::getInstance()->getGuildFromId(user->getGuildId());
if( invTemp ) if (!guild)
{ {
freeSlotcount -= invTemp->getUsedSlotCount(); LOGMISSIONACTION("recv_fame : Invalid guild id '" + NLMISC::toString(user->getGuildId()) + "'");
maxBulk -= invTemp->getInventoryBulk(); return;
}
if( (neededSlotCount <= freeSlotcount) && ( neededBulk + invBag->getInventoryBulk() <= maxBulk) )
{
fail = false;
break;
}
}
} }
if( fail )
// add the item to inventory
CGameItemPtr item = CNamedItems::getInstance().createNamedItem(_NamedItem, _Quantity);
if (item == NULL)
{
LOGMISSIONACTION("named item '" + _NamedItem + "' is unknown");
return;
}
if (!guild->putItem(item))
{ {
CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( instance->getTemplateId() ); CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( instance->getTemplateId() );
if ( templ ) if ( templ )
@ -1032,39 +1025,103 @@ class CMissionActionRecvNamedItem : public IMissionAction
} }
} }
} }
else
{
for ( uint i = 0; i < entities.size(); i++ )
{
CCharacter * user = PlayerManager.getChar( entities[i] );
if ( user )
{
SM_STATIC_PARAMS_2(params, STRING_MANAGER::dyn_string_id, STRING_MANAGER::integer);
params[0].StringId = item->sendNameId(user);
params[1].Int = _Quantity;
PHRASE_UTILITIES::sendDynamicSystemMessage(user->getEntityRowId(),"MIS_GUILD_RECV_NAMED_ITEM", params);
}
}
}
} }
else else
{ {
LOGMISSIONACTION("named item '" + _NamedItem + "' is unknown"); // check free room space in inventory
return; // NB : in case of group, fail happens only if noone in the group have enough free space
} CGameItemPtr itemTmp = CNamedItems::getInstance().createNamedItem(_NamedItem, _Quantity);
if( itemTmp != NULL )
// apply the action to all entities
for ( uint i = 0; i < entities.size(); i++ )
{
CCharacter * user = PlayerManager.getChar( entities[i] );
if ( user )
{ {
if (!user->enterTempInventoryMode(TEMP_INV_MODE::MissionReward)) sint16 neededSlotCount = (sint16) ceil( (float)_Quantity / itemTmp->getMaxStackSize() );
continue; uint32 neededBulk = _Quantity * itemTmp->getStackBulk();
itemTmp.deleteItem();
// add the item to inventory
CGameItemPtr item = CNamedItems::getInstance().createNamedItem(_NamedItem, _Quantity); bool fail = true;
if (item == NULL) for ( uint i = 0; i < entities.size(); i++ )
{ {
LOGMISSIONACTION("named item '" + _NamedItem + "' is unknown"); CCharacter * user = PlayerManager.getChar( entities[i] );
return; if ( user )
{
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;
}
}
} }
if(!user->addItemToInventory(INVENTORIES::temporary, item)) if( fail )
{ {
item.deleteItem(); CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( instance->getTemplateId() );
if ( templ )
{
if ( templ->Tags.FailIfInventoryIsFull )
{
instance->setProcessingState(CMission::ActionFailed);
return;
}
}
} }
else }
else
{
LOGMISSIONACTION("named item '" + _NamedItem + "' is unknown");
return;
}
// apply the action to all entities
for ( uint i = 0; i < entities.size(); i++ )
{
CCharacter * user = PlayerManager.getChar( entities[i] );
if ( user )
{ {
SM_STATIC_PARAMS_2(params, STRING_MANAGER::dyn_string_id, STRING_MANAGER::integer); if (!user->enterTempInventoryMode(TEMP_INV_MODE::MissionReward))
params[0].StringId = item->sendNameId(user); continue;
params[1].Int = _Quantity;
PHRASE_UTILITIES::sendDynamicSystemMessage(user->getEntityRowId(),"MIS_RECV_NAMED_ITEM", params); // add the item to inventory
CGameItemPtr item = CNamedItems::getInstance().createNamedItem(_NamedItem, _Quantity);
if (item == NULL)
{
LOGMISSIONACTION("named item '" + _NamedItem + "' is unknown");
return;
}
if(!user->addItemToInventory(INVENTORIES::temporary, item))
{
item.deleteItem();
}
else
{
SM_STATIC_PARAMS_2(params, STRING_MANAGER::dyn_string_id, STRING_MANAGER::integer);
params[0].StringId = item->sendNameId(user);
params[1].Int = _Quantity;
PHRASE_UTILITIES::sendDynamicSystemMessage(user->getEntityRowId(),"MIS_RECV_NAMED_ITEM", params);
}
} }
} }
} }

Loading…
Cancel
Save