当前位置: 首页>>代码示例>>C++>>正文


C++ IWeapon::GetAmmoCount方法代码示例

本文整理汇总了C++中IWeapon::GetAmmoCount方法的典型用法代码示例。如果您正苦于以下问题:C++ IWeapon::GetAmmoCount方法的具体用法?C++ IWeapon::GetAmmoCount怎么用?C++ IWeapon::GetAmmoCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWeapon的用法示例。


在下文中一共展示了IWeapon::GetAmmoCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ProcessEvent

	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;
		}
	}
开发者ID:aronarts,项目名称:FireNET,代码行数:49,代码来源:FlowWeaponNodes.cpp

示例2: ProcessEvent

	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));
				}
			}
		}
	}
开发者ID:aronarts,项目名称:FireNET,代码行数:44,代码来源:FlowWeaponNodes.cpp


注:本文中的IWeapon::GetAmmoCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。