Exemple #1
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		if(eFE_Activate == event)
		{
			const bool bAttach = IsPortActive(pActInfo, EIP_ATTACH);
			const bool bDetach = IsPortActive(pActInfo, EIP_DETACH);
			if (!bAttach && !bDetach)
				return;

			IActor* pActor = GetActor(pActInfo);
			if (pActor == 0)
				return;

			const string& className = GetPortString(pActInfo, EIP_WEAPON);

			CWeapon* pWeapon = static_cast<CWeapon*> ( className.empty() ? GetWeapon(pActor) : GetWeapon(pActor, className.c_str()) );
			if (pWeapon != 0)
			{
				ItemString acc = ItemString(GetPortString(pActInfo, EIP_ACCESSORY));
				if (bAttach && pWeapon->GetAccessory(acc) == 0)
				{
					pWeapon->SwitchAccessory(acc);
					ActivateOutput(pActInfo, EOP_ATTACHED, true);
				}
				else if (bDetach && pWeapon->GetAccessory(acc) != 0)
				{
					pWeapon->SwitchAccessory(acc);
					ActivateOutput(pActInfo, EOP_DETACHED, true);
				}
			}
		}
	}
Exemple #2
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		if(eFE_Activate == event && IsPortActive(pActInfo,0))
		{
			IActor* pActor = GetActor(pActInfo);
			if (pActor == 0)
				return;

			CWeapon* pWeapon = static_cast<CWeapon*> (GetWeapon(pActor));
			if (pWeapon != 0)
			{
				CItem* pAcc = pWeapon->GetAccessory(GetPortString(pActInfo, 1).c_str());
				if (pAcc != 0)
					ActivateOutput(pActInfo, 1, true); // [True]
				else
					ActivateOutput(pActInfo, 0, true); // [False]
			}
		}
	}
int CScriptBind_Weapon::GetAccessory(IFunctionHandler *pH, const char *accessoryName)
{
	CWeapon *pWeapon = GetWeapon(pH);
	if (!pWeapon)
		return pH->EndFunction();

	CItem *pItem = pWeapon->GetAccessory(accessoryName);					
	
	if(!pItem)
		return 0;

	IEntity *pEntity  = pItem->GetEntity();

	if(!pEntity)
		return 0;
	
	IScriptTable *pScriptTable = pEntity->GetScriptTable();

	return pH->EndFunction( pScriptTable );
}
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);

	}
}