Beispiel #1
0
//------------------------------------------------------------------------
void CItem::DoSwitchAccessory(const ItemString &inAccessory)
{
	const ItemString &accessory = (inAccessory == g_pItemStrings->SCARSleepAmmo) ? g_pItemStrings->SCARTagAmmo : inAccessory;

	SAccessoryParams *params = GetAccessoryParams(accessory);
	bool attached = false;

	if(params)
	{
		ItemString replacing;

		for(TAccessoryMap::iterator it = m_accessories.begin(); it != m_accessories.end(); it++)
		{
			SAccessoryParams *p = GetAccessoryParams(it->first);

			if(p && p->attach_helper == params->attach_helper)
			{
				replacing = it->first;
				attached = true;
			}
		}

		if(attached)
		{
			AttachAccessory(replacing, false, true, true);

			if(accessory != replacing)
				AttachAccessory(accessory, true, true, true);
		}
	}

	if(!attached)
		AttachAccessory(accessory, true, true, true);
}
Beispiel #2
0
//------------------------------------------------------------------------
void CItem::InitialSetup()
{
	if(!(GetISystem()->IsSerializingFile() && GetGameObject()->IsJustExchanging()))
	{
		if(IsServer())
		{
			TInitialSetupMap::iterator initSetupIter = m_initialSetup.find(CONST_TEMPITEM_STRING(m_currentInitialSetup.c_str()));

			if(initSetupIter != m_initialSetup.end())
			{
				const TInitialSetup &initSetup = initSetupIter->second;
				TInitialSetup::const_iterator it = initSetup.begin();
				TInitialSetup::const_iterator itEnd = initSetup.end();

				for(; it != itEnd; ++it)
				{
					//if (!IsClient())
					//	AddAccessory(*it);
					//else
					AttachAccessory(*it, true, true, true, true);
				}
			}
		}
	}
}
//------------------------------------------------------------------------
IMPLEMENT_RMI(CItem, SvRequestDetachAccessory)
{
	if (IInventory *pInventory=GetActorInventory(GetOwnerActor()))
	{
		char accessoryName[129] = {0};
		bool result = g_pGame->GetIGameFramework()->GetNetworkSafeClassName(accessoryName, 128, params.accessoryClassId);

#if !defined(_RELEASE)
		if(!result)
		{
			char errorMsg[256];
			sprintf(errorMsg, "CItem::SvRequestDetachAccessory failed to find network safe class name for id %d", params.accessoryClassId);
			CRY_ASSERT_MESSAGE(result, errorMsg);
		}
#endif

		if (accessoryName[0] != '\0')
		{
			AttachAccessory(accessoryName, false, true, true);
			GetGameObject()->InvokeRMI(ClDetachAccessory(), params, eRMI_ToRemoteClients);

			return true;
		}
	}
	return true; 
}
//------------------------------------------------------------------------
IMPLEMENT_RMI(CItem, ClDetachAccessory)
{
	char accessoryName[129] = {0};
	bool result = g_pGame->GetIGameFramework()->GetNetworkSafeClassName(accessoryName, 128, params.accessoryClassId);

#if !defined(_RELEASE)
	if(!result)
	{
		char errorMsg[256];
		sprintf(errorMsg, "CItem::ClDetachAccessory failed to find network safe class name for id %d", params.accessoryClassId);
		CRY_ASSERT_MESSAGE(result, errorMsg);
	}
#endif

	AttachAccessory(accessoryName, false, true, true);
	return true;
}