void CHeavyMountedWeapon::Use(EntityId userId) { int frameID = gEnv->pRenderer->GetFrameID(); if (m_lastUsedFrame == frameID) return; m_lastUsedFrame = frameID; if (!m_owner.GetId()) { StartUse(userId); HighlightWeapon(false); } else if (m_owner.GetId() == userId) { if (m_rippedOff || m_rippingOff) { FinishRipOff(); DeselectAndDrop(userId); } else { StopUse(userId); } } }
void CHeavyWeapon::OnOwnClientEnteredGame() { //If we're registered it's because we want to highlight the weapon (Unless somebody has since picked it up) if(!GetOwner()) { HighlightWeapon(true); } }
IMPLEMENT_RMI(CHeavyWeapon, ClHeavyWeaponHighlighted) { if(g_pGame->GetIGameFramework()->GetClientActor() != NULL) { HighlightWeapon(true); } else { g_pGame->GetGameRules()->RegisterClientConnectionListener(this); } return true; }
void CHeavyMountedWeapon::PostInit( IGameObject * pGameObject ) { BaseClass::PostInit(pGameObject); if(gEnv->bMultiplayer && !gEnv->IsDedicated()) { if(g_pGame->GetIGameFramework()->GetClientActor() != NULL) { HighlightWeapon(true); } else { g_pGame->GetGameRules()->RegisterClientConnectionListener(this); //We unregister again once we received the event (in CHeavyWeapon::OnOwnClientEnteredGame) } } }
void CHeavyMountedWeapon::StopUse(EntityId userId) { UnRegisterAsUser(); if (m_rippedOff || m_rippingOff) { CActor *pActor = GetOwnerActor(); m_rippedOff = true; m_rippingOff = false; RemoveViewLimits(); BaseClass::StopUse(userId); if(pActor) { pActor->LockInteractor(GetEntityId(), false); } } else { CActor *pActor = GetOwnerActor(); if (!pActor) { return; } if (m_isFiring) { StopFire(); } DoRipOffPrompt(GetOwnerId(), false); SetViewMode(eIVM_ThirdPerson); DrawSlot(eIGS_ThirdPerson, true); if(gEnv->bMultiplayer) { HighlightWeapon(true); } //The use of CWeapon::StopUse() here and not BaseClass::StopUse() is deliberate; it avoids the '::Drop()' call that CHeavyWeapon makes CWeapon::StopUse(userId); } }
void CHeavyMountedWeapon::StartUse(EntityId userId) { HighlightWeapon(false); if(m_rippedOff) { m_stats.dropped = false; BaseClass::StartUse(userId); } else { CWeapon::StartUse(userId); if (IsOwnerFP()) { DrawSlot(eIGS_FirstPerson, true, true); } } RegisterAsUser(); CActor* pOwner = GetOwnerActor(); if (pOwner) { CHANGED_NETWORK_STATE(pOwner, CPlayer::ASPECT_CURRENT_ITEM); if (!m_rippedOff) { IPlayerInput* pPlayerInput = pOwner && pOwner->IsPlayer() ? static_cast<CPlayer*>(pOwner)->GetPlayerInput() : 0; if (pPlayerInput) pPlayerInput->ClearXIMovement(); } } m_expended_ammo = 0; }
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(); }
//------------------------------------------------------------------------ void CWeapon::OnDropped(EntityId actorId, bool ownerWasAI) { BROADCAST_WEAPON_EVENT(OnDropped, (this, actorId)); BaseClass::OnDropped(actorId, ownerWasAI); IEntity * pEntity = GetEntity(); if(gEnv->bServer) { bool removeWeapon = true; if(gEnv->bMultiplayer && GetParams().check_clip_size_after_drop) { TFireModeVector::const_iterator firemodesEndIt = m_firemodes.end(); for (TFireModeVector::const_iterator firemodeCit = m_firemodes.begin(); firemodeCit != firemodesEndIt && removeWeapon; ++firemodeCit) { const CFireMode* pFiremode = *firemodeCit; if (pFiremode) { IEntityClass* pFiremodeAmmo = pFiremode->GetAmmoType(); if (pFiremodeAmmo) { //only check the main ammo type given with the weapon if(SWeaponAmmoUtils::FindAmmoConst(m_weaponsharedparams->ammoParams.ammo, pFiremodeAmmo)) { int currentClipAmount = GetAmmoCount(pFiremodeAmmo); int clipSize = pFiremode->GetClipSize(); if(currentClipAmount > 0 && currentClipAmount >= clipSize) { removeWeapon = false; } } } } } } else { const bool outOfAmmo = OutOfAmmo(true) && !ownerWasAI; const bool removeOnDrop = GetSharedItemParams()->params.remove_on_drop; removeWeapon = !gEnv->pSystem->IsSerializingFile() && (outOfAmmo && removeOnDrop); } if(removeWeapon && GetParams().check_bonus_ammo_after_drop) { for(unsigned int i = 0; i < m_bonusammo.size(); ++i) { if(m_bonusammo[i].count > 0) { removeWeapon = false; break; } } } if(removeWeapon) { if(gEnv->IsEditor()) { pEntity->Hide(true); } else { gEnv->pEntitySystem->RemoveEntity(pEntity->GetId()); } } } uint32 flags = pEntity->GetFlags(); flags &= ~ENTITY_FLAG_NO_PROXIMITY; pEntity->SetFlags(flags); m_expended_ammo = 0; if(gEnv->bMultiplayer && (g_pGameCVars->i_highlight_dropped_weapons == 2) || (IsHeavyWeapon() && g_pGameCVars->i_highlight_dropped_weapons == 1)) { HighlightWeapon(true, true); } }
//------------------------------------------------------------------------ void CWeapon::OnPickedUp(EntityId actorId, bool destroyed) { BROADCAST_WEAPON_EVENT(OnPickedUp, (this, actorId, destroyed)); BaseClass::OnPickedUp(actorId, destroyed); GetEntity()->SetFlags(GetEntity()->GetFlags() | ENTITY_FLAG_NO_PROXIMITY); // bonus ammo is always put in the actor's inv if (!m_bonusammo.empty()) { for (TAmmoVector::iterator it = m_bonusammo.begin(); it != m_bonusammo.end(); ++it) { const SWeaponAmmo& currentBonusAmmo = *it; SetInventoryAmmoCount(currentBonusAmmo.pAmmoClass, GetInventoryAmmoCount(currentBonusAmmo.pAmmoClass)+currentBonusAmmo.count); } m_bonusammo.clear(); } if(GetISystem()->IsSerializingFile() == 1) return; CActor *pActor = GetActor(actorId); if (!pActor) return; // current ammo is only added to actor's inv, if we already have this weapon if (destroyed && m_sharedparams->params.unique) { for (TAmmoVector::iterator it = m_ammo.begin(); it!=m_ammo.end(); ++it) { //Only add ammo to inventory, if not accessory ammo (accessories give ammo already) const SWeaponAmmo& currentAmmo = *it; const SWeaponAmmo* pAccessoryAmmo = SWeaponAmmoUtils::FindAmmo(m_weaponsharedparams->ammoParams.accessoryAmmo, currentAmmo.pAmmoClass); if(pAccessoryAmmo != NULL) { SetInventoryAmmoCount(currentAmmo.pAmmoClass, GetInventoryAmmoCount(currentAmmo.pAmmoClass)+currentAmmo.count); } } } TestClipAmmoCountIsValid(); if (!gEnv->bServer && pActor->IsPlayer()) { IEntityClass* pCurrentAmmoClass = m_fm ? m_fm->GetAmmoType() : NULL; if (pCurrentAmmoClass) { //server has serialised the inventory count already if(IInventory* pInventory = GetActorInventory(GetOwnerActor())) { if(m_lastRecvInventoryAmmo > pInventory->GetAmmoCapacity(pCurrentAmmoClass)) { pInventory->SetAmmoCapacity(pCurrentAmmoClass, m_lastRecvInventoryAmmo); } SetInventoryAmmoCountInternal(pInventory, pCurrentAmmoClass, m_lastRecvInventoryAmmo); } } } if(gEnv->bMultiplayer) { HighlightWeapon(false); } m_expended_ammo = 0; }