//------------------------------------------------------------------------ IMPLEMENT_RMI(CWeapon, SvRequestShoot) { CHECK_OWNER_REQUEST(); bool ok=true; CActor *pActor=GetActorByNetChannel(pNetChannel); if (!pActor || pActor->IsDead()) ok=false; if (ok) { m_fireCounter++; m_expended_ammo++; IActor *pLocalActor=m_pGameFramework->GetClientActor(); bool isLocal = pLocalActor && (pLocalActor->GetChannelId() == pActor->GetChannelId()); #ifdef SERVER_CHECKS const float fCurrentTime = gEnv->pTimer->GetAsyncCurTime(); const int kOldShotId = m_lastShotId; if(ShouldEndVerificationSample(fCurrentTime, params.shotId)) { EndVerificationSample(pActor, kOldShotId); StartVerificationSample(fCurrentTime); } m_fLastSampleTakenTime = fCurrentTime; m_fSampleNumShots += 1.0f; CPlayer * pPlayer = static_cast<CPlayer*>(pActor); pPlayer->GetShotCounter()->RecordShot(); #endif if (!isLocal) { NetShoot(params.hit, 0, params.fireModeId); } CHANGED_NETWORK_STATE(this, ASPECT_STREAM); } #ifdef SERVER_CHECKS CGameRules * pGameRules = static_cast<CGameRules*>(g_pGame->GetGameRules()); if(pGameRules) //really we should assert here. I struggle to think of a situation where someone is requesting a shot but there are no GameRules... { IGameRulesDamageHandlingModule * pDamageHandler = pGameRules->GetDamageHandlingModule(); assert(pDamageHandler); pDamageHandler->RegisterShotIdentification(pActor->GetEntityId(), this, params.shotId); } #endif return true; }
void CLocalPlayerComponent::UpdatePlayerLowHealthStatus( const float oldHealth ) { const float healthThrLow = g_pGameCVars->g_playerLowHealthThreshold; const float healthThrMid = g_pGameCVars->g_playerMidHealthThreshold; const float maxHealth = (float)m_rPlayer.GetMaxHealth(); const float minHealth = 0; const float currentHealth = m_rPlayer.m_health.GetHealth(); const bool isDead = m_rPlayer.m_health.IsDead(); CRY_ASSERT( maxHealth > minHealth ); //Extra 'mid-low' health sound hint if ((currentHealth <= healthThrMid) && (oldHealth > healthThrMid)) { m_rPlayer.PlaySound(CPlayer::ESound_EnterMidHealth); m_playedMidHealthSound = true; } else if ((oldHealth <= healthThrMid) && (currentHealth > healthThrMid) && m_playedMidHealthSound) { m_rPlayer.PlaySound(CPlayer::ESound_EnterMidHealth, false); m_rPlayer.PlaySound(CPlayer::ESound_ExitMidHealth); m_playedMidHealthSound = false; } if((currentHealth <= healthThrLow) && (oldHealth > healthThrLow)) { if(!isDead) { m_rPlayer.SetClientSoundmood(CPlayer::ESoundmood_LowHealth); } IAIObject* pAI = m_rPlayer.GetEntity()->GetAI(); if (pAI) { float mercyTimeScale = 1.0f; SAIEVENT aiEvent; aiEvent.fThreat = mercyTimeScale; pAI->Event(AIEVENT_LOWHEALTH, &aiEvent); CGameRules* pGameRules = g_pGame->GetGameRules(); if(pGameRules != NULL) { IGameRulesDamageHandlingModule* pDamageHandling = pGameRules->GetDamageHandlingModule(); if(pDamageHandling != NULL) { pDamageHandling->OnGameEvent(IGameRulesDamageHandlingModule::eGameEvent_LocalPlayerEnteredMercyTime); } } } } else if((currentHealth > healthThrLow) && (oldHealth <= healthThrLow)) { m_rPlayer.SetClientSoundmood(CPlayer::ESoundmood_Alive); } const float k_minDamageForHit = 10.0f; //this is partly to deal with small differences in health over the network if(!isDead && (currentHealth < oldHealth - k_minDamageForHit)) { m_rPlayer.SendMusicLogicEvent(eMUSICLOGICEVENT_PLAYER_WOUNDED); } const float defiantSkillKillLowHealth = maxHealth * g_pGameCVars->g_defiant_lowHealthFraction; if(currentHealth > defiantSkillKillLowHealth) { m_timeEnteredLowHealth = 0.f; } else if(m_timeEnteredLowHealth <= 0.f) { m_timeEnteredLowHealth = gEnv->pTimer->GetFrameStartTime(); } }