本文整理汇总了C++中CActor::GetCurrentItem方法的典型用法代码示例。如果您正苦于以下问题:C++ CActor::GetCurrentItem方法的具体用法?C++ CActor::GetCurrentItem怎么用?C++ CActor::GetCurrentItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActor
的用法示例。
在下文中一共展示了CActor::GetCurrentItem方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsCurrentItem
//------------------------------------------------------------------------
bool CItem::IsCurrentItem()
{
CActor *pOwner = GetOwnerActor();
if (!pOwner)
return false;
if (pOwner->GetCurrentItem() == this)
return true;
return false;
}
示例2: 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;
}
示例3: OnGameplayEvent
void CGameStateRecorder::OnGameplayEvent(IEntity *pEntity, const GameplayEvent &event)
{
EntityId id;
if(!pEntity || !(id = pEntity->GetId()))
{
GameWarning("TimeDemo:GameState::OnGamePlayEvent: Entity not found");
return;
}
CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id));
if(!pActor)
{
GameWarning("TimeDemo:GameState::OnGamePlayEvent: Entity %s has no actor", pEntity->GetName());
return;
}
GameplayEvent event2 = event;
event2.extra = 0;// event2 is the forwarded event, extra either will be not used by the listener or re-set as a string
uint8 eType = event.event;
bool bPlayer = (pActor->IsPlayer() && m_mode);
if(bPlayer || m_mode==GPM_AllActors)
{
//items
switch(eType)
{
case eGE_ItemPickedUp:
{
CheckInventory(pActor,0);//,*m_pRecordGameEventFtor);
}
break;
case eGE_ItemDropped:
{
TItemName itemName = GetItemName(EntityId(event.extra));
if(!itemName ) //if(itemIdx < 0)
break;
event2.description = itemName;
SendGamePlayEvent(pEntity,event2);
IEntity* pItemEntity = gEnv->pEntitySystem->FindEntityByName(itemName);
if(!pItemEntity)
break;
IItem* pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pItemEntity->GetId());
if(!pItem)
break;
IEntityClass* pItemClass = pItem->GetEntity()->GetClass();
if(pItemClass && !strcmpi(pItemClass->GetName(),"SOCOM"))
{
IItem* pCurrentItem = pActor->GetCurrentItem();
if(pCurrentItem)
{
IEntityClass* pCurrentItemClass = pCurrentItem->GetEntity()->GetClass();
if(pCurrentItemClass && !strcmpi(pCurrentItemClass->GetName(),"SOCOM"))
{
GameplayEvent event3;
event3.event = eGE_ItemSelected;
TItemName itemName = GetItemName(pCurrentItem->GetEntity()->GetId());
if(!itemName)
break;
event3.value = 0;
event3.description = (const char*)itemName;
SendGamePlayEvent(pEntity,event3);
}
}
}
}
break;
case eGE_WeaponFireModeChanged:
{
TItemName itemIdx = GetItemName(EntityId(event.extra));
if(!itemIdx)//if(itemIdx < 0)
break;
event2.description = (const char*)itemIdx;
SendGamePlayEvent(pEntity,event2);
}
break;
case eGE_ItemSelected:
{
EntityId itemId = EntityId(event.extra);
TItemName itemIdx = GetItemName(itemId);
if(itemId && !itemIdx)
break;
event2.value = 0;
event2.description = (const char*)itemIdx;
SendGamePlayEvent(pEntity,event2);
}
break;
case eGE_AttachedAccessory:
{
if(!IsGrenade(event.description)) // NOT OffHandGrenade
SendGamePlayEvent(pEntity,event2);
}
break;
case eGE_AmmoCount:
{
const char* itemIdx = event.description;
//.........这里部分代码省略.........
示例4: OnRecordedGameplayEvent
//.........这里部分代码省略.........
if(demo_forceGameState == 2)
pInventory->SetAmmoCount(pAmmoClass,it->second);
}
}
}
}
}
}
break;
case eGE_ItemSelected:
{
TItemName itemName = event.description;
gstate.itemSelected = itemName;
if(itemName)
{
if( !bRecording && (event.value > 0 || demo_forceGameState==2)) // EVENT.VALUE > 0 means initialization
{
CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id));
if(pActor && pActor->GetInventory())
{
IItem* pItem = pActor->GetInventory()->GetItemByName(itemName);
if(pItem)
pActor->SelectItem(pItem->GetEntityId(),false);
}
}
}
if(m_bLogWarning)
{
CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id));
if(pActor)
{
IItem* pItem = pActor->GetCurrentItem();
const char* curItemName= pItem && pItem->GetEntity() ? pItem->GetEntity()->GetName(): NULL;
CheckDifferenceString(itemName,curItemName,"TimeDemo:GameState: Frame %d - Actor %s - SELECTED ITEM mismatch (rec:%s, cur:%s)",pEntity);
}
}
break;
}
break;
case eGE_ItemExchanged:
{
// prevent unwanted record/play mismatch error with current item during item exchanging
// two unneeded game events are sent (selecting fists)
m_IgnoredEvents.push_back(eGE_ItemSelected);
m_IgnoredEvents.push_back(eGE_ItemSelected);
}
break;
case eGE_ItemPickedUp:
{
TItemName sel = (TItemName)event.description;
// gstate.itemSelected = sel;
TItemContainer& Items = gstate.Items;
TItemContainer::iterator it = Items.find(sel);
if(it == Items.end())
{
Items.insert(std::make_pair(sel,SItemProperties()));
it = Items.find(sel);
}
if(it != Items.end())
{
it->second.count++;
示例5: OnUsed
//------------------------------------------------------------------------
int CScriptBind_Item::OnUsed(IFunctionHandler *pH, ScriptHandle userId)
{
CItem *pItem = GetItem(pH);
if (!pItem)
return pH->EndFunction();
CActor *pActor = GetActor((EntityId)userId.n);
if (!pActor)
return pH->EndFunction();
if (pItem->CanUse((EntityId)userId.n))
{
if(IEntity* pParent = pItem->GetEntity()->GetParent())
{
IVehicle* pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(pParent->GetId());
if(pVehicle)
{
CPlayer* pPlayer = static_cast<CPlayer*>(pActor);
IInteractor* pInteractor = pPlayer->GetInteractor();
return pH->EndFunction( pVehicle->OnUsed((EntityId)userId.n, pInteractor->GetOverSlotIdx()) );
}
}
pActor->UseItem(pItem->GetEntityId());
return pH->EndFunction(true);
}
else if (pItem->CanPickUp((EntityId)userId.n))
{
//Should be always the client...
if (pActor->IsClient())
{
CPlayer* pClientPlayer = static_cast<CPlayer*>(pActor);
const SInteractionInfo& interactionInfo = pClientPlayer->GetCurrentInteractionInfo();
bool expectedItem = (interactionInfo.interactiveEntityId == pItem->GetEntityId());
bool expectedInteraction = (interactionInfo.interactionType == eInteraction_PickupItem) ||
(interactionInfo.interactionType == eInteraction_ExchangeItem);
if (!expectedItem || !expectedInteraction)
{
return pH->EndFunction();
}
if (interactionInfo.interactionType == eInteraction_ExchangeItem)
{
IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
CItem* pCurrentItem = static_cast<CItem*>(pActor->GetCurrentItem());
CItem* pExchangeItem = static_cast<CItem*>(pItemSystem->GetItem(interactionInfo.swapEntityId));
if (pExchangeItem && pCurrentItem)
pExchangeItem->ScheduleExchangeToNextItem(pActor, pItem, pCurrentItem);
}
else
{
pActor->PickUpItem(pItem->GetEntityId(), true, true);
}
}
else
{
pActor->PickUpItem(pItem->GetEntityId(), true, true);
}
return pH->EndFunction(true);
}
return pH->EndFunction();
}
示例6: ViewSpectatorTarget
void CPlayerView::ViewSpectatorTarget(SViewParams &viewParams)
{
CActor* pTarget = (CActor*)g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.stats_spectatorTarget);
if(!pTarget)
return;
IVehicle* pVehicle = pTarget->GetLinkedVehicle();
static float defaultOffset = 0.3f;
static float viewHeight = 1.8f;
Matrix34 worldTM = pTarget->GetEntity()->GetWorldTM();
Vec3 worldPos = worldTM.GetTranslation();
if(!pVehicle)
{
const SStanceInfo* stanceInfo = pTarget->GetStanceInfo(pTarget->GetStance());
if(stanceInfo)
{
Interpolate(viewHeight, stanceInfo->viewOffset.z, 5.0f, viewParams.frameTime);
worldPos.z += viewHeight + defaultOffset;
}
else
{
worldPos.z += 1.8f;
}
}
else
{
// use vehicle pos/ori
worldTM = pVehicle->GetEntity()->GetWorldTM();
worldPos = pVehicle->GetEntity()->GetWorldPos();
worldPos.z += 1.5f;
}
Ang3 worldAngles = Ang3::GetAnglesXYZ(Matrix33(worldTM));
float distance = 3;
// if freelook allowed, get orientation and distance from player entity
if(g_pGameCVars->g_spectate_FixedOrientation == 0)
{
CPlayer* pThisPlayer = static_cast<CPlayer*>(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.entityId));
if(!pThisPlayer)
return;
Matrix34 ownOrientation = pThisPlayer->GetEntity()->GetWorldTM();
worldAngles += Ang3::GetAnglesXYZ(Matrix33(ownOrientation));
distance = pThisPlayer->GetSpectatorZoom();
}
if(pVehicle)
{
distance *= 4.0f;
// air vehicles need bigger distance
if(pVehicle->GetMovement() && pVehicle->GetMovement()->GetMovementType() == IVehicleMovement::eVMT_Air)
distance *= 2.0f;
}
Vec3 goal;
goal.x = distance * cos(worldAngles.z + gf_PI*1.5f) + worldPos.x;
goal.y = distance * sin(worldAngles.z - gf_PI/2.0f) + worldPos.y;
AABB targetBounds;
pTarget->GetEntity()->GetLocalBounds(targetBounds);
goal.z = targetBounds.max.z;
float offset = defaultOffset;
if(pVehicle)
{
if(pVehicle->GetMovement() && pVehicle->GetMovement()->GetMovementType() == IVehicleMovement::eVMT_Air)
offset = 3.0f;
else
offset = 1.0f;
}
goal.z += pTarget->GetEntity()->GetWorldPos().z + offset;
// store / interpolate the offset, not the world pos (reduces percieved jitter in vehicles)
static Vec3 viewOffset(goal-worldPos);
static Vec3 camPos(goal);
static Vec3 entPos(worldPos);
static EntityId lastSpectatorTarget(m_in.stats_spectatorTarget);
// do a ray cast to check for camera intersection
static ray_hit hit;
IPhysicalEntity* pSkipEntities[10];
int nSkip = 0;
if(pVehicle)
{
// vehicle drivers don't seem to have current items, so need to add the vehicle itself here
nSkip = pVehicle->GetSkipEntities(pSkipEntities, 10);
}
else
{
IItem* pItem = pTarget->GetCurrentItem();
if (pItem)
{
CWeapon* pWeapon = (CWeapon*)pItem->GetIWeapon();
if (pWeapon)
nSkip = CSingle::GetSkipEntities(pWeapon, pSkipEntities, 10);
}
}
//.........这里部分代码省略.........
示例7: ViewSpectatorTarget
void CPlayerView::ViewSpectatorTarget(SViewParams &viewParams)
{
CActor *pTarget = (CActor *)g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.stats_spectatorTarget);
if(!pTarget)
{
return;
}
Matrix34 worldTM = pTarget->GetEntity()->GetWorldTM();
Vec3 worldPos = worldTM.GetTranslation();
worldPos.z += 1.5f;
Ang3 worldAngles = Ang3::GetAnglesXYZ(Matrix33(worldTM));
float rot = worldAngles.z;// + m_rot;
float distance = 3;//(m_defaultDistance != 0) ? m_defaultDistance : m_distance;
if(IVehicle *pVehicle = pTarget->GetLinkedVehicle())
{
AABB vehicleBox;
pVehicle->GetEntity()->GetLocalBounds(vehicleBox);
distance = 2.0f * vehicleBox.GetRadius();
}
Vec3 goal;
float zoom = 1.0f;
goal.x = distance * zoom * cosf(rot + gf_PI * 1.5f) + worldPos.x;
goal.y = distance * zoom * sinf(rot - gf_PI / 2.0f) + worldPos.y;
AABB targetBounds;
pTarget->GetEntity()->GetLocalBounds(targetBounds);
goal.z = targetBounds.max.z;
static float defaultOffset = 0.75f;
float offset = defaultOffset;
if(pTarget->GetLinkedVehicle())
{
offset = 2.0f;
}
goal.z += pTarget->GetEntity()->GetWorldPos().z + offset;
// store / interpolate the offset, not the world pos (reduces percieved jitter in vehicles)
static Vec3 viewOffset(goal - worldPos);
static Vec3 position(goal);
static Vec3 entPos(worldPos);
static EntityId lastSpectatorTarget(m_in.stats_spectatorTarget);
// do a ray cast to check for camera intersection
static ray_hit hit;
IPhysicalEntity *pSkipEntities[10];
int nSkip = 0;
IItem *pItem = pTarget->GetCurrentItem();
if (pItem)
{
CWeapon *pWeapon = (CWeapon *)pItem->GetIWeapon();
if (pWeapon)
{
nSkip = CSingle::GetSkipEntities(pWeapon, pSkipEntities, 10);
}
}
else if(IVehicle *pVehicle = pTarget->GetLinkedVehicle())
{
// vehicle drivers don't seem to have current items, so need to add the vehicle itself here
nSkip = pVehicle->GetSkipEntities(pSkipEntities, 10);
}
const float wallSafeDistance = 0.2f; // how far to keep camera from walls
Vec3 dir = goal - worldPos;
primitives::sphere sphere;
sphere.center = worldPos;
sphere.r = wallSafeDistance;
geom_contact *pContact = 0;
float hitDist = gEnv->pPhysicalWorld->PrimitiveWorldIntersection(sphere.type, &sphere, dir, ent_static | ent_terrain | ent_rigid | ent_sleeping_rigid,
&pContact, 0, geom_colltype_player, 0, 0, 0, pSkipEntities, nSkip);
// even when we have contact, keep the camera the same height above the target
float minHeightDiff = dir.z;
if(hitDist > 0 && pContact)
{
goal = worldPos + (hitDist * dir.GetNormalizedSafe());
if(goal.z - worldPos.z < minHeightDiff)
{
// can't move the camera far enough away from the player in this direction. Try moving it directly up a bit
sphere.center = goal;
// (move back just slightly to avoid colliding with the wall we've already found...)
sphere.center -= dir.GetNormalizedSafe() * 0.05f;
float newHitDist = gEnv->pPhysicalWorld->PrimitiveWorldIntersection(sphere.type, &sphere, Vec3(0, 0, minHeightDiff), ent_static | ent_terrain | ent_rigid | ent_sleeping_rigid,
&pContact, 0, geom_colltype_player, 0, 0, 0, pSkipEntities, nSkip);
float raiseDist = minHeightDiff - (goal.z - worldPos.z) - wallSafeDistance;
if(newHitDist != 0)
{
raiseDist = MIN(minHeightDiff, newHitDist);
}
raiseDist = MAX(0.0f, raiseDist);
goal.z += raiseDist;
worldPos.z += raiseDist * 0.8f;
}
}
//.........这里部分代码省略.........
示例8: StartUse
void CHeavyWeapon::StartUse(EntityId userId)
{
// holster user item here
SetOwnerId(userId);
CActor* pOwner = GetOwnerActor();
if (!pOwner)
return;
HighlightWeapon(false);
Physicalize(false, false);
if(gEnv->bMultiplayer)
{
m_properties.usable &= strlen(g_pGameCVars->g_forceHeavyWeapon->GetString()) == 0;
CHANGED_NETWORK_STATE(pOwner, CPlayer::ASPECT_CURRENT_ITEM);
}
if(IItem* pCurrentItem = pOwner->GetCurrentItem())
{
//Don't keep history if we're switching from Pick & Throw otherwsie we'll switch back to it when we're done with the heavy weapon
static IEntityClass* pPickAndThrowWeaponClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("PickAndThrowWeapon");
m_pItemSystem->SetActorItem(pOwner, GetEntityId(), pCurrentItem->GetEntity()->GetClass() != pPickAndThrowWeaponClass);
}
else
{
m_pItemSystem->SetActorItem(pOwner, GetEntityId(), true);
}
TriggerRespawn();
EnableUpdate(true, eIUS_General);
RequireUpdate(eIUS_General);
RegisterAsUser();
HandleHeavyWeaponPro(*pOwner);
m_stats.brandnew = false;
m_stats.used = true;
m_stats.detached = false;
if(IsClient() && gEnv->pGame->GetIGameFramework()->GetClientActorId()==userId)
{
if(IEntity* pEntity = GetEntity())
{
const char* collectibleId = pEntity->GetClass()->GetName();
CPersistantStats* pStats = g_pGame->GetPersistantStats();
if(pStats && pStats->GetStat(collectibleId, EMPS_SPWeaponByName) == 0)
{
pStats->SetMapStat(EMPS_SPWeaponByName, collectibleId, eDatabaseStatValueFlag_Available);
if(!gEnv->bMultiplayer)
{
// Show hud unlock msg
SHUDEventWrapper::DisplayWeaponUnlockMsg(collectibleId);
}
}
}
}
if (IsServer())
{
pOwner->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClStartUse(), CActor::ItemIdParam(GetEntityId()), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());
g_pGame->GetGameRules()->AbortEntityRemoval(GetEntityId());
}
OnStartUsing();
}