Changed: #1304: Implementation of the "guild" parameter for the "recv_item" action
This commit is contained in:
parent
bc4ac5dac6
commit
42adc7f469
3 changed files with 220 additions and 114 deletions
|
@ -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();
|
item.deleteItem();
|
||||||
|
return res == CInventoryBase::ior_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -235,7 +235,7 @@ public:
|
||||||
return _Inventory->getItem(slot);
|
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!)
|
/// 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)
|
/// return the inventory (const)
|
||||||
const NLMISC::CSmartPtr<CGuildInventory>& getInventory() const { return _Inventory; }
|
const NLMISC::CSmartPtr<CGuildInventory>& getInventory() const { return _Inventory; }
|
||||||
|
|
|
@ -617,7 +617,7 @@ class CMissionActionRecvItem : 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());
|
||||||
|
@ -628,141 +628,245 @@ class CMissionActionRecvItem : public IMissionAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the case we want to give the item to the guild
|
||||||
// check free room space in inventory
|
if (_Guild)
|
||||||
// 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)
|
|
||||||
{
|
{
|
||||||
neededSlotCount = (sint16) ceil( (float)_Quantity / itemTmp->getMaxStackSize() );
|
if (entities.size() == 0)
|
||||||
neededBulk = _Quantity * itemTmp->getStackBulk();
|
return;
|
||||||
itemTmp.deleteItem();
|
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
LOGMISSIONACTION("can't get static item from sheet " + sheet.toString());
|
// check free room space in inventory
|
||||||
return;
|
// 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();
|
||||||
bool fail = true;
|
CGameItemPtr itemTmp = GameItemManager.createItem(sheet, _Quality, true, true);
|
||||||
for ( uint i = 0; i < entities.size(); i++ )
|
if (itemTmp != NULL)
|
||||||
{
|
|
||||||
CCharacter * user = PlayerManager.getChar( entities[i] );
|
|
||||||
if ( user )
|
|
||||||
{
|
{
|
||||||
CInventoryPtr invBag = user->getInventory( INVENTORIES::bag );
|
neededSlotCount = (sint16) ceil( (float)_Quantity / itemTmp->getMaxStackSize() );
|
||||||
sint16 freeSlotcount = invBag->getFreeSlotCount();
|
neededBulk = _Quantity * itemTmp->getStackBulk();
|
||||||
uint32 maxBulk = invBag->getMaxBulk();
|
itemTmp.deleteItem();
|
||||||
|
|
||||||
CInventoryPtr invTemp = user->getInventory( INVENTORIES::temporary );
|
|
||||||
if( invTemp )
|
|
||||||
{
|
|
||||||
freeSlotcount -= invTemp->getUsedSlotCount();
|
|
||||||
maxBulk -= invTemp->getInventoryBulk();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( (neededSlotCount <= freeSlotcount) && ( neededBulk + invBag->getInventoryBulk() <= maxBulk) )
|
|
||||||
{
|
|
||||||
fail = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
if( fail )
|
|
||||||
{
|
|
||||||
CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( instance->getTemplateId() );
|
|
||||||
if ( templ )
|
|
||||||
{
|
{
|
||||||
if ( templ->Tags.FailIfInventoryIsFull )
|
LOGMISSIONACTION("can't get static item from sheet " + sheet.toString());
|
||||||
{
|
return;
|
||||||
instance->setProcessingState(CMission::ActionFailed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for ( uint i = 0; i < entities.size(); i++ )
|
bool fail = true;
|
||||||
{
|
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);
|
CCharacter * user = PlayerManager.getChar( entities[i] );
|
||||||
if ( _SheetId != CSheetId::Unknown )
|
if ( user )
|
||||||
{
|
{
|
||||||
const CStaticItem * form = CSheets::getForm( _SheetId );
|
CInventoryPtr invBag = user->getInventory( INVENTORIES::bag );
|
||||||
if ( !form )
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (form->Family != ITEMFAMILY::MISSION_ITEM && !user->enterTempInventoryMode(TEMP_INV_MODE::MissionReward))
|
}
|
||||||
continue;
|
}
|
||||||
|
|
||||||
uint quantity = _Quantity;
|
for ( uint i = 0; i < entities.size(); i++ )
|
||||||
while (quantity > 0)
|
{
|
||||||
|
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);
|
const CStaticItem * form = CSheets::getForm( _SheetId );
|
||||||
if (item == NULL)
|
if ( !form )
|
||||||
break;
|
|
||||||
const uint32 stackSize = item->getStackSize();
|
|
||||||
|
|
||||||
if( form->Family != ITEMFAMILY::MISSION_ITEM )
|
|
||||||
{
|
{
|
||||||
|
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))
|
if (!user->addItemToInventory(INVENTORIES::temporary, item))
|
||||||
{
|
{
|
||||||
item.deleteItem();
|
item.deleteItem();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
// from here item maybe NULL (because of autostack)
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!user->addItemToInventory(INVENTORIES::bag, item))
|
|
||||||
{
|
|
||||||
item.deleteItem();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue