本文整理汇总了C++中CActor::GetInventory方法的典型用法代码示例。如果您正苦于以下问题:C++ CActor::GetInventory方法的具体用法?C++ CActor::GetInventory怎么用?C++ CActor::GetInventory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActor
的用法示例。
在下文中一共展示了CActor::GetInventory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetOwnerActor
//------------------------------------------------------------------------
bool CC4::CanSelect() const
{
bool canSelect = (CWeapon::CanSelect() && !OutOfAmmo(false));
//Check for remaining projectiles to detonate
if(!canSelect)
{
CActor *pOwner = GetOwnerActor();
if(!pOwner)
return false;
EntityId detonatorId = pOwner->GetInventory()?pOwner->GetInventory()->GetItemByClass(CItem::sDetonatorClass):0;
//Do not re-select detonator again
if(detonatorId && (detonatorId==pOwner->GetCurrentItemId()))
return false;
IFireMode *pFM = GetFireMode(GetCurrentFireMode());
if(pFM)
{
//CC4::Select will select the detonator in this case
EntityId projectileId = pFM->GetProjectileId();
if(projectileId && g_pGame->GetWeaponSystem()->GetProjectile(projectileId))
return true;
}
}
return canSelect;
};
示例2: GetOwnerActor
//------------------------------------------------------------------------
void CC4::Drop(float impulseScale, bool selectNext, bool byDeath)
{
EntityId fistsId = 0;
CActor *pOwner = GetOwnerActor();
if(pOwner)
fistsId = pOwner->GetInventory()?pOwner->GetInventory()->GetItemByClass(CItem::sFistsClass):0;
CItem::Drop(impulseScale,selectNext,byDeath);
if (fistsId)
pOwner->SelectItem(fistsId,true);
}
示例3: PostSerialize
void CJaw::PostSerialize()
{
BaseClass::PostSerialize();
if(m_auxSlotUsed)
{
SetViewMode(0);
DrawSlot(eIGS_ThirdPersonAux,true);
}
else if (GetOwner() != 0 && !IsAttachedToBack() && !IsAttachedToHand())
{
Hide(true);
}
else if (!IsOwnerFP())
{
SetViewMode(eIVM_ThirdPerson);
DrawSlot(eIGS_ThirdPerson, true);
DrawSlot(eIGS_ThirdPersonAux,false);
}
if (m_smokeActive)
{
Pickalize(false, true);
}
if (GetOwner() != 0)
{
CActor* pOwner = GetOwnerActor();
IInventory* pInventory = pOwner ? pOwner->GetInventory() : 0;
UnregisterUsedAmmoWithInventory(pInventory);
RegisterUsedAmmoWithInventory(pInventory);
}
}
示例4: SetInventoryAmmo
//------------------------------------------------------------------------
int CScriptBind_Actor::SetInventoryAmmo(IFunctionHandler *pH, const char *ammo, int amount)
{
CActor * pActor = GetActor(pH);
if (!pActor)
return pH->EndFunction();
IInventory *pInventory=pActor->GetInventory();
if (!pInventory)
return pH->EndFunction();
IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammo);
assert(pClass);
int capacity = pInventory->GetAmmoCapacity(pClass);
int current = pInventory->GetAmmoCount(pClass);
if((!gEnv->IsEditor()) && (amount > capacity))
{
//If still there's some place, full inventory to maximum...
if(current<capacity)
{
pInventory->SetAmmoCount(pClass,capacity);
if (gEnv->bServer)
pActor->GetGameObject()->InvokeRMI(CActor::ClSetAmmo(), CActor::AmmoParams(ammo, amount), eRMI_ToRemoteClients);
}
}
else
{
pInventory->SetAmmoCount(pClass, amount);
if (gEnv->bServer)
pActor->GetGameObject()->InvokeRMI(CActor::ClSetAmmo(), CActor::AmmoParams(ammo, amount), eRMI_ToRemoteClients);
}
return pH->EndFunction();
}
示例5: AddInventoryAmmo
//------------------------------------------------------------------------
int CScriptBind_Actor::AddInventoryAmmo(IFunctionHandler *pH, const char *ammo, int amount)
{
CActor * pActor = GetActor(pH);
if (!pActor)
return pH->EndFunction();
IInventory *pInventory=pActor->GetInventory();
if (!pInventory)
return pH->EndFunction();
IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammo);
assert(pClass);
int capacity = pInventory->GetAmmoCapacity(pClass);
int current = pInventory->GetAmmoCount(pClass);
if((!gEnv->pSystem->IsEditor()) && (amount > capacity))
{
if(pActor->IsClient())
SAFE_HUD_FUNC(DisplayFlashMessage("@ammo_maxed_out", 2, ColorF(1.0f, 0,0), true, (string("@")+pClass->GetName()).c_str()));
//If still there's some place, full inventory to maximum...
if(current<capacity)
{
pInventory->SetAmmoCount(pClass,capacity);
if(pActor->IsClient() && capacity - current > 0)
{
/*char buffer[5];
itoa(capacity - current, buffer, 10);
SAFE_HUD_FUNC(DisplayFlashMessage("@grab_ammo", 3, Col_Wheat, true, (string("@")+pClass->GetName()).c_str(), buffer));*/
if(g_pGame->GetHUD())
g_pGame->GetHUD()->DisplayAmmoPickup(pClass->GetName(), capacity - current);
}
if (gEnv->bServer)
pActor->GetGameObject()->InvokeRMI(CActor::ClAddAmmo(), CActor::AmmoParams(ammo, amount), eRMI_ToRemoteClients);
}
}
else
{
pInventory->SetAmmoCount(pClass, amount);
if(pActor->IsClient() && amount - current > 0)
{
/*char buffer[5];
itoa(amount - current, buffer, 10);
SAFE_HUD_FUNC(DisplayFlashMessage("@grab_ammo", 3, Col_Wheat, true, (string("@")+pClass->GetName()).c_str(), buffer));*/
if(g_pGame->GetHUD())
g_pGame->GetHUD()->DisplayAmmoPickup(pClass->GetName(), amount - current);
}
if (gEnv->bServer)
pActor->GetGameObject()->InvokeRMI(CActor::ClAddAmmo(), CActor::AmmoParams(ammo, amount), eRMI_ToRemoteClients);
}
return pH->EndFunction();
}
示例6: OutOfAmmo
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;
}
示例7: GetInventoryAmmo
//------------------------------------------------------------------------
int CScriptBind_Actor::GetInventoryAmmo(IFunctionHandler *pH, const char *ammo)
{
CActor * pActor = GetActor(pH);
if (!pActor)
return pH->EndFunction();
IInventory *pInventory=pActor->GetInventory();
if (!pInventory)
return pH->EndFunction();
IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammo);
assert(pClass);
return pH->EndFunction(pInventory->GetAmmoCount(pClass));
}
示例8: SwitchToMeleeWeaponAndAttack
bool CMelee::SwitchToMeleeWeaponAndAttack()
{
// Checking for the equipped MeleeWeapon for each melee is hateful, but there's nowhere to check the inventory when a weapon is equipped.
CActor* pOwner = m_pWeapon->GetOwnerActor();
if( pOwner && (pOwner->GetInventory()->GetItemByClass( CItem::sWeaponMeleeClass ) != 0) )
{
m_pWeapon->SetPlaySelectAction( false );
pOwner->SelectItemByName( "WeaponMelee", true );
// trigger the attack - should be good without ptr checks, we validated that the weapon exists in the inventory.
pOwner->GetCurrentItem()->GetIWeapon()->MeleeAttack();
return true;
}
return false;
}
示例9: Drop
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);
}
}
示例10: AddAmmoCapacity
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);
}
}
示例11: NetSetOwnerId
//------------------------------------------------------------------------
void CItem::NetSetOwnerId(EntityId id)
{
if (id == m_ownerId)
{
return;
}
CryLogAlways("%s::NetSetOwnerId(%s)", GetEntity()->GetName(), GetActor(id) ? GetActor(id)->GetEntity()->GetName() : "null");
if (id)
{
PickUp(id, true);
}
else
{
Drop();
CActor *pActor = GetOwnerActor();
if (pActor)
{
pActor->GetInventory()->SetCurrentItem(0);
}
}
}
示例12: DoAutoDrop
void CJaw::DoAutoDrop()
{
if(!m_playedDropAction && m_fm)
{
m_firedRockets--;
CActor* pOwner = GetOwnerActor();
// no need to auto-drop for AI
if(pOwner && !pOwner->IsPlayer())
return;
if((GetAmmoCount(m_fm->GetAmmoType())<=0)&&(m_firedRockets<=0))
{
if( pOwner )
{
uint8 uniqueId = m_pItemSystem->GetItemUniqueId(GetEntity()->GetClass()->GetName());
bool selectNext = pOwner->GetInventory()->GetCountOfUniqueId(uniqueId) <= 1;
PlayAction(GetFragmentIds().drop);
m_playedDropAction = true;
}
}
}
}
示例13: OnIncendiaryAmmoPickedUp
//----------------------------------------------------
void CAmmoPickup::OnIncendiaryAmmoPickedUp(IEntityClass *pClass,int count)
{
bool incendiary = (pClass == CItem::sIncendiaryAmmo);
if(incendiary && !gEnv->bMultiplayer)
{
CActor* pPlayer = GetOwnerActor();
if(!pPlayer)
return;
if(IInventory *pInventory = pPlayer->GetInventory())
{
if(pInventory->GetCountOfClass("FY71IncendiaryAmmo")==0)
{
const int clipSize = 30;
m_pItemSystem->GiveItem(pPlayer,"FY71IncendiaryAmmo",false,false,false);
int amount = count-clipSize;
amount = MAX(0,amount);
pInventory->SetAmmoCount(pClass,amount);
}
}
}
}
示例14: OnRecordedGameplayEvent
void CGameStateRecorder::OnRecordedGameplayEvent(IEntity *pEntity, const GameplayEvent &event, int currentFrame, bool bRecording)
{
EntityId id;
m_currentFrame = currentFrame;
int demo_forceGameState = 0;
if(!bRecording)
{
ICVar *pVar = gEnv->pConsole->GetCVar( "demo_force_game_state" );
if(pVar)
demo_forceGameState = pVar->GetIVal();
}
if(!pEntity || !(id = pEntity->GetId()))
return;
if(m_IgnoredEvents.size())
if(event.event == m_IgnoredEvents[0])
{
m_IgnoredEvents.erase(m_IgnoredEvents.begin());
return;
}
TGameStates::iterator itActor = m_GameStates.find(id);
if(itActor == m_GameStates.end())
{
m_GameStates.insert(std::make_pair(id,SActorGameState()));
itActor = m_GameStates.find(id);
}
if(itActor == m_GameStates.end())
{
GameWarning("TimeDemo:GameState: actor %s not found in records",pEntity->GetName());
return;
}
SActorGameState& gstate = itActor->second;
switch(event.event)
{
case eGE_HealthChanged:
{
gstate.health = event.value;
if(!m_bRecording)
{
CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id));
if(pActor)
{
if(m_bLogWarning)
{
if(CHECK_MISMATCH(pActor->GetHealth(), gstate.health,10))
{
if(!gstate.bHealthDifferent)
{
GameWarning("TimeDemo:GameState: Frame %d - Actor %s - HEALTH mismatch (%d, %d)",m_currentFrame,pEntity->GetName(), static_cast<int>(pActor->GetHealth()), static_cast<int>(gstate.health));
gstate.bHealthDifferent = true;
}
}
else
gstate.bHealthDifferent = false;
}
if( demo_forceGameState)
pActor->SetHealth(gstate.health);
}
}
}
break;
case eGE_WeaponFireModeChanged:
{
TItemName sel = (event.description);
if(sel)
{
TItemContainer& Items = gstate.Items;
TItemContainer::iterator iti = Items.find(sel);
uint8 recFireModeIdx = uint8(event.value);
if(iti != Items.end())
iti->second.fireMode = recFireModeIdx;
CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id));
if(pActor && pActor->GetInventory())
{
IItem* pItem = pActor->GetInventory()->GetItemByName(sel);
CWeapon* pWeapon;
if(pItem && (pWeapon = (CWeapon*)(pItem->GetIWeapon())))
{
int fireModeIdx = pWeapon->GetCurrentFireMode();
if(m_bLogWarning)
{
CheckDifference(recFireModeIdx,fireModeIdx,"TimeDemo:GameState: Frame %d - Actor %s - FIRE MODE mismatch for weapon %s (rec:%d, cur:%d)",pEntity,pItem->GetEntity() ? pItem->GetEntity()->GetName() : "(null)");
}
if(demo_forceGameState==2 && fireModeIdx!= recFireModeIdx)
pWeapon->SetCurrentFireMode(recFireModeIdx);
}
}
}
}
//.........这里部分代码省略.........
示例15: RenderInfo
float CGameStateRecorder::RenderInfo(float y, bool bRecording)
{
float retY = 0;
IRenderer *pRenderer = gEnv->pRenderer;
if (bRecording)
{
float fColor[4] = {1,0,0,1};
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Recording game state");
retY +=15;
}
else
{
const float xp = 300;
const float xr = 400;
const float xri = 600;
float fColor[4] = {0,1,0,1};
float fColorWarning[4] = {1,1,0,1};
const char* actorName = m_demo_actorInfo->GetString();
CActor *pActor = GetActorOfName(actorName);
if(pActor)
{
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Game state - Actor: %s --------------------------------------------------",pActor->GetEntity()? pActor->GetEntity()->GetName(): "(no entity)");
retY +=15;
if(m_itSingleActorGameState != m_GameStates.end() && pActor->GetEntity() && m_itSingleActorGameState->first == pActor->GetEntity()->GetId())
{
ICVar *pVar = gEnv->pConsole->GetCVar( "demo_force_game_state" );
if(pVar)
{
int demo_forceGameState = pVar->GetIVal();
if(demo_forceGameState)
{
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false,demo_forceGameState==1 ?
" Override mode = (health, suit energy)" : " Override mode = (all)");
retY +=15;
}
}
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColor,false,"Current");
pRenderer->Draw2dLabel( xr,y+retY, 1.3f, fColor,false,"Recorded");
retY +=15;
SActorGameState& gstate = m_itSingleActorGameState->second;
float recordedHealth = (float)gstate.health;
float health = (float)pActor->GetHealth();
bool bError = CHECK_MISMATCH(health, recordedHealth,10);
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Health:");
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, bError? fColorWarning : fColor, false,"%d",(int)health);
pRenderer->Draw2dLabel( xr,y+retY, 1.3f, bError? fColorWarning : fColor, false,"%d",(int)recordedHealth);
retY +=15;
// items
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Inventory ---------------------------------------------------------------------------------------");
retY +=15;
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColor,false,"Current");
pRenderer->Draw2dLabel( xri,y+retY, 1.3f, fColor,false,"Recorded");
retY +=15;
CInventory *pInventory = (CInventory*)(pActor->GetInventory());
if(pInventory)
{
int nInvItems = pInventory->GetCount();
TItemContainer& Items = gstate.Items;
int nRecItems = Items.size();
int maxItems = max(nRecItems,nInvItems);
int i=0;
EntityId curSelectedId = pActor->GetCurrentItemId();
TItemName curSelClass = GetItemName(curSelectedId);
bool bSelectedError = !equal_strings(gstate.itemSelected,curSelClass);
for(; i< nInvItems; i++)
{
IItem *pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pInventory->GetItem(i));
if(pItem)
{
TItemName szItemName = GetItemName(pItem->GetEntityId());
TItemContainer::iterator it = Items.find(szItemName);
bError = it==Items.end();
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," %2d)",i+1);
EntityId curId = pItem->GetEntityId();
TItemName curClass = GetItemName(curId);
if(equal_strings(curClass,curSelClass) )
pRenderer->Draw2dLabel( xp-16,y+retY, 1.3f,bSelectedError ? fColorWarning:fColor, false, "[]");
if(equal_strings(szItemName, gstate.itemSelected))
pRenderer->Draw2dLabel( xri-16,y+retY, 1.3f,bSelectedError ? fColorWarning:fColor, false, "[]");
char itemName[32];
const char* originalItemName = pItem->GetEntity() ? pItem->GetEntity()->GetName():"(null)";
int length = strlen(originalItemName);
length = min(length,31);
//.........这里部分代码省略.........