void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		if (event == eFE_Activate && IsPortActive(pActInfo,0))
		{
			IGameFramework * pGameFramework = gEnv->pGame->GetIGameFramework();

			IActor* pActor = GetInputActor( pActInfo );
			if (!pActor || pActor!=gEnv->pGame->GetIGameFramework()->GetClientActor())  // to avoid some extra RMIs and object creation. Tho, this causes the node to not work properly if it is used with non players entities. (which was never intended anyway)
				return;
						
			IInventory *pInventory = pActor->GetInventory();
      if (!pInventory)
        return;

      const string& itemClass = GetPortString( pActInfo, 1 );
			IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( itemClass.c_str() );
      EntityId id = pInventory->GetItemByClass( pClass );
      
      if (id!=0)
      {
        pInventory->RMIReqToServer_RemoveItem( itemClass.c_str() );
        // TODO: instant output activation, with delayed effective change in the inventory, it potentially could cause problems in rare situations
        ActivateOutput(pActInfo,0,true);
      }
      else
        ActivateOutput(pActInfo,0,true);
		}
	}
Exemple #2
0
//------------------------------------------------------------------------
void CWeaponSystem::RefGun(IConsoleCmdArgs *args)
{
	IGameFramework* pGF = gEnv->pGame->GetIGameFramework();  
	IItemSystem* pItemSystem = pGF->GetIItemSystem();

	IActor* pActor = pGF->GetClientActor();
	if (!pActor || !pActor->IsPlayer())
		return;

	IInventory *pInventory = pActor->GetInventory();
	if (!pInventory)
		return;

	// give & select the refgun 
	EntityId itemId = pInventory->GetItemByClass(CItem::sRefWeaponClass);
	if (0 == itemId)        
	{
		// if actor doesn't have it, only give it in editor
		if (!GetISystem()->IsEditor())
			return;

		itemId = pItemSystem->GiveItem(pActor, CItem::sRefWeaponClass->GetName(), false, true, true);
	}
	pItemSystem->SetActorItem(pActor, itemId, true);   

}
  void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
  {
    IGameFramework* pGF = gEnv->pGame->GetIGameFramework();
  
    if (event == eFE_Activate && IsPortActive(pActInfo,0))
    {
			IActor* pActor = GetInputActor( pActInfo );
			if (!pActor)
				return;

			IInventory *pInventory = pActor->GetInventory();
      if (!pInventory)
        return;

      const string& item = GetPortString(pActInfo, 1);

			IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(item);
      if (0 == pInventory->GetItemByClass(pClass))
      {
        ActivateOutput(pActInfo, 0, false);
      }
      else
      {
        pGF->GetIItemSystem()->SetActorItem(pActor, item, true);
        ActivateOutput(pActInfo, 0, true);
      }
    }
  }
int wmain()
{
	// CoInitialize(NULL);
	CoInitializeEx(NULL, COINIT_MULTITHREADED);

	IInventory* pInv = NULL;
	HRESULT hr = CoCreateInstance(CLSID_Trader, NULL, CLSCTX_INPROC_SERVER, IID_IInventory, reinterpret_cast<LPVOID*>(&pInv));
	if(SUCCEEDED(hr))
	{
		int qty;
		double bal;

		wcout << L"Number of items to purchase : ";
		wcin >> qty;
		hr = pInv->Buy(qty, 100);
		if(FAILED(hr))
			wcout << L"Buy operation failed with error code of " << hex << hr << endl;
		else
		{
			IAccount* pAcc = NULL;
			pInv->QueryInterface(IID_IAccount, reinterpret_cast<LPVOID*>(&pAcc));
			pInv->GetStock(&qty);
			pAcc->GetBalance(&bal);
			wcout << L"Current stock : " << qty << endl;
			wcout << L"Current balance : " << bal << endl;
			pAcc->Release();
		}
		pInv->Release();
	}
	else
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		if (event == eFE_Activate && IsPortActive(pActInfo,0))
		{
			IActor* pActor = GetInputActor( pActInfo );
			if (!pActor || pActor!=gEnv->pGame->GetIGameFramework()->GetClientActor())  // to avoid some extra RMIs and object creation. Tho, this causes the node to not work properly if it is used with non players entities. (which was never intended anyway)
				return;

			IEntitySystem* pEntSys = gEnv->pEntitySystem;

			IInventory *pInventory = pActor->GetInventory();
			if (!pInventory)
				return;

			const string& itemClass = GetPortString(pActInfo, 1);
			const char* pItemClass = itemClass.c_str();
			IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(pItemClass);
			EntityId id = pInventory->GetItemByClass(pClass);

			if (id == 0 || GetPortBool(pActInfo, 3) == false)
			{
				if(gEnv->bServer)
				{
					gEnv->pGame->GetIGameFramework()->GetIItemSystem()->GiveItem( pActor, pItemClass , false, true, true );
				}
				else
				{
					// TODO: instant output activation, with delayed effective change in the inventory, it potentially could cause problems in rare situations
					pInventory->RMIReqToServer_AddItem( pItemClass );
				}
				ActivateOutput( pActInfo, 0, true );
			}
			else
			{
				// item already in inventory
				ActivateOutput(pActInfo, 0, false);
			}			
		}
		else if (event == eFE_PrecacheResources)
		{
			const string& itemClass = GetPortString(pActInfo, 1);

			if (!itemClass.empty())
			{
				IGameRules* pGameRules = CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRules();
				CRY_ASSERT_MESSAGE(pGameRules != NULL, "No game rules active, can not precache resources");
				if (pGameRules)
				{
					pGameRules->PrecacheLevelResource(itemClass.c_str(), eGameResourceType_Item);
				}
			}
		}
	}
void CFlashUIInventoryNode::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
	if(event == eFE_Activate && IsPortActive(pActInfo, 0))
	{
		IActor* pActor = GetInputActor( pActInfo );
		if(pActor)
		{
			IInventory* pInventory = pActor->GetInventory();
			if(pInventory)
			{
				string weapons = "";
				bool first = true;
				int inv_cap = gEnv->pConsole->GetCVar("i_inventory_capacity")->GetIVal();
				for (int i = 0; i < inv_cap; i++)
				{
					const char* weaponName = pInventory->GetItemString(i);

					if(strcmp(weaponName, "") != 0)
					{
						bool selectable = false;

						//Get the weapon and check if it is a selectable item
						IEntityClassRegistry *pRegistry = gEnv->pEntitySystem->GetClassRegistry();
						EntityId item = pInventory->GetItemByClass(pRegistry->FindClass(weaponName));
						IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item);

						if(pEntity)
						{
							CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER);
							CItem* pItem = (CItem*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName());
							if(pItem)
							{
								selectable = pItem->CanSelect();
							}
						}
						if(selectable)
						{
							if(!first)
								weapons.append(",");
							first = false;
							weapons.append(weaponName);
						}
					}

				}

				ActivateOutput(pActInfo, eO_OnCall, true);
				ActivateOutput(pActInfo, eO_Args, weapons);
			}
		}
	}
}
void CFlashUIGetCompatibleAccessoriesNode ::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
	if(event == eFE_Activate && IsPortActive(pActInfo, 0))
	{
		string accessories = "";
		IActor* pActor = GetInputActor( pActInfo );

		if(pActor)
		{
			IInventory* pInventory = pActor->GetInventory();
			if(pInventory)
			{
				//Get the item ID via the Input string
				const string weapon_name = GetPortString(pActInfo, eI_Weapon);
				IEntityClassRegistry *pRegistery = gEnv->pEntitySystem->GetClassRegistry();
				EntityId item = pInventory->GetItemByClass(pRegistery->FindClass(weapon_name));

				//Fetch the actual weapon via the ID
				IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item);
				if(pEntity)
				{

					CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER);
					const char* ext = pGameObject->GetEntity()->GetClass()->GetName();
					CWeapon* pWeapon = (CWeapon*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName());

					//If the weapon exists, ask for all compatible accessories
					if(pWeapon)
					{
						//All compatible accessories for this weapon
						const DynArray<string> pCompatibleAccessoriesVec = pWeapon->GetCompatibleAccessories();

						bool first = true;
						DynArray<string>::const_iterator it;
						for (it = pCompatibleAccessoriesVec.begin(); it != pCompatibleAccessoriesVec.end(); it++)
						{
							if (!first)
								accessories.append(",");
							accessories.append((*it));
							first = false;
						}
					}
				}
			}
		}

		//return, if 'accessories' is empty, it has no compatible attachments, or the weapon/inventory was invalid
		ActivateOutput(pActInfo, eO_OnCall, true);
		ActivateOutput(pActInfo, eO_Args, accessories);
	}
}
Exemple #8
0
void CJaw::DropUnused(CActor* pOwner)
{
	IInventory* pInventory = pOwner->GetInventory();
	EntityId nextJawEntity = 0;
	for (;;)
	{
		nextJawEntity = pInventory->GetItemByClass(GetEntity()->GetClass());
		if (!nextJawEntity)
			break;
		CJaw* pNextJawItem = static_cast<CJaw*>(m_pItemSystem->GetItem(nextJawEntity));
		if (pNextJawItem)
			pNextJawItem->Drop(1.0f, false, false);
	}
}
Exemple #9
0
bool CJaw::OutOfAmmo(bool allFireModes) const
{
	CActor* pOwner = GetOwnerActor();
	IInventory* pOwnerInventory = pOwner ? pOwner->GetInventory() : 0;
	if (!pOwnerInventory)
		return true;

	IEntityClass* pJawClass = GetEntity()->GetClass();
	IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
	int jawUniqueId = pItemSystem->GetItemUniqueId(pJawClass->GetName());
	int currentNumJaws = pOwnerInventory->GetCountOfUniqueId(jawUniqueId);

	return currentNumJaws == 0;
}
Exemple #10
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{ 
		switch (event)
		{
		case (eFE_Activate):
			{
				if (!IsPortActive(pActInfo, 0))
					return;

				IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();

				// get actor
				IActor* pActor = CCryAction::GetCryAction()->GetClientActor();
				if (!pActor) 
					return;

				IInventory *pInventory = pActor->GetInventory();
				if (!pInventory)
					return;

				IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(GetPortString(pActInfo,1));
				IItem* pItem = pItemSys->GetItem(pInventory->GetItemByClass(pClass));
				if (!pItem || !pItem->GetIWeapon())
				{
					pItem = pActor->GetCurrentItem();
					if (!pItem || pItem->GetEntity()->GetClass() != pClass || !pItem->GetIWeapon())
					{
						GameWarning("[flow] CFlowNode_WeaponAmmo: No item/weapon %s!", GetPortString(pActInfo,1).c_str());
						return;
					}
				}
				IWeapon *pWeapon = pItem->GetIWeapon();
				const string& ammoType = GetPortString(pActInfo,2);
				IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str());
				CRY_ASSERT(pAmmoClass);
				IFireMode* pCurrentFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode());
				if (pCurrentFireMode)
				{
					int clipSize = pCurrentFireMode->GetClipSize();
					int ammo = pWeapon->GetAmmoCount(pAmmoClass) + GetPortInt(pActInfo,3);
					ammo = CLAMP(ammo, 0, clipSize);
					pWeapon->SetAmmoCount(pAmmoClass, ammo);
				}

				ActivateOutput(pActInfo, 0, pWeapon->GetAmmoCount(pAmmoClass));
			}
			break;
		}
	}
Exemple #11
0
//------------------------------------------------------------------------
CItem *CItem::GetAccessoryPlaceHolder(const ItemString &name)
{
	IInventory *pInventory = GetActorInventory(GetOwnerActor());

	if(!pInventory)
		return 0;

	IEntityClass *pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(name);
	int slotId = pInventory->FindNext(pClass, 0, -1, false);

	if(slotId >= 0)
		return static_cast<CItem *>(m_pItemSystem->GetItem(pInventory->GetItem(slotId)));

	return 0;
}
Exemple #12
0
bool CJaw::GiveExtraTubeToInventory(IActor* pPickerActor, IItemSystem* pItemSystem) const
{
	if (m_weaponsharedparams->ammoParams.extraItems == 0 || !pPickerActor->IsPlayer())
		return false;

	if (m_extraTubesAdded)
		return false;

	IEntityClass* pJawClass = GetEntity()->GetClass();
	IInventory* pPickerInventory = pPickerActor ? pPickerActor->GetInventory() : 0;
	int jawUniqueId = pItemSystem->GetItemUniqueId(pJawClass->GetName());
	int currentNumJaws = pPickerInventory ? pPickerInventory->GetCountOfUniqueId(jawUniqueId) : 0;
	bool giveExtraTube = (currentNumJaws == 0);

	return giveExtraTube;
}
void CFlowNode_AISequenceAction_WeaponDrawFromInventory::HandleSequenceEvent(AIActionSequence::SequenceEvent sequenceEvent)
{
	switch(sequenceEvent)
	{
	case AIActionSequence::StartAction:
		{
			CRY_ASSERT_MESSAGE(m_actInfo.pEntity, "entity has magically gone");
			if (!m_actInfo.pEntity)
			{
				// the entity has gone for some reason, at least make sure the action gets finished properly and the FG continues
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIActorSystem());
			IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actInfo.pEntity->GetId());
			if (!pActor)
			{
				CRY_ASSERT_MESSAGE(0, "Provided entity must be an IActor");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Provided entity %s must be an IActor", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIItemSystem());
			IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();

			IInventory* pInventory = pActor->GetInventory();
			if (!pInventory)
			{
				CRY_ASSERT_MESSAGE(0, "Actor has no inventory");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s has no inventory", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			pInventory->SetHolsteredItem(EntityId(0));	// otherwise trying to holster the new weapon later on will not work (i. e. will do nothing)

			// draw the weapon
			const string& weaponName = GetPortString(&m_actInfo, InputPort_WeaponName);
			pItemSystem->SetActorItem(pActor, weaponName.c_str(), false);

			FinishSequenceActionAndActivateOutputPort(OutputPort_Done);
		}
		break;
	}
}
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		if (event == eFE_Activate && IsPortActive(pActInfo,0))
		{
			IActor* pActor = GetInputActor( pActInfo );
			if (!pActor)
				return;

			IInventory *pInventory = pActor->GetInventory();
			
			if (pInventory)
			{
	      pInventory->ResetAmmo();

				const bool removeFromWeapons = GetPortBool(pActInfo, 1);
				if(removeFromWeapons)
				{
					IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem();
					const size_t numItems = pInventory->GetCount();
					for(size_t i=0; i<numItems; ++i)
					{
						const EntityId item = pInventory->GetItem(i);
						if(IItem* pItem = pItemSystem->GetItem(item))
						{
							if(IWeapon* pWeapon = pItem->GetIWeapon())
							{
								const size_t numFiremodes = pWeapon->GetNumOfFireModes();
								for(size_t f=0; f<numFiremodes; ++f)
								{
									if(IFireMode* pFireMode = pWeapon->GetFireMode(f))
									{
										if(IEntityClass* pAmmoType = pFireMode->GetAmmoType())
										{
											pWeapon->SetAmmoCount(pAmmoType, 0);
										}
									}
								}
							}
						}
					}
				}
				ActivateOutput(pActInfo, 0, true);
			}
			else
  			ActivateOutput(pActInfo, 0, false);
		}
	}
Exemple #15
0
//--------------------------------------------
bool CAmmoPickup::CheckAmmoRestrictions(EntityId pickerId)
{
	if(g_pGameCVars->i_unlimitedammo != 0)
		return true;

	if(gEnv->pSystem->IsEditor())
		return true;

	IActor* pPicker = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pickerId);
	if(pPicker)
	{
		IInventory *pInventory = pPicker->GetInventory();
		if(pInventory)
		{
			for (TAmmoMap::const_iterator it=m_ammo.begin(); it!=m_ammo.end(); ++it)
			{
				int invAmmo  = pInventory->GetAmmoCount(it->first);
				int invLimit = pInventory->GetAmmoCapacity(it->first);

				if(invAmmo>=invLimit && (!gEnv->pSystem->IsEditor()))
					return false;
			}

			const char *ammoName=0;
			if (GetEntityProperty("AmmoName", ammoName) && ammoName && ammoName[0])
			{
				int count=0;
				GetEntityProperty("Count", count);
				if (count)
				{
					IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoName);
					if(pClass)
					{
						int invAmmo  = pInventory->GetAmmoCount(pClass);
						int invLimit = pInventory->GetAmmoCapacity(pClass);
						if(invAmmo>=invLimit)
							return false;
					}
				}
			}
		}
	}

	return true;
}
Exemple #16
0
	void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
	{
		if (event == eFE_Activate && (IsPortActive(pActInfo, IN_GET) || IsPortActive(pActInfo, IN_SET)))
		{
			IActor* pActor = GetInputActor(pActInfo);
			if (!pActor) 
				return;
			
			IInventory *pInventory = pActor->GetInventory();
			if (pInventory)
			{
				const string& ammoType = GetPortString(pActInfo, IN_AMMOTYPE);
				IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str());

				if (pAmmoClass)
				{
					if (IsPortActive(pActInfo, IN_SET))
					{
						const bool bAdd = GetPortBool(pActInfo, IN_ADD);
						const int ammoAmount = GetPortInt(pActInfo, IN_AMMOCOUNT);

						pInventory->SetAmmoCount(pAmmoClass, bAdd ? (ammoAmount + pInventory->GetAmmoCount(pAmmoClass)) : (ammoAmount));
					}

					int magazineAmmo = 0;
					int inventoryAmmo = pInventory->GetAmmoCount(pAmmoClass);

					if (IItem* pItem = pActor->GetCurrentItem())
					{
						IWeapon* pCurrentWeapon = GetWeapon(pItem->GetEntityId());

						if (pCurrentWeapon)
						{
							magazineAmmo = pCurrentWeapon->GetAmmoCount(pAmmoClass);
						}
					}

					ActivateOutput(pActInfo, OUT_MAGAZINE, magazineAmmo);
					ActivateOutput(pActInfo, OUT_INVENTORY, inventoryAmmo);
					ActivateOutput(pActInfo, OUT_TOTAL, (magazineAmmo + inventoryAmmo));
				}
			}
		}
	}
Exemple #17
0
void CJaw::Drop(float impulseScale, bool selectNext, bool byDeath)
{
	// No special handling needed when exiting editor game mode
	if (gEnv->IsEditor() && !gEnv->IsEditorGameMode())
		return BaseClass::Drop(impulseScale, selectNext, byDeath);

	CActor* pOwner = GetOwnerActor();
	//Don't let the player drop it if it has not been opened
	if(m_stats.first_selection && pOwner && pOwner->IsPlayer() && !pOwner->IsDead() && !byDeath)
		return;

	if(pOwner && !pOwner->IsPlayer())
	{
		//In this case goes to the clip, no the inventory

		if(m_minDropAmmoAvailable && !m_weaponsharedparams->ammoParams.minDroppedAmmo.empty())
		{
			TAmmoVector::const_iterator end = m_weaponsharedparams->ammoParams.minDroppedAmmo.end();

			for(TAmmoVector::const_iterator it = m_weaponsharedparams->ammoParams.minDroppedAmmo.begin(); it != end; ++it)
			{
				SWeaponAmmoUtils::SetAmmo(m_ammo, it->pAmmoClass, it->count);
			}

			m_minDropAmmoAvailable = false;
		}
	}

	BaseClass::Drop(impulseScale,selectNext,byDeath);
	if (pOwner && !selectNext && !pOwner->IsHeadUnderWater())
	{
		IInventory* pInventory = pOwner->GetInventory();
		EntityId pNextJawItem = pInventory->GetItemByClass(GetEntity()->GetClass());
		m_pItemSystem->SetActorItem(pOwner, pNextJawItem, true);
	}

	if (pOwner && pOwner->IsPlayer())
	{
		if (m_fired)
			DropUsed();
		else
			DropUnused(pOwner);
	}
}
  void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
  {
    if (event == eFE_Activate && IsPortActive(pActInfo,0))
    {
      IGameFramework* pGF = gEnv->pGame->GetIGameFramework();
      
			IActor* pActor = GetInputActor( pActInfo );
			if (!pActor || pActor!=gEnv->pGame->GetIGameFramework()->GetClientActor())  // to avoid some extra RMIs and object creation. Tho, this causes the node to not work properly if it is used with non players entities. (which was never intended anyway)
				return;

			IInventory *pInventory = pActor->GetInventory();
      if (!pInventory)
        return;
        
      pInventory->RMIReqToServer_RemoveAllItems();
      // TODO: instant output activation, with delayed effective change in the inventory, it potentially could cause problems in rare situations
      ActivateOutput(pActInfo, 0, true);
    }
  }
Exemple #19
0
void CJaw::AddAmmoCapacity()
{
	CActor* pOwner = GetOwnerActor();
	if (!pOwner || !(gEnv->bServer || pOwner->IsClient()))
		return;
	IInventory* pOwnerInventory = pOwner->GetInventory();
	if (!pOwnerInventory)
		return;
	if (pOwnerInventory->GetItemByClass(GetEntity()->GetClass()) != 0)
		return;
	const CWeaponSharedParams* pWeaponParams = GetWeaponSharedParams();

	for (size_t i = 0; i < pWeaponParams->ammoParams.capacityAmmo.size(); ++i)
	{
		IEntityClass* pAmmoType = pWeaponParams->ammoParams.capacityAmmo[i].pAmmoClass;
		int capacity = pWeaponParams->ammoParams.capacityAmmo[i].count;
		pOwnerInventory->SetAmmoCapacity(pAmmoType, capacity);
	}
}
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		if (event == eFE_Activate && IsPortActive(pActInfo, EIP_Trigger))
		{
			IActor* pActor = GetInputActor( pActInfo );
			if (!pActor)
				return;

			IInventory *pInventory = pActor->GetInventory();
			if (!pInventory)
				return;

			const bool& addPack = GetPortBool(pActInfo, EIP_AddToggle);
			const string& packName = GetPortString(pActInfo, EIP_EquipmentPack);
			const bool& selectPrimary = GetPortBool(pActInfo, EIP_SelectPrimary);

			if (pActor->IsPlayer())
				pInventory->RMIReqToServer_AddEquipmentPack( packName.c_str(), addPack, selectPrimary );
			else
			{
				if (gEnv->bServer)
					CCryAction::GetCryAction()->GetIItemSystem()->GetIEquipmentManager()->GiveEquipmentPack( pActor, packName.c_str(), addPack, selectPrimary );
			}
				
			// TODO: instant output activation, with delayed effective change in the inventory, it potentially could cause problems in rare situations
			ActivateOutput(pActInfo, EOP_Done, true);
		}
		else if (event == eFE_PrecacheResources)
		{
			const string& packName = GetPortString(pActInfo, 1);

			if (!packName.empty())
			{
				IGameRules* pGameRules = CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRules();
				CRY_ASSERT_MESSAGE(pGameRules != NULL, "No game rules active, can not precache resources");
				if (pGameRules)
				{
					pGameRules->PrecacheLevelResource(packName.c_str(), eGameResourceType_Loadout);
				}
			}
		}
	}
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		if (event == eFE_Activate && IsPortActive(pActInfo,0))
		{
			IActor* pActor = GetInputActor( pActInfo );
			if (!pActor)
				return;
      
			IInventory *pInventory = pActor->GetInventory();
      if (!pInventory)
        return;

			IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(GetPortString(pActInfo,1));
      EntityId id = pInventory->GetItemByClass(pClass);
			
			ActivateOutput(pActInfo, 0, id !=0 ? true : false);
			ActivateOutput(pActInfo, id != 0 ? 2 : 1, true);
			ActivateOutput(pActInfo, 3, id);
		}
	}
void CFlashUIGetEquippedAccessoriesNode::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
	if(event == eFE_Activate && IsPortActive(pActInfo, 0))
	{
		string accessories = "";
		IActor* pActor = GetInputActor( pActInfo );

		if(pActor)
		{
			IInventory* pInventory = pActor->GetInventory();
			if(pInventory)
			{

				//Get the item ID via the Input string
				const string weapon_name = GetPortString(pActInfo, eI_Weapon);
				IEntityClassRegistry *pRegistery = gEnv->pEntitySystem->GetClassRegistry();
				EntityId item = pInventory->GetItemByClass(pRegistery->FindClass(weapon_name));

				//Fetch the actual object via the ID
				CGameObject * pGameObject = (CGameObject*)gEnv->pEntitySystem->GetEntity(item)->GetProxy(ENTITY_PROXY_USER);
				const char* ext = pGameObject->GetEntity()->GetClass()->GetName();
				IItem* pWeapon = (IItem*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName());

				//If the weapon exists, return all equipped attachments in a comma seperated string
				if(pWeapon)
				{
					//All equipped accessories for this weapon weapons
					accessories = static_cast<CItem*>(pWeapon)->GetAttachedAccessoriesString();
				}
			}
		}

		//return, if 'accesories' is empty, it has no attachments, or something was invalid
		ActivateOutput(pActInfo, eO_OnCall, true);
		ActivateOutput(pActInfo, eO_Args, accessories);
	}
}
Exemple #23
0
//------------------------------------------------------------------------
void CWeapon::OnPickedUp(EntityId actorId, bool destroyed)
{
	BROADCAST_WEAPON_EVENT(OnPickedUp, (this, actorId, destroyed));

	CItem::OnPickedUp(actorId, destroyed);

	GetEntity()->SetFlags(GetEntity()->GetFlags() | ENTITY_FLAG_NO_PROXIMITY);
	GetEntity()->SetFlags(GetEntity()->GetFlags() & ~ENTITY_FLAG_ON_RADAR);

	if(GetISystem()->IsSerializingFile() == 1)
		return;

	if(!IsServer())
		return;

	CActor *pActor=GetActor(actorId);

	if(!pActor)
		return;

	// bonus ammo is always put in the actor's inv
	if(!m_bonusammo.empty())
	{
		for(TAmmoMap::iterator it=m_bonusammo.begin(); it!=m_bonusammo.end(); ++it)
		{
			int count=it->second;

			SetInventoryAmmoCount(it->first, GetInventoryAmmoCount(it->first)+count);
		}

		m_bonusammo.clear();
	}

	if(!m_ammoCapacity.empty())
	{
		IInventory *pInventory = GetActorInventory(GetOwnerActor());

		if(pInventory)
		{
			for(TAmmoMap::iterator it=m_ammoCapacity.begin(); it!=m_ammoCapacity.end(); ++it)
				pInventory->SetAmmoCapacity(it->first, it->second);
		}

		m_ammoCapacity.clear();
	}

	// current ammo is only added to actor's inv, if we already have this weapon
	if(destroyed && m_sharedparams->params.unique)
	{
		for(TAmmoMap::iterator it=m_ammo.begin(); it!=m_ammo.end(); ++it)
		{
			//Only add ammo to inventory, if not accessory ammo (accessories give ammo already)
			if(m_accessoryAmmo.find(it->first)==m_accessoryAmmo.end())
			{
				int count=it->second;

				SetInventoryAmmoCount(it->first, GetInventoryAmmoCount(it->first)+count);
			}
		}
	}

	if(!gEnv->bMultiplayer && !m_initialSetup.empty() && pActor->IsClient())
	{
		for(TAccessoryMap::iterator it=m_accessories.begin(); it!=m_accessories.end(); ++it)
			FixAccessories(GetAccessoryParams(it->first), true);
	}

	m_expended_ammo = 0;
}
Exemple #24
0
void CAccessory::PickUp(EntityId pickerId, bool sound, bool select/* =true */, bool keepHistory/* =true */, const char *setup /*= NULL*/)
{
    CActor *pActor=GetActor(pickerId);
    if (!pActor)
        return;

    TriggerRespawn();

    GetEntity()->EnablePhysics(false);
    Physicalize(false, false);

    bool soundEnabled = IsSoundEnabled();
    EnableSound(sound);

    SetViewMode(0);
    SetOwnerId(pickerId);

    CopyRenderFlags(GetOwner());

    Hide(true);
    m_stats.dropped = false;
    m_stats.detached = false;
    m_stats.brandnew = false;


    IInventory *pInventory = pActor->GetInventory();
    if (!pInventory)
        {
            GameWarning("Actor '%s' has no inventory, when trying to pickup '%s'!",pActor->GetEntity()->GetName(),GetEntity()->GetName());
            return;
        }

    if (!pActor->IsPlayer() || pActor->IsClient() || gEnv->bMultiplayer)
        {
            bool hasAccessory = pInventory->HasAccessory(GetEntity()->GetClass());
            bool hasAccessoryForThisWeapon = pInventory->HasAccessory(GetEntity()->GetClass());

            if (!hasAccessoryForThisWeapon)
                pInventory->AddAccessory(GetEntity()->GetClass());
            if (!hasAccessory)
                ProcessAccessoryAmmoCapacities(pInventory, true);
            if (!hasAccessoryForThisWeapon)
                ProcessAccessoryAmmo(pInventory);
        }

    OnPickedUp(pickerId, m_sharedparams->params.unique);

    if (select)
        {
            PlayAction(GetFragmentIds().pickedup);
        }

    EnableSound(soundEnabled);

    bool isLocalEntity = GetEntity()->GetFlags()&(ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY) ? true : false;

    if (IsServer() && !IsDemoPlayback())
        {
            if(!gEnv->bMultiplayer || isLocalEntity)
                RemoveEntity();
            else if(g_pGame->GetGameRules())
                g_pGame->GetGameRules()->ScheduleEntityRemoval(GetEntityId(),10.0f,false); //Give some time to the clients to pick the msg
        }

    if (IsServer())
        {
            GetGameObject()->SetNetworkParent(pickerId);
            if (!isLocalEntity)
                {
                    pActor->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClPickUp(), CActor::PickItemParams(GetEntityId(), m_stats.selected, sound), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());
                }
        }
}
Exemple #25
0
void CAccessory::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char *setup)
{
	CActor *pActor=GetActor(pickerId);
	if (!pActor)
		return;

	if(!CheckAmmoRestrictions(pickerId))
	{
		if (IsServer())
			g_pGame->GetGameRules()->SendTextMessage(eTextMessageCenter, "@ammo_maxed_out", eRMI_ToClientChannel, pActor->GetChannelId(), (string("@")+GetEntity()->GetClass()->GetName()).c_str());
		return;
	}

	TriggerRespawn();

	GetEntity()->EnablePhysics(false);
	Physicalize(false, false);

	bool soundEnabled = IsSoundEnabled();
	EnableSound(sound);

	SetViewMode(0);		
	SetOwnerId(pickerId);

	CopyRenderFlags(GetOwner());

	Hide(true);
	m_stats.dropped = false;
	m_stats.brandnew = false;


	IInventory *pInventory = pActor->GetInventory();
	if (!pInventory)
	{
		GameWarning("Actor '%s' has no inventory, when trying to pickup '%s'!",pActor->GetEntity()->GetName(),GetEntity()->GetName());
		return;
	}

	if(!pInventory->HasAccessory(GetEntity()->GetClass()))
	{
		pInventory->AddAccessory(GetEntity()->GetClass());
	}

	OnPickedUp(pickerId, m_sharedparams->params.unique);	

	PlayAction(g_pItemStrings->pickedup);

	EnableSound(soundEnabled);

	if (IsServer() && !IsDemoPlayback())
	{
		if(!gEnv->bMultiplayer)
			RemoveEntity();
		else if(g_pGame->GetGameRules())
			g_pGame->GetGameRules()->ScheduleEntityRemoval(GetEntityId(),10.0f,false); //Give some time to the clients to pick the msg
	}

	if (IsServer())
	{
		GetGameObject()->SetNetworkParent(pickerId);
		if ((GetEntity()->GetFlags()&(ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY)) == 0)
		{
			pActor->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClPickUp(), CActor::PickItemParams(GetEntityId(), m_stats.selected, sound), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());

			const char *displayName=GetDisplayName();
}
	}
}
void CFlashUICheckAccessoryState ::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
	if(event == eFE_Activate && IsPortActive(pActInfo, 0))
	{
		IActor* pActor = GetInputActor( pActInfo );
		bool is_equipped = false;
		bool is_inInventory = false;

		if(pActor)
		{
			IInventory* pInventory = pActor->GetInventory();

			if(pInventory)
			{
				IEntityClassRegistry *pRegistry = gEnv->pEntitySystem->GetClassRegistry();

				//Find the accessory's class in the registry
				const string accessory_name = GetPortString(pActInfo, eI_Accessory);				
				IEntityClass* pClass = pRegistry->FindClass(accessory_name);

				//Check if its in inventory
				if(pInventory->HasAccessory(pClass) != 0)
				{
					is_inInventory = true;
				}	

				//if it is, check if its equipped as well
				if(is_inInventory)
				{
					//Get the weapon ID via the Input string
					const char* weapon_name = GetPortString(pActInfo, eI_Weapon).c_str();
					EntityId item = pInventory->GetItemByClass(pRegistry->FindClass(weapon_name));

					//Fetch the actual weapon via the ID
					IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item);
					if(pEntity)
					{

						CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER);
						const char* ext = pGameObject->GetEntity()->GetClass()->GetName();
						CWeapon* pWeapon = (CWeapon*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName());
						bool selectable = pWeapon->CanSelect();
						if(pWeapon)
						{
							if(pWeapon->GetAccessory(pClass->GetName()) != 0)
							{
								is_equipped = true;
							}					
						}
					}
				}
			}
		}

		if(!is_inInventory)
			ActivateOutput(pActInfo, eO_DontHave, true);
		else if(is_equipped)
			ActivateOutput(pActInfo, eO_Equipped, true);
		else
			ActivateOutput(pActInfo, eO_InInventory, true);

	}
}
int CScriptBind_Weapon::AttachAccessoryPlaceHolder(IFunctionHandler *pH, SmartScriptTable accessory, bool attach)
{
	CWeapon *pWeapon = GetWeapon(pH);
	if (!pWeapon)
		return pH->EndFunction();

	const char *accessoryName;
	accessory->GetValue("class", accessoryName);
	ScriptHandle id;
	accessory->GetValue("id", id);
	
	EntityId entId = (EntityId)id.n;
	//CryLogAlways("id = %d", entId);
	IEntity *attachment = gEnv->pEntitySystem->GetEntity(entId);
	

	if (accessoryName)
	{
		//CryLogAlways("got name: %s", accessoryName);
		if (pWeapon->GetAccessoryPlaceHolder(accessoryName))
		{
			//CryLogAlways("found accessory place holder");
			pWeapon->AttachAccessoryPlaceHolder(accessoryName, attach);
		}
		else
		{
			//CryLogAlways("accessory place holder not found");
			CActor *pActor = pWeapon->GetOwnerActor();
			IEntity *wep = pWeapon->GetEntity();
			//IGameObject *pGameObject = pWeapon->GetOwnerActor()->GetGameObject();
			IInventory *pInventory = pActor->GetInventory();
			if (pInventory)
			{
				//CryLogAlways("found inventory");
				if (attachment)
				{
					if (pInventory->FindItem(entId) != -1)
					{
						//CryLogAlways("found attachment in inventory already...");
					}
					else
					{
						//CryLogAlways("attachment not found in inventory, adding...");
					}
					//CryLogAlways("found attachment");
					
					
					//attachment->DetachThis(0);
					//attachment->SetParentId(0);
					//CItem *t = (CItem *)attachment;
					//t->SetParentId(0);
					//pWeapon->GetEntity()->AttachChild(attachment, false)
					pInventory->AddItem(attachment->GetId());
					//for (int i = 0; i < wep->GetChildCount(); i++)
					//{
					//	IEntity *cur = wep->GetChild(i);
					//	CryLogAlways("none of these should be %s", attachment->GetName());
					//	CryLogAlways(" %s", cur->GetName());
					//}
					pWeapon->AttachAccessoryPlaceHolder(accessoryName, attach);
					pInventory->RemoveItem(attachment->GetId());
					
				}
				else
				{
					//CryLogAlways("!attachment");
				}
			}
		}
		
	}
	return pH->EndFunction();
}
Exemple #28
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{ 
		switch (event)
		{
		case eFE_Initialize:
			{
				m_actInfo = *pActInfo;
				Reset();
			}
			break;

		case eFE_Activate:
			{ 
				IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();

				// create listener
				if (IsPortActive(pActInfo, IN_DISABLE))
				{ 
					Reset();
				}
				if (IsPortActive(pActInfo, IN_ENABLE))
				{ 
					Reset();
					IItem* pItem = 0;

					EntityId weaponId = GetPortEntityId(pActInfo, IN_WEAPONID);                    
					if (weaponId != 0)
					{
						pItem = pItemSys->GetItem(weaponId);
					}
					else
					{            
						IActor* pActor = CCryAction::GetCryAction()->GetClientActor();
						if (!pActor) 
							return;

						IInventory *pInventory = pActor->GetInventory();
						if (!pInventory)
							return;

						const string& weaponClass = GetPortString(pActInfo, IN_WEAPONCLASS);
						if (!weaponClass.empty())
						{
							// get actor weapon by class
							IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(weaponClass);
							pItem = pItemSys->GetItem( pInventory->GetItemByClass(pClass) );
						}
						else
						{
							// get current actor weapon
							pItem = pItemSys->GetItem(pInventory->GetCurrentItem());
						}
					}          

					if (!pItem || !pItem->GetIWeapon())
					{
						GameWarning("[flow] CFlowNode_WeaponListener: no item/weapon.");
						return;
					}

					m_weapId = pItem->GetEntity()->GetId();
					IWeapon* pWeapon = pItem->GetIWeapon();

					// set initial ammo
					m_ammo = GetPortInt(pActInfo, IN_AMMO);
					if (m_ammo == 0)
						m_ammo = -1; // 0 input means infinite

					// set weapon listener                            
					pWeapon->AddEventListener(this, "CFlowNode_WeaponListener");

					m_active = true;

					//CryLog("WeaponListener successfully created on %s", pItem->GetEntity()->GetName());
				}           
				break;
			}
		}
	}
Exemple #29
0
// (jh) this function is called on any input dispatching it to a relevant method and eventually to Lua onAction method
void CPlayerInput::OnAction( const ActionId& actionId, int activationMode, float value )
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if (g_pGame->GetHostMigrationState() != CGame::eHMS_NotMigrating)
	{
		Reset();
		return;
	}

	m_pPlayer->GetGameObject()->ChangedNetworkState( INPUT_ASPECT );

	m_lastActions=m_actions;

	//this tell if OnAction have to be forwarded to scripts, now its true by default, only high framerate actions are ignored
	bool filterOut = true;
	m_checkZoom = false;
	const CGameActions& actions = g_pGame->Actions();
	IVehicle* pVehicle = m_pPlayer->GetLinkedVehicle();

	bool canMove = CanMove();

	// disable movement while standing up
	if (!canMove)
		m_deltaMovement.zero();

	// try to dispatch action to OnActionHandlers
	bool handled;

	{
		FRAME_PROFILER("New Action Processing", GetISystem(), PROFILE_GAME);
		handled = s_actionHandler.Dispatch(this, m_pPlayer->GetEntityId(), actionId, activationMode, value, filterOut);
	}

	{
		FRAME_PROFILER("Regular Action Processing", GetISystem(), PROFILE_GAME);
		if (!handled)
		{
			filterOut = true;
			if (!m_pPlayer->m_stats.spectatorMode)
			{
				if (actions.ulammo==actionId && m_pPlayer->m_pGameFramework->CanCheat() && gEnv->pSystem->IsDevMode())
				{
					g_pGameCVars->i_unlimitedammo = 1;
				}
				else if (actions.debug_ag_step == actionId)
				{
					gEnv->pConsole->ExecuteString("ag_step");
				}
				else if(actions.voice_chat_talk == actionId)
				{
					if(gEnv->bMultiplayer)
					{
						if(activationMode == eAAM_OnPress)
							g_pGame->GetIGameFramework()->EnableVoiceRecording(true);
						else if(activationMode == eAAM_OnRelease)
							g_pGame->GetIGameFramework()->EnableVoiceRecording(false);
					}
				}
			}
		}

		if (!m_pPlayer->m_stats.spectatorMode)
		{
			IInventory* pInventory = m_pPlayer->GetInventory();
			if (!pInventory)
				return;

			bool scope = false;
			EntityId itemId = pInventory->GetCurrentItem();
			CWeapon *pWeapon = 0;
			if (itemId)
			{
				pWeapon = m_pPlayer->GetWeapon(itemId);
				if (pWeapon)
				{
					scope = (pWeapon->IsZoomed() && pWeapon->GetMaxZoomSteps()>1);
				}
			}

			if (pVehicle)
			{
				if (m_pPlayer->m_pVehicleClient && !m_pPlayer->IsFrozen())
					m_pPlayer->m_pVehicleClient->OnAction(pVehicle, m_pPlayer->GetEntityId(), actionId, activationMode, value);

				//FIXME:not really good
				m_actions = 0;
				m_deltaMovement.Set(0,0,0);
			}
			else if (m_pPlayer->GetHealth() > 0 && !m_pPlayer->m_stats.isFrozen.Value() && !m_pPlayer->m_stats.inFreefall.Value() && !m_pPlayer->m_stats.isOnLadder 
				&& !m_pPlayer->m_stats.isStandingUp && m_pPlayer->GetGameObject()->GetAspectProfile(eEA_Physics)!=eAP_Sleep)
			{
				m_pPlayer->CActor::OnAction(actionId, activationMode, value);

				if ((!scope || actionId == actions.use))
				{
					COffHand* pOffHand = static_cast<COffHand*>(m_pPlayer->GetWeaponByClass(CItem::sOffHandClass));
					if (pOffHand)
					{
						pOffHand->OnAction(m_pPlayer->GetEntityId(), actionId, activationMode, value);
					}

					if ((!pWeapon || !pWeapon->IsMounted()))
					{
						if ((actions.drop==actionId) && itemId)
						{
							float impulseScale=1.0f;
							if (activationMode==eAAM_OnPress)
								m_buttonPressure=2.5f;
							if (activationMode==eAAM_OnRelease)
							{
								m_buttonPressure=CLAMP(m_buttonPressure, 0.0f, 2.5f);
								impulseScale=1.0f+(1.0f-m_buttonPressure/2.5f)*15.0f;
								if (m_pPlayer->DropItem(itemId, impulseScale, true) && pOffHand && pOffHand->IsSelected())
								{							
									if (EntityId fistsId = pInventory->GetItemByClass(CItem::sFistsClass))
									{
										m_pPlayer->SelectItem(fistsId, false);
									}
									pOffHand->PreExecuteAction(eOHA_REINIT_WEAPON, eAAM_OnPress);
									CItem* pItem = static_cast<CItem*>(m_pPlayer->GetCurrentItem());
									if (pItem)
									{
										pItem->SetActionSuffix("akimbo_");
										pItem->PlayAction(g_pItemStrings->idle);
									}
								}
							}
						}
						else if (actions.nextitem==actionId)
							m_pPlayer->SelectNextItem(1, true, 0);
						else if (actions.previtem==actionId)
							m_pPlayer->SelectNextItem(-1, true, 0);
						else if (actions.handgrenade==actionId)
							m_pPlayer->SelectNextItem(1, true, actionId.c_str());
						else if (actions.explosive==actionId)
							m_pPlayer->SelectNextItem(1, true, actionId.c_str());
						else if (actions.utility==actionId)
							m_pPlayer->SelectNextItem(1, true, actionId.c_str());
						else if (actions.small==actionId)
							m_pPlayer->SelectNextItem(1, true, actionId.c_str());
						else if (actions.medium==actionId)
							m_pPlayer->SelectNextItem(1, true, actionId.c_str());
						else if (actions.heavy==actionId)
							m_pPlayer->SelectNextItem(1, true, actionId.c_str());
						else if (actions.debug==actionId)
						{
							if (g_pGame)
							{							
								if (!m_pPlayer->GetInventory()->GetItemByClass(CItem::sDebugGunClass))
									g_pGame->GetWeaponSystem()->DebugGun(0);				
								if (!m_pPlayer->GetInventory()->GetItemByClass(CItem::sRefWeaponClass))
									g_pGame->GetWeaponSystem()->RefGun(0);
							}

							m_pPlayer->SelectNextItem(1, true, actionId.c_str());
						}
					}
				}
				else 
				{
					if (actions.handgrenade==actionId)
						m_pPlayer->SelectNextItem(1, true, actionId.c_str());
					else if (actions.explosive==actionId)
						m_pPlayer->SelectNextItem(1, true, actionId.c_str());
					else if (actions.utility==actionId)
						m_pPlayer->SelectNextItem(1, true, actionId.c_str());
					else if (actions.small==actionId)
						m_pPlayer->SelectNextItem(1, true, actionId.c_str());
					else if (actions.medium==actionId)
						m_pPlayer->SelectNextItem(1, true, actionId.c_str());
					else if (actions.heavy==actionId)
						m_pPlayer->SelectNextItem(1, true, actionId.c_str());
					else if (actions.drop==actionId && activationMode == eAAM_OnRelease && itemId)
						m_pPlayer->DropItem(itemId, 1.0f, true);
				}
			}

			if (m_checkZoom)
			{
				if (pWeapon)
				{
					IZoomMode *zm = pWeapon->GetZoomMode(pWeapon->GetCurrentZoomMode());
					CScreenEffects* pScreenEffects = m_pPlayer->GetScreenEffects();
					if (zm && !zm->IsZoomingInOrOut() && !zm->IsZoomed() && pScreenEffects != 0)
					{
						if (!m_moveButtonState && m_pPlayer->IsClient())
						{
							IBlendedEffect *fovEffect	= CBlendedEffect<CFOVEffect>::Create(CFOVEffect(m_pPlayer->GetEntityId(),1.0f));
							IBlendType   *blend				= CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f));
							pScreenEffects->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomIn, false);
							pScreenEffects->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomOut, false);
							pScreenEffects->StartBlend(fovEffect, blend, 1.0f/.25f, CScreenEffects::eSFX_GID_ZoomIn);
						}
						else
						{
							pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_ZoomIn);
							pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_ZoomOut);
							pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_HitReaction);
						}
					}
				}
			}
		}
	}


	bool hudFilterOut = true;

	// FIXME: temporary method to dispatch Actions to HUD (it's not yet possible to register)
	hudFilterOut = true;

	//Filter must take into account offHand too
	COffHand* pOffHand = static_cast<COffHand*>(m_pPlayer->GetWeaponByClass(CItem::sOffHandClass));
	if(pOffHand && pOffHand->IsSelected())
		filterOut = false;

	//send the onAction to scripts, after filter the range of actions. for now just use and hold
	if (filterOut && hudFilterOut)
	{
		FRAME_PROFILER("Script Processing", GetISystem(), PROFILE_GAME);
		HSCRIPTFUNCTION scriptOnAction(NULL);

		IScriptTable *scriptTbl = m_pPlayer->GetEntity()->GetScriptTable();

		if (scriptTbl)
		{
			scriptTbl->GetValue("OnAction", scriptOnAction);

			if (scriptOnAction)
			{
				char *activation = 0;

				switch(activationMode)
				{
				case eAAM_OnHold:
					activation = "hold";
					break;
				case eAAM_OnPress:
					activation = "press";
					break;
				case eAAM_OnRelease:
					activation = "release";
					break;
				default:
					activation = "";
					break;
				}

				Script::Call(gEnv->pScriptSystem,scriptOnAction,scriptTbl,actionId.c_str(),activation, value);
			}
		}

		gEnv->pScriptSystem->ReleaseFunc(scriptOnAction);
	}	
}
Exemple #30
0
//------------------------------------------------------------------------
void CCarryEntity::Attach( EntityId actorId )
{
    CPlayer *pPlayer = static_cast<CPlayer*>(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(actorId));
    if (pPlayer)
    {
        const bool bIsOwnerFP = !pPlayer->IsThirdPerson();
        IEntity *pPlayerEntity = pPlayer->GetEntity();

        IInventory *pInventory = pPlayer->GetInventory();
        m_previousWeaponId = pInventory->GetCurrentItem();
        if (m_previousWeaponId == m_spawnedWeaponId)
        {
            // Current item is the spawned weapon - this won't be happy so get the previous item instead
            m_previousWeaponId = pInventory->GetLastItem();
            if (m_previousWeaponId == m_spawnedWeaponId)
            {
                // Item is still the spawned weapon, can't have this so default to 0
                m_previousWeaponId = 0;
            }
        }

        // Get the secondary weapon id - if the player doesn't have one then use the spawned weapon
        EntityId secondaryWeaponId = pPlayer->SimpleFindItemIdInCategory("secondary");
        bool bIsSpawnedWeapon = false;
        if (secondaryWeaponId == 0)
        {
            secondaryWeaponId = m_spawnedWeaponId;
            bIsSpawnedWeapon = true;
        }

        bool bDoAttach = true;
        // If swimming attach here - DT#17176 Picking up relay/tick while swimming was reverting to main weapon instead of primary when leaving water, and not hiding attached item.
        if (pPlayer->IsSwimming())
        {
            AttachmentUtils::AttachObject( bIsOwnerFP, pPlayerEntity, GetEntity(), CARRYENTITY_ATTACHMENT_NAME );
            bDoAttach = false;
        }

        EntityId holsteredId = pInventory->GetHolsteredItem();
        if (holsteredId)
        {
            if (pPlayer->IsClient())
            {
                pPlayer->HideLeftHandObject(true);
            }
            m_cachedLastItemId = holsteredId;
            pInventory->SetHolsteredItem(secondaryWeaponId);

            if (gEnv->bServer && bIsSpawnedWeapon)
            {
                pPlayer->PickUpItem(secondaryWeaponId, false, false);
            }
        }
        else
        {
            pPlayer->CancelScheduledSwitch();
            if (!bIsSpawnedWeapon)
            {
                pPlayer->SelectItem(secondaryWeaponId, true, true);
            }
            else if (gEnv->bServer)
            {
                pPlayer->PickUpItem(secondaryWeaponId, false, true);
            }
        }


        m_bSpawnedWeaponAttached = bIsSpawnedWeapon;

        pPlayer->EnableSwitchingItems(false);
        pPlayer->EnableIronSights(false);
        pPlayer->EnablePickingUpItems(false);

        pPlayer->SetTagByCRC( m_playerTagCRC, true );

        if(bDoAttach)
        {
            // If not swimming, attach here !B DT10978 Fix for issues with left handed weapons and picking up relays/extraction ticks. We now start the weapon switch prior to attaching the objective so that the left handed weapon doesn't clear it from the left hand
            AttachmentUtils::AttachObject( bIsOwnerFP, pPlayerEntity, GetEntity(), CARRYENTITY_ATTACHMENT_NAME );
        }
    }

    m_attachedActorId = actorId;
}