本文整理汇总了C++中IActor::GetInventory方法的典型用法代码示例。如果您正苦于以下问题:C++ IActor::GetInventory方法的具体用法?C++ IActor::GetInventory怎么用?C++ IActor::GetInventory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IActor
的用法示例。
在下文中一共展示了IActor::GetInventory方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessEvent
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
if (event == eFE_Activate || event == eFE_Initialize)
{
if (IsPortActive(pActInfo, INP_ACTIVE))
{
bool active = GetPortBool(pActInfo, 0);
if (active)
m_pGF->GetIItemSystem()->RegisterListener(this);
else
m_pGF->GetIItemSystem()->UnregisterListener(this);
}
if (IsPortActive(pActInfo, INP_CHECK))
{
IActor* pActor = GetInputActor( pActInfo );
if (pActor)
{
IInventory* pInventory = pActor->GetInventory();
if (pInventory)
{
IEntity* pEntityItem = gEnv->pEntitySystem->GetEntity( pInventory->GetCurrentItem() );
TriggerOutputs( pActInfo, pEntityItem );
}
}
}
}
}
开发者ID:NightOwlsEntertainment,项目名称:PetBox_A_Journey_to_Conquer_Elementary_Algebra,代码行数:27,代码来源:FlowInventoryNodes.cpp
示例2: RefGun
//------------------------------------------------------------------------
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(!gEnv->IsEditor())
return;
itemId = pItemSystem->GiveItem(pActor, CItem::sRefWeaponClass->GetName(), false, true, true);
}
pItemSystem->SetActorItem(pActor, itemId, true);
}
示例3: ProcessEvent
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);
}
}
}
}
示例4: GetInputActor
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);
}
}
示例5: 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;
}
}
示例6: HandleSequenceEvent
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;
}
}
示例7: CheckAmmoRestrictions
//--------------------------------------------
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;
}
示例8: 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));
}
}
}
}
示例9: PickUp
void CJaw::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char* setup)
{
for (TAmmoVector::iterator it = m_bonusammo.begin(); it != m_bonusammo.end(); ++it)
{
SWeaponAmmo& currentBonusAmmo = *it;
currentBonusAmmo.count = 0;
}
IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
IActor* pPicketActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pickerId);
IInventory* pInventory = pPicketActor->GetInventory();
bool giveExtraTube = GiveExtraTubeToInventory(pPicketActor, pItemSystem);
if (pPicketActor->IsClient())
SetAmmoCount(m_fm->GetAmmoType(), 1);
BaseClass::PickUp(pickerId,sound,select,keepHistory, setup);
if (giveExtraTube)
{
int numJaws = m_weaponsharedparams->ammoParams.extraItems;
while(numJaws-- > 0)
{
pItemSystem->GiveItem(pPicketActor, GetEntity()->GetClass()->GetName(), false, false, false);
}
m_extraTubesAdded = true;
}
if(m_auxSlotUsed)
{
DrawSlot(eIGS_ThirdPersonAux,false);
m_auxSlotUsed = false;
}
if(GetOwnerActor() && !GetOwnerActor()->IsPlayer())
m_stats.first_selection = false;
}
示例10: UpdateCrosshair
void CHUDCrosshair::UpdateCrosshair()
{
IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
if(!pClientActor)
return;
int iNewFriendly = 0;
if(pClientActor->GetLinkedVehicle())
{
// JanM/MichaelR:
// Get status from the VehicleWeapon, which raycasts considering the necessary SkipEntities (in contrast to WorldQuery)
// Julien: this is now done in MP as well
iNewFriendly = g_pHUD->GetVehicleInterface()->GetFriendlyFire();
}
else
{
if(!gEnv->bMultiplayer)
{
CWeapon *pWeapon = g_pHUD->GetCurrentWeapon();
if(pWeapon)
{
iNewFriendly = pWeapon->IsWeaponLowered() && pWeapon->IsPendingFireRequest();
if(iNewFriendly && pWeapon->GetEntity()->GetClass() == CItem::sTACGunFleetClass)
iNewFriendly = 0;
}
else{
//Two handed pickups need the red X as well
CPlayer *pPlayer= static_cast<CPlayer*>(pClientActor);
if(CWeapon *pOffHand = static_cast<CWeapon*>(pPlayer->GetItemByClass(CItem::sOffHandClass)))
iNewFriendly = pOffHand->IsWeaponLowered();
}
}
else
{
EntityId uiCenterId = pClientActor->GetGameObject()->GetWorldQuery()->GetLookAtEntityId();
if(uiCenterId)
{
iNewFriendly = IsFriendlyEntity(gEnv->pEntitySystem->GetEntity(uiCenterId));
}
}
}
// SNH: if player is carrying a claymore or mine, ask the weapon whether it is possible to place it currently
// (takes into account player speed / stance / aim direction).
// So 'friendly' is a bit of a misnomer here, but we want the "don't/can't fire" crosshair...
if(iNewFriendly != 1 && g_pHUD)
{
CWeapon *pWeapon = g_pHUD->GetCurrentWeapon();
if(pWeapon)
{
static IEntityClass* pClaymoreClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("Claymore");
static IEntityClass* pAVMineClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("AVMine");
IEntityClass* pClass = pWeapon->GetEntity()->GetClass();
if(pClass == pClaymoreClass || pClass == pAVMineClass)
{
if(IFireMode* pfm = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()))
{
if(!pfm->IsFiring())
iNewFriendly = pWeapon->CanFire() ? 0 : 1;
}
}
}
}
if(iNewFriendly != m_iFriendlyTarget)
{
m_iFriendlyTarget = iNewFriendly;
//m_animCrossHair.Invoke("setFriendly", m_iFriendlyTarget);
if(iNewFriendly)
m_animFriendCross.SetVisible(true);
else
m_animFriendCross.SetVisible(false);
}
if(m_animInterActiveIcons.GetVisible())
{
m_bHideUseIconTemp = false;
CItem *pItem = static_cast<CItem*>(pClientActor->GetCurrentItem());
if(pItem)
{
IWeapon *pWeapon = pItem->GetIWeapon();
if(pWeapon)
{
CItem::SStats stats = pItem->GetStats();
if(stats.mounted && stats.used)
m_bHideUseIconTemp = true;
}
}
if(!m_bHideUseIconTemp)
{
EntityId offHandId = pClientActor->GetInventory()->GetItemByClass(CItem::sOffHandClass);
IItem *pOffHandItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(offHandId);
if(pOffHandItem)
{
COffHand *pOffHand = static_cast<COffHand*>(pOffHandItem);
uint32 offHandState = pOffHand->GetOffHandState();
if(offHandState == eOHS_HOLDING_OBJECT || offHandState == eOHS_THROWING_OBJECT ||
offHandState == eOHS_HOLDING_NPC || offHandState == eOHS_THROWING_NPC)
m_bHideUseIconTemp = true;
//.........这里部分代码省略.........
示例11: OnInitiate
//------------------------------------------------------------------------
bool CGameRules::OnInitiate(SHostMigrationInfo& hostMigrationInfo, uint32& state)
{
if (!g_pGame->GetIGameFramework()->ShouldMigrateNub(hostMigrationInfo.m_session))
{
return true;
}
CryLog("[Host Migration]: CGameRules::OnInitiate() Saving character for host migration started");
m_hostMigrationClientHasRejoined = false;
IEntityScriptProxy* pScriptProxy = static_cast<IEntityScriptProxy*>(GetEntity()->GetProxy(ENTITY_PROXY_SCRIPT));
if (pScriptProxy)
{
if (string(pScriptProxy->GetState()) == "InGame")
{
m_hostMigrationTimeSinceGameStarted = (m_cachedServerTime - m_gameStartedTime);
}
}
HostMigrationStopAddingPlayers();
if (gEnv->IsClient())
{
if (!m_pHostMigrationParams)
{
m_pHostMigrationParams = new SHostMigrationClientRequestParams();
m_pHostMigrationClientParams = new SHostMigrationClientControlledParams();
}
IActor *pPlayer = g_pGame->GetIGameFramework()->GetClientActor();
if (pPlayer)
{
m_pHostMigrationClientParams->m_viewQuat = pPlayer->GetViewRotation();
m_pHostMigrationClientParams->m_position = pPlayer->GetEntity()->GetPos();
pe_status_living livStat;
IPhysicalEntity *pPhysicalEntity = pPlayer->GetEntity()->GetPhysics();
if (pPhysicalEntity != NULL && (pPhysicalEntity->GetType() == PE_LIVING) && (pPhysicalEntity->GetStatus(&livStat) > 0))
{
m_pHostMigrationClientParams->m_velocity = livStat.velUnconstrained;
m_pHostMigrationClientParams->m_hasValidVelocity = true;
CryLog(" velocity={%f,%f,%f}", m_pHostMigrationClientParams->m_velocity.x, m_pHostMigrationClientParams->m_velocity.y, m_pHostMigrationClientParams->m_velocity.z);
}
IInventory *pInventory = pPlayer->GetInventory();
m_pHostMigrationClientParams->m_numExpectedItems = 0;
int numAmmoTypes = 0;
m_pHostMigrationClientParams->m_pAmmoParams = new SHostMigrationClientControlledParams::SAmmoParams[numAmmoTypes];
m_pHostMigrationClientParams->m_numAmmoParams = numAmmoTypes;
/*CryLog(" player has %i different ammo types", numAmmoTypes);
for (int i = 0; i < numAmmoTypes; ++ i)
{
IEntityClass *pAmmoType = pInventory->GetAmmoType(i);
int ammoCount = pInventory->GetAmmoCount(pAmmoType);
m_pHostMigrationClientParams->m_pAmmoParams[i].m_pAmmoClass = pAmmoType;
m_pHostMigrationClientParams->m_pAmmoParams[i].m_count = ammoCount;
CryLog(" %s : %i", pAmmoType->GetName(), ammoCount);
}*
EntityId holseredItemId = pInventory->GetHolsteredItem();
if (holseredItemId)
{
IEntity *pHolsteredEntity = gEnv->pEntitySystem->GetEntity(holseredItemId);
if (pHolsteredEntity)
{
m_pHostMigrationClientParams->m_pHolsteredItemClass = pHolsteredEntity->GetClass();
}
}*/
IMovementController *pMovementController = pPlayer->GetMovementController();
if(pMovementController)
{
SMovementState movementState;
pMovementController->GetMovementState(movementState);
m_pHostMigrationClientParams->m_aimDirection = movementState.aimDirection;
}
/*CItem *pItem = static_cast<CItem*>(pPlayer->GetCurrentItem());
if (pItem)
{
m_pHostMigrationClientParams->m_pSelectedItemClass = pItem->GetEntity()->GetClass();
CryLog(" currently using item '%s", pItem->GetEntity()->GetName());
}*/
}
else
{
CRY_ASSERT_MESSAGE(false, "Failed to find client actor when initiating a host migration");
gEnv->pNetwork->TerminateHostMigration(hostMigrationInfo.m_session);
return false;
}
}
//.........这里部分代码省略.........
示例12: if
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);
}
}
示例13: Update
void CHUDCrosshair::Update(float fDeltaTime)
{
if(m_bBroken)
return;
IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
IItemSystem *pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
if(!pClientActor || !pItemSystem)
return;
IInventory *pInventory = pClientActor->GetInventory();
if(!pInventory)
return;
IItem *pItem = pItemSystem->GetItem(pInventory->GetCurrentItem());
IWeapon *pWeapon = NULL;
IWeapon *pSlaveWeapon = NULL;
const float fAlternateIronSight = 0.03f;
if(pItem)
{
pWeapon = pItem->GetIWeapon();
if(pItem->IsDualWieldMaster())
{
if(IItem *pSlave=pItem->GetDualWieldSlave())
pSlaveWeapon = pSlave->GetIWeapon();
}
}
else if(IVehicle *pVehicle=pClientActor->GetLinkedVehicle())
{
pItem = pItemSystem->GetItem(pVehicle->GetCurrentWeaponId(pClientActor->GetEntityId()));
if(pItem)
pWeapon = pItem->GetIWeapon();
}
if(pWeapon)
{
float fMinSpread = 0.0f;
float fMaxSpread = 0.0f;
m_spread = 0.0f;
if(IFireMode *pFireMode=pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()))
{
fMinSpread = pFireMode->GetMinSpread();
fMaxSpread = pFireMode->GetMaxSpread();
m_spread = pFireMode->GetSpread();
}
if(pSlaveWeapon)
{
if(IFireMode *pSlaveFireMode=pSlaveWeapon->GetFireMode(pSlaveWeapon->GetCurrentFireMode()))
{
fMinSpread += pSlaveFireMode->GetMinSpread();
fMaxSpread += pSlaveFireMode->GetMaxSpread();
m_spread += pSlaveFireMode->GetSpread();
}
}
CPlayer *pPlayer = static_cast<CPlayer*>(pClientActor);
if(pPlayer && pPlayer->GetNanoSuit() && pPlayer->GetNanoSuit()->GetMode() == NANOMODE_STRENGTH)
m_spread *=0.5;
if(g_pGameCVars->hud_iAlternateCrosshairSpread)
{
if(m_spread < fMinSpread)
m_spread = min(m_spread,g_pGameCVars->hud_fAlternateCrosshairSpreadCrouch) / g_pGameCVars->hud_fAlternateCrosshairSpreadCrouch;
else
m_spread = min(m_spread,g_pGameCVars->hud_fAlternateCrosshairSpreadNeutral) / g_pGameCVars->hud_fAlternateCrosshairSpreadNeutral;
}
else
{
m_spread = min((m_spread-fMinSpread),15.0f) / 15.0f;
IZoomMode *pZoomMode = pWeapon->GetZoomMode(pWeapon->GetCurrentZoomMode());
if(pZoomMode && !pZoomMode->IsToggle() && (pZoomMode->IsZoomed() || pZoomMode->IsZooming()))
{
m_spread -= fAlternateIronSight;
}
else
{
m_spread = min(m_spread,1.0f);
m_spread = max(m_spread,0.0f);
}
}
}
if(m_animCrossHair.GetVisible() && !g_pHUD->InSpectatorMode())
{
//also disables the damage indicator
if(/*g_pGameCVars->hud_crosshair>0 && m_iCrosshair > 0 &&*/ (g_pGameCVars->g_difficultyLevel<4 || gEnv->bMultiplayer))
{
m_animCrossHair.GetFlashPlayer()->Advance(fDeltaTime);
m_animCrossHair.GetFlashPlayer()->Render();
}
//.........这里部分代码省略.........