float CMelee::GetOwnerStrength() const { CActor *pActor = m_pWeapon->GetOwnerActor(); if(!pActor) return 1.0f; IMovementController * pMC = pActor->GetMovementController(); if (!pMC) return 1.0f; float strength = 1.0f;//pActor->GetActorStrength(); if (pActor->GetActorClass() == CPlayer::GetActorClassType()) { CPlayer *pPlayer = (CPlayer *)pActor; if (CNanoSuit *pSuit = pPlayer->GetNanoSuit()) { ENanoMode curMode = pSuit->GetMode(); if (curMode == NANOMODE_STRENGTH) { strength = pActor->GetActorStrength(); strength = strength * (1.0f + 2.0f * pSuit->GetSlotValue(NANOSLOT_STRENGTH)*STRENGTH_MULT); } } } return strength; }
//------------------------------------------------------------------------ void CGameRulesMPDamageHandling::ProcessDeath( const HitInfo &hitInfo, CActor& rTarget ) { if(rTarget.GetActorClass() == CPlayer::GetActorClassType()) { m_pGameRules->KillPlayer(&rTarget, (hitInfo.type != CGameRules::EHitType::PunishFall), true, hitInfo); } }
//------------------------------------------------------------------------ void CMelee::NetShootEx(const Vec3 &pos, const Vec3 &dir, const Vec3 &vel, const Vec3 &hit, float extra, int ph) { CActor *pActor = m_pWeapon->GetOwnerActor(); if(!pActor) return; IMovementController * pMC = pActor->GetMovementController(); if (!pMC) return; float strength = 1.0f;//pActor->GetActorStrength(); if (pActor->GetActorClass() == CPlayer::GetActorClassType()) { CPlayer *pPlayer = (CPlayer *)pActor; if (CNanoSuit *pSuit = pPlayer->GetNanoSuit()) { ENanoMode curMode = pSuit->GetMode(); if (curMode == NANOMODE_STRENGTH) { strength = pActor->GetActorStrength(); strength = strength * (1.0f + 2.0f * pSuit->GetSlotValue(NANOSLOT_STRENGTH)*STRENGTH_MULT); } } } if (!PerformRayTest(pos, dir, strength, true)) if(!PerformCylinderTest(pos, dir, strength, true)) ApplyCameraShake(false); m_ignoredEntity = 0; m_meleeScale = 1.0f; }
//------------------------------------------------------------------------ float CGameRulesCommonDamageHandling::GetAIPlayerAgainstColliderEnergyScale(const IEntity& collider) const { const float energyScaleAgainstNonActor = 10.0f; const float energyScaleAgainstRagdoll = 50.0f; CActor* pColliderActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(collider.GetId())); if (pColliderActor) { uint8 physicsAspectProfile = pColliderActor->GetGameObject()->GetAspectProfile(eEA_Physics) ; if ((physicsAspectProfile == eAP_Ragdoll) || (physicsAspectProfile == eAP_Sleep)) { return energyScaleAgainstRagdoll; } if (pColliderActor->GetActorClass() == CPlayer::GetActorClassType()) { SPlayerStats* pColliderStats = static_cast<SPlayerStats*>(pColliderActor->GetActorStats()); if (pColliderStats != NULL && pColliderStats->followCharacterHead) { return 0.0f; } } } return energyScaleAgainstNonActor; }
void CFlowNode_SimulateInput::ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo) { if(event == eFE_Activate) { bool isPressPort = IsPortActive(pActInfo, eInputPorts_Press); bool isReleasePort = IsPortActive(pActInfo, eInputPorts_Release); bool isHoldPort = IsPortActive(pActInfo, eInputPorts_Hold); bool triggerResponse = false; int playerInputEvent; int nodeOutput; if(isPressPort) { triggerResponse = true; playerInputEvent = eAAM_OnPress; nodeOutput = eOutputPort_Pressed; } else if(isHoldPort) { triggerResponse = true; playerInputEvent = eAAM_OnHold; nodeOutput = eOutputPort_Held; } else if(isReleasePort) { triggerResponse = true; playerInputEvent = eAAM_OnRelease; nodeOutput = eOutputPort_Released; } if(triggerResponse) { CActor *pClientActor = static_cast<CActor *>(g_pGame->GetIGameFramework()->GetClientActor()); if(pClientActor) { if(pClientActor->GetActorClass() == CPlayer::GetActorClassType()) { CPlayer *pClientPlayer = static_cast<CPlayer *>(pClientActor); const char *action = GetPortString(pActInfo, eInputPorts_Action).c_str(); const float inputValue = GetPortFloat(pActInfo, eInputPorts_Value); IPlayerInput *pPlayerInput = pClientPlayer->GetPlayerInput(); if(pPlayerInput) { CODECHECKPOINT(SimulateInput_ProcessEvent_SendAction); pPlayerInput->OnAction(action, playerInputEvent, isPressPort ? clamp(inputValue, 0.0f, 1.0f) : 0.0f); } } } ActivateOutput(pActInfo, nodeOutput, true); } } }
void CCinematicInput::UpdateAdditiveCameraInput( IScriptSystem* pScriptSystem, float frameTime ) { CCinematicInput::SUpdateContext updateCtx; pScriptSystem->GetGlobalValue("Cinematic_CameraLookUp", updateCtx.m_lookUpLimit); pScriptSystem->GetGlobalValue("Cinematic_CameraLookDown", updateCtx.m_lookDownLimit); pScriptSystem->GetGlobalValue("Cinematic_CameraLookLeft", updateCtx.m_lookLeftLimit); pScriptSystem->GetGlobalValue("Cinematic_CameraLookRight", updateCtx.m_lookRightLimit); float recenterCamera = 0.0f; pScriptSystem->GetGlobalValue("Cinematic_CameraDoNotCenter", recenterCamera); updateCtx.m_lookUpLimit = DEG2RAD(updateCtx.m_lookUpLimit); updateCtx.m_lookDownLimit = DEG2RAD(updateCtx.m_lookDownLimit); updateCtx.m_lookLeftLimit = DEG2RAD(updateCtx.m_lookLeftLimit); updateCtx.m_lookRightLimit = DEG2RAD(updateCtx.m_lookRightLimit); updateCtx.m_recenter = (recenterCamera < 0.01f); updateCtx.m_frameTime = frameTime; CActor* pClientActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetClientActor()); if (pClientActor) { CRY_ASSERT(pClientActor->GetActorClass() == CPlayer::GetActorClassType()); CPlayer* pClientPlayer = static_cast<CPlayer*>(pClientActor); IPlayerInput* pIPlayerInput = pClientPlayer->GetPlayerInput(); if(pIPlayerInput && pIPlayerInput->GetType() == IPlayerInput::PLAYER_INPUT) { CPlayerInput * pPlayerInput = static_cast<CPlayerInput*>(pIPlayerInput); Ang3 frameAccumulatedAngles(0.0f, 0.0f, 0.0f); #if CINEMATIC_INPUT_PC_MOUSE const bool isAimingWithMouse = pPlayerInput->IsAimingWithMouse(); RefreshInputMethod(isAimingWithMouse); if (isAimingWithMouse) { frameAccumulatedAngles = UpdateAdditiveCameraInputWithMouse(updateCtx, pPlayerInput->GetRawMouseInput()); } else { frameAccumulatedAngles = UpdateAdditiveCameraInputWithController(updateCtx, pPlayerInput->GetRawControllerInput()); } #else frameAccumulatedAngles = UpdateAdditiveCameraInputWithController(updateCtx, pPlayerInput->GetRawControllerInput()); #endif IView* pActiveView = g_pGame->GetIGameFramework()->GetIViewSystem()->GetActiveView(); if (pActiveView) { pActiveView->SetFrameAdditiveCameraAngles(frameAccumulatedAngles); } } } }
//------------------------------------------------------------------------ int CScriptBind_Actor::SetSearchBeam(IFunctionHandler *pH, Vec3 dir) { CActor *pActor = GetActor(pH); if (!pActor || pActor->GetActorClass() != CAlien::GetActorClassType()) return pH->EndFunction(); ((CAlien*)pActor)->SetSearchBeamGoal(dir); return pH->EndFunction(); }
//------------------------------------------------------------------------ int CScriptBind_Actor::SetNanoSuitEnergy(IFunctionHandler *pH, int energy) { CActor *pActor = GetActor(pH); if (!pActor || pActor->GetActorClass() != CPlayer::GetActorClassType()) return pH ->EndFunction(); if(CNanoSuit *pSuit = ((CPlayer*)pActor)->GetNanoSuit()) pSuit->SetSuitEnergy(energy); return pH->EndFunction(); }
//------------------------------------------------------------------------ int CScriptBind_Actor::GetNanoSuitMode(IFunctionHandler *pH) { CActor *pActor = GetActor(pH); if (!pActor || pActor->GetActorClass() != CPlayer::GetActorClassType()) return pH->EndFunction(0); if(CNanoSuit *pSuit = ((CPlayer*)pActor)->GetNanoSuit()) return pH->EndFunction((int)(pSuit->GetMode())); return pH->EndFunction(0); }
void CCinematicInput::TogglePlayerThirdPerson(bool bEnable) { CActor* pClientActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetClientActor()); if (pClientActor) { CRY_ASSERT(pClientActor->GetActorClass() == CPlayer::GetActorClassType()); CPlayer* pClientPlayer = static_cast<CPlayer*>(pClientActor); pClientPlayer->SetThirdPerson((bEnable && !pClientPlayer->IsThirdPerson())); } }
void CCinematicInput::UpdateAdditiveCameraInput(IScriptSystem *pScriptSystem, float frameTime) { float lookUpLimit = 0.0f, lookDownLimit = 0.0f; float lookLeftLimit = 0.0f, lookRightLimit = 0.0f; pScriptSystem->GetGlobalValue("Cinematic_CameraLookUp", lookUpLimit); pScriptSystem->GetGlobalValue("Cinematic_CameraLookDown", lookDownLimit); pScriptSystem->GetGlobalValue("Cinematic_CameraLookLeft", lookLeftLimit); pScriptSystem->GetGlobalValue("Cinematic_CameraLookRight", lookRightLimit); lookUpLimit = DEG2RAD(lookUpLimit); lookDownLimit = DEG2RAD(lookDownLimit); lookLeftLimit = DEG2RAD(lookLeftLimit); lookRightLimit = DEG2RAD(lookRightLimit); CActor *pClientActor = static_cast<CActor *>(g_pGame->GetIGameFramework()->GetClientActor()); if(pClientActor) { CRY_ASSERT(pClientActor->GetActorClass() == CPlayer::GetActorClassType()); CPlayer *pClientPlayer = static_cast<CPlayer *>(pClientActor); IPlayerInput *pIPlayerInput = pClientPlayer->GetPlayerInput(); if(pIPlayerInput && pIPlayerInput->GetType() == IPlayerInput::PLAYER_INPUT) { CPlayerInput *pPlayerInput = static_cast<CPlayerInput *>(pIPlayerInput); Ang3 rawMouseInput = pPlayerInput->GetRawMouseInput() * 0.25f; rawMouseInput.z = - rawMouseInput.z; rawMouseInput.x *= (g_pGameCVars->cl_invertMouse == 0) ? 1.0f : -1.0f; Ang3 rawControllerInput = pPlayerInput->GetRawControllerInput() + rawMouseInput; //Yaw angle (Z axis) rawControllerInput.z = -clamp((float)__fsel(rawControllerInput.z, rawControllerInput.z * lookRightLimit, rawControllerInput.z * lookLeftLimit), -lookLeftLimit, lookRightLimit); //Pitch angle (X axis) rawControllerInput.x *= (g_pGameCVars->cl_invertController == 0) ? 1.0f : -1.0f; rawControllerInput.x = clamp((float)__fsel(rawControllerInput.x, rawControllerInput.x * lookUpLimit, rawControllerInput.x * lookDownLimit), -lookDownLimit, lookUpLimit); //No roll allowed rawControllerInput.y = 0.0f; Interpolate(m_currentRawInputAngles, rawControllerInput, 2.5f, frameTime); IView *pActiveView = g_pGame->GetIGameFramework()->GetIViewSystem()->GetActiveView(); if(pActiveView) { pActiveView->SetFrameAdditiveCameraAngles(m_currentRawInputAngles); } } } }
//------------------------------------------------------------------------ int CScriptBind_Actor::ActivateNanoSuit(IFunctionHandler *pH, int on) { CActor *pActor = GetActor(pH); if (!pActor) return pH->EndFunction(); if(pActor->GetActorClass() != CPlayer::GetActorClassType()) return pH->EndFunction(); ((CPlayer*)pActor)->ActivateNanosuit((on)?true:false); return pH->EndFunction(); }
void CCinematicInput::DisablePlayerForCutscenes() { CActor* pClientActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetClientActor()); if (pClientActor) { CRY_ASSERT(pClientActor->GetActorClass() == CPlayer::GetActorClassType()); CPlayer* pClientPlayer = static_cast<CPlayer*>(pClientActor); pClientPlayer->OnBeginCutScene(); } g_pGameActions->FilterCutsceneNoPlayer()->Enable(true); }
//------------------------------------------------------------------------ int CScriptBind_Actor::NanoSuitHit(IFunctionHandler *pH, int damage) { CActor *pActor = GetActor(pH); if (!pActor) return pH->EndFunction(); if(pActor->GetActorClass() != CPlayer::GetActorClassType()) return pH->EndFunction(); if(CNanoSuit *pSuit = ((CPlayer*)pActor)->GetNanoSuit()) pSuit->Hit(damage); return pH->EndFunction(); }
//------------------------------------------------------------------------ void CMelee::NetAttack() { MeleeDebugLog ("CMelee<%p> NetAttack", this); const ItemString &meleeAction = SelectMeleeAction(); m_pWeapon->OnMelee(m_pWeapon->GetOwnerId()); CActor* pOwner = m_pWeapon->GetOwnerActor(); if (!DoSlideMeleeAttack(pOwner)) { if(!gEnv->bMultiplayer || !g_pGameCVars->pl_melee.mp_melee_system || !StartMultiAnimMeleeAttack(pOwner)) { FragmentID fragmentId = m_pWeapon->GetFragmentID(meleeAction.c_str()); m_pWeapon->PlayAction(fragmentId, 0, false, CItem::eIPAF_Default); } } else { CRY_ASSERT(pOwner && (pOwner->GetActorClass() == CPlayer::GetActorClassType())); if( pOwner->IsPlayer() ) { static_cast<CPlayer*> (pOwner)->StateMachineHandleEventMovement( SStateEventSlideKick(this) ); } } m_attacking = true; m_slideKick = false; m_netAttacking = true; m_delayTimer = GetDelay(); m_pWeapon->SetBusy(true); m_pWeapon->RequireUpdate(eIUS_FireMode); CPlayer *pOwnerPlayer = m_pWeapon->GetOwnerPlayer(); if (pOwnerPlayer) { if (pOwnerPlayer->IsThirdPerson()) { CAudioSignalPlayer::JustPlay(m_pMeleeParams->meleeparams.m_3PSignalId, pOwnerPlayer->GetEntityId()); } else { CAudioSignalPlayer::JustPlay(m_pMeleeParams->meleeparams.m_FPSignalId, pOwnerPlayer->GetEntityId()); } } }
void CCinematicInput::DisablePlayerForCutscenes() { CActor* pClientActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetClientActor()); if (pClientActor) { CRY_ASSERT(pClientActor->GetActorClass() == CPlayer::GetActorClassType()); CPlayer* pClientPlayer = static_cast<CPlayer*>(pClientActor); pClientPlayer->StateMachineHandleEventMovement( SStateEventCutScene( true ) ); } g_pGameActions->FilterCutsceneNoPlayer()->Enable(true); g_pGame->GetIGameFramework()->GetIActionMapManager()->EnableActionMap( "player_cine" , true ); }
CPlayer* Mouse::getPlayer(EntityId id) { if (id == 0) { return NULL; } CActor* pActor = g_pGame ? static_cast<CActor*> (g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)) : NULL; if (pActor != NULL && pActor->GetActorClass() == CPlayer::GetActorClassType()) { return static_cast<CPlayer*> (pActor); } return NULL; }
//------------------------------------------------------------------------ int CScriptBind_Actor::PlayNanoSuitSound(IFunctionHandler *pH, int sound) { if(sound < NO_SOUND || sound > ESound_Suit_Last) return pH->EndFunction(); CActor *pActor = GetActor(pH); if (!pActor) return pH->EndFunction(); if(pActor->GetActorClass() != CPlayer::GetActorClassType()) return pH->EndFunction(); if(CNanoSuit *pSuit = ((CPlayer*)pActor)->GetNanoSuit()) pSuit->PlaySound((ENanoSound)sound); return pH->EndFunction(); }
//------------------------------------------------------------------------ int CScriptBind_Actor::SetNanoSuitMode(IFunctionHandler *pH, int mode) { CActor *pActor = GetActor(pH); if (!pActor) return pH->EndFunction(); if(mode<0 || mode>=NANOMODE_LAST) return pH->EndFunction(); if(pActor->GetActorClass() != CPlayer::GetActorClassType()) return pH->EndFunction(); if(CNanoSuit *pSuit = ((CPlayer*)pActor)->GetNanoSuit()) pSuit->SetMode((ENanoMode)mode); else GameWarning("Lua tried to set NanoMode on not activated/existing Nanosuit of Player %s!", pActor->GetEntity()->GetName()); return pH->EndFunction(); }
//------------------------------------------------------------------------ float CGameRulesCommonDamageHandling::GetPlayerAgainstColliderEnergyScale(const IEntity& collider) const { CActor* pColliderActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(collider.GetId())); if (pColliderActor) { if (pColliderActor->GetActorClass() == CPlayer::GetActorClassType()) { SPlayerStats* pColliderStats = static_cast<SPlayerStats*>(pColliderActor->GetActorStats()); if (pColliderStats != NULL && pColliderStats->followCharacterHead) { return 0.0f; } } } return 1.0f; }
//------------------------------------------------------------------------ void CGameRules::KnockActorDown( EntityId actorEntityId ) { // Forbid fall and play if the actor is playing a hit/death reaction CActor* pHitActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor( actorEntityId )); if (pHitActor) { if (pHitActor->GetActorClass() == CPlayer::GetActorClassType()) { // Don't trigger Fall and Play if the actor is playing a hit reaction CPlayer* pHitPlayer = static_cast<CPlayer*>(pHitActor); CHitDeathReactionsConstPtr pHitDeathReactions = pHitPlayer->GetHitDeathReactions(); if (!pHitDeathReactions || !pHitDeathReactions->IsInReaction()) pHitActor->Fall(); } else pHitActor->Fall(); } }
//------------------------------------------------------------------------ void CWeapon::OnShoot(EntityId shooterId, EntityId ammoId, IEntityClass *pAmmoType, const Vec3 &pos, const Vec3 &dir, const Vec3 &vel) { BROADCAST_WEAPON_EVENT(OnShoot, (this, shooterId, ammoId, pAmmoType, pos, dir, vel)); //FIXME:quick temporary solution CActor *pActor = static_cast<CActor *>(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(shooterId)); if(pActor) pActor->HandleEvent(SGameObjectEvent(eCGE_OnShoot,eGOEF_ToExtensions)); IActor *pClientActor=m_pGameFramework->GetClientActor(); if(pActor && pActor->GetActorClass() == CPlayer::GetActorClassType() && IsServer()) { if(pActor == pClientActor) { if(IAIObject *pAIObject=pActor->GetEntity()->GetAI()) gEnv->pAISystem->SendSignal(SIGNALFILTER_LEADER, 1, "OnEnableFire", pAIObject, 0); } } if(pClientActor && m_fm && strcmp(m_fm->GetType(), "Thrown")) { // inform the HUDRadar about the sound event Vec3 vPlayerPos=pClientActor->GetEntity()->GetWorldPos(); float fDist2=(vPlayerPos-pos).len2(); if(fDist2<250.0f*250.0f) { //if (pClientActor->GetEntityId() != shooterId) // pHUD->ShowSoundOnRadar(pos); if(gEnv->bMultiplayer) { CGameRules *pGameRules = g_pGame->GetGameRules(); } if((!IsSilencerAttached()) && fDist2<sqr(SAFE_GAMEAUDIO_BATTLESTATUS_FUNC_RET(GetBattleRange()))) SAFE_GAMEAUDIO_BATTLESTATUS_FUNC(TickBattleStatus(1.0f)); } } }
//------------------------------------------------------------------------ void CIronSight::OnEnterZoom() { CActor *pActor = m_pWeapon->GetOwnerActor(); if(pActor && pActor->IsClient()) { if(g_pGameCVars->g_dof_ironsight != 0) { if(m_pShared->zoomParams.dof) { gEnv->p3DEngine->SetPostEffectParam("Dof_UseMask", 1); gEnv->p3DEngine->SetPostEffectParamString("Dof_MaskTexName", UseAlternativeIronSight()? m_pShared->zoomParams.alternate_dof_mask : m_pShared->zoomParams.dof_mask); } else { gEnv->p3DEngine->SetPostEffectParam("Dof_UseMask", 0); } gEnv->p3DEngine->SetPostEffectParam("Dof_Active", 1); gEnv->p3DEngine->SetPostEffectParam("Dof_FocusRange", -1); } if(m_pShared->zoomParams.blur_amount > 0.0f) { gEnv->p3DEngine->SetPostEffectParam("FilterMaskedBlurring_Amount", m_pShared->zoomParams.blur_amount); gEnv->p3DEngine->SetPostEffectParamString("FilterMaskedBlurring_MaskTexName", m_pShared->zoomParams.blur_mask); } if(pActor->GetActorClass() == CPlayer::GetActorClassType()) { CPlayer *pPlayer = static_cast<CPlayer *>(pActor); if(g_pGameCVars->bt_ironsight && !g_pGameCVars->bt_speed) { g_pGame->GetBulletTime()->Activate(true); } } } m_swayTime = 0.0f; }
void CCinematicInput::ReEnablePlayerAfterCutscenes() { CActor* pClientActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetClientActor()); if (pClientActor) { CRY_ASSERT(pClientActor->GetActorClass() == CPlayer::GetActorClassType()); CPlayer* pClientPlayer = static_cast<CPlayer*>(pClientActor); if (m_bMutedAudioForCutscene) { uint32 playerFlags = pClientPlayer->GetEntity()->GetFlagsExtended(); pClientPlayer->GetEntity()->SetFlagsExtended(playerFlags & ~ENTITY_FLAG_EXTENDED_AUDIO_DISABLED); } pClientPlayer->StateMachineHandleEventMovement( SStateEventCutScene( false ) ); } g_pGameActions->FilterCutsceneNoPlayer()->Enable(false); g_pGame->GetIGameFramework()->GetIActionMapManager()->EnableActionMap( "player_cine" , false ); }
//------------------------------------------------------------------------ void CWeapon::OnShoot(EntityId shooterId, EntityId ammoId, IEntityClass* pAmmoType, const Vec3 &pos, const Vec3 &dir, const Vec3&vel) { BROADCAST_WEAPON_EVENT(OnShoot, (this, shooterId, ammoId, pAmmoType, pos, dir, vel)); //FIXME:quick temporary solution CActor *pActor = static_cast<CActor*> (g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(shooterId)); if (pActor) pActor->HandleEvent(SGameObjectEvent(eCGE_OnShoot,eGOEF_ToExtensions)); IActor *pClientActor=m_pGameFramework->GetClientActor(); if (pActor && pActor->GetActorClass() == CPlayer::GetActorClassType() && IsServer()) { if (pActor == pClientActor) { if (IAIObject *pAIObject=pActor->GetEntity()->GetAI()) gEnv->pAISystem->SendSignal(SIGNALFILTER_LEADER, 1, "OnEnableFire", pAIObject, 0); } CPlayer *pPlayer=static_cast<CPlayer *>(pActor); CNanoSuit *pSuit=pPlayer->GetNanoSuit(); if(m_fm && strcmp(m_fm->GetType(), "Repair")) { if(pSuit) { if (pSuit->GetMode() == NANOMODE_STRENGTH && !IsMounted()) pSuit->SetSuitEnergy(pSuit->GetSuitEnergy()-g_pGameCVars->g_suitRecoilEnergyCost); else if(pSuit->GetMode() == NANOMODE_CLOAK) pSuit->SetSuitEnergy(0.0f); } } if (gEnv->bServer && pSuit && pSuit->IsInvulnerable()) pSuit->SetInvulnerability(false); } if (pClientActor && m_fm && strcmp(m_fm->GetType(), "Thrown")) { // inform the HUDRadar about the sound event Vec3 vPlayerPos=pClientActor->GetEntity()->GetWorldPos(); float fDist2=(vPlayerPos-pos).len2(); if (fDist2<250.0f*250.0f) { //if (pClientActor->GetEntityId() != shooterId) // pHUD->ShowSoundOnRadar(pos); if(gEnv->bMultiplayer) { CGameRules *pGameRules = g_pGame->GetGameRules(); if(pGameRules->GetTeamCount() < 2 || (pGameRules->GetTeam(shooterId) != pGameRules->GetTeam(pClientActor->GetEntityId()))) { //Small workaround for patch2... IFireMode* pFM = GetFireMode(GetCurrentFireMode()); bool grenade = pFM?(pFM->GetAmmoType()==CItem::sScarGrenadeClass):false; //~... if (!IsSilencerAttached() || grenade) { SAFE_HUD_FUNC(GetRadar()->AddEntityTemporarily(shooterId, 5.0f)); } else if(fDist2<5.0f*5.0f) { //Silencer attached SAFE_HUD_FUNC(GetRadar()->AddEntityTemporarily(shooterId, 5.0f)); } } } if ((!IsSilencerAttached()) && fDist2<sqr(SAFE_HUD_FUNC_RET(GetBattleRange()))) SAFE_HUD_FUNC(TickBattleStatus(1.0f)); } } }
//------------------------------------------------------------------------ void CMelee::Update(float frameTime, uint frameId) { FUNCTION_PROFILER( GetISystem(), PROFILE_GAME ); bool requireUpdate = false; if (m_attacking) { requireUpdate = true; if (m_delayTimer>0.0f) { m_delayTimer-=frameTime; if (m_delayTimer<=0.0f) m_delayTimer=0.0f; } else { if (!m_attacked) { m_attacked = true; CActor *pActor = m_pWeapon->GetOwnerActor(); if(!pActor) return; Vec3 pos(ZERO); Vec3 dir(ZERO); IMovementController * pMC = pActor->GetMovementController(); if (!pMC) return; float strength = 1.0f;//pActor->GetActorStrength(); if (pActor->GetActorClass() == CPlayer::GetActorClassType()) { CPlayer *pPlayer = (CPlayer *)pActor; if (CNanoSuit *pSuit = pPlayer->GetNanoSuit()) { ENanoMode curMode = pSuit->GetMode(); if (curMode == NANOMODE_STRENGTH) { strength = pActor->GetActorStrength(); strength = strength * (1.0f + 2.0f * pSuit->GetSlotValue(NANOSLOT_STRENGTH)* STRENGTH_MULT); if(!pPlayer->IsPlayer() && g_pGameCVars->g_difficultyLevel < 4) strength *= g_pGameCVars->g_AiSuitStrengthMeleeMult; } } } SMovementState info; pMC->GetMovementState(info); pos = info.eyePosition; dir = info.eyeDirection; if (!PerformRayTest(pos, dir, strength, false)) if(!PerformCylinderTest(pos, dir, strength, false)) ApplyCameraShake(false); m_ignoredEntity = 0; m_meleeScale = 1.0f; m_pWeapon->RequestMeleeAttack(m_pWeapon->GetMeleeFireMode()==this, pos, dir); } } } if (requireUpdate) m_pWeapon->RequireUpdate(eIUS_FireMode); }
//------------------------------------------------------------------------ void CMelee::Hit(const Vec3 &pt, const Vec3 &dir, const Vec3 &normal, IPhysicalEntity *pCollider, int partId, int ipart, int surfaceIdx, float damageScale, bool remote) { // generate the damage IEntity *pTarget = gEnv->pEntitySystem->GetEntityFromPhysics(pCollider); // Report punch to AI system. // The AI notification must come before the game rules are // called so that the death handler in AIsystem understands that the hit // came from the player. CActor *pActor = m_pWeapon->GetOwnerActor(); if (pActor && pActor->GetActorClass() == CPlayer::GetActorClassType()) { CPlayer *pPlayer = (CPlayer *)pActor; if (pPlayer && pPlayer->GetNanoSuit()) { if (pPlayer->GetEntity() && pPlayer->GetEntity()->GetAI()) { SAIEVENT AIevent; AIevent.targetId = pTarget ? pTarget->GetId() : 0; // pPlayer->GetNanoSuit()->GetMode() == NANOMODE_STRENGTH pPlayer->GetEntity()->GetAI()->Event(AIEVENT_PLAYER_STUNT_PUNCH, &AIevent); } } } bool ok = true; if(pTarget) { if(!gEnv->bMultiplayer && pActor && pActor->IsPlayer()) { IActor* pAITarget = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTarget->GetId()); if(pAITarget && pTarget->GetAI() && !pTarget->GetAI()->IsHostile(pActor->GetEntity()->GetAI(),false)) { ok = false; m_noImpulse = true; } } if(ok) { CGameRules *pGameRules = g_pGame->GetGameRules(); HitInfo info(m_pWeapon->GetOwnerId(), pTarget->GetId(), m_pWeapon->GetEntityId(), m_meleeparams.damage*damageScale*m_meleeScale, 0.0f, pGameRules->GetHitMaterialIdFromSurfaceId(surfaceIdx), partId, pGameRules->GetHitTypeId(m_meleeparams.hit_type.c_str()), pt, dir, normal); info.remote = remote; if (m_pWeapon->GetForcedHitMaterial() != -1) info.material=pGameRules->GetHitMaterialIdFromSurfaceId(m_pWeapon->GetForcedHitMaterial()); pGameRules->ClientHit(info); } } // play effects if(ok) { IMaterialEffects* pMaterialEffects = gEnv->pGame->GetIGameFramework()->GetIMaterialEffects(); TMFXEffectId effectId = pMaterialEffects->GetEffectId("melee", surfaceIdx); if (effectId != InvalidEffectId) { SMFXRunTimeEffectParams params; params.pos = pt; params.playflags = MFX_PLAY_ALL | MFX_DISABLE_DELAY; params.soundSemantic = eSoundSemantic_Player_Foley; pMaterialEffects->ExecuteEffect(effectId, params); } } ApplyCameraShake(true); m_pWeapon->PlayAction(m_meleeactions.hit.c_str()); }
CHitDeathReactionsPtr CCustomReactionFunctions::GetActorHitDeathReactions(CActor& actor) const { CRY_ASSERT(actor.GetActorClass() == CPlayer::GetActorClassType()); CPlayer& player = static_cast<CPlayer&>(actor); return player.GetHitDeathReactions(); }
//------------------------------------------------------------------------ void CMelee::Impulse(const Vec3 &pt, const Vec3 &dir, const Vec3 &normal, IPhysicalEntity *pCollider, int partId, int ipart, int surfaceIdx, float impulseScale) { if(m_noImpulse) { m_noImpulse = false; return; } if (pCollider && m_meleeparams.impulse>0.001f) { bool strengthMode = false; CPlayer *pPlayer = (CPlayer *)m_pWeapon->GetOwnerActor(); if(pPlayer) { if (CNanoSuit *pSuit = pPlayer->GetNanoSuit()) { ENanoMode curMode = pSuit->GetMode(); if (curMode == NANOMODE_STRENGTH) strengthMode = true; } } pe_status_dynamics dyn; if (!pCollider->GetStatus(&dyn)) { if(strengthMode) impulseScale *= 3.0f; } else impulseScale *= clamp((dyn.mass * 0.01f), 1.0f, 15.0f); //[kirill] add impulse to phys proxy - to make sure it's applied to cylinder as well (not only skeleton) - so that entity gets pushed // if no pEntity - do it old way IEntity * pEntity = (IEntity*) pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY); if(gEnv->bMultiplayer && pEntity) { if(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pEntity->GetId()) == NULL) impulseScale *= 0.33f; } if(pEntity) { bool crapDollFilter = false; #ifdef CRAPDOLLS static IEntityClass* pDeadBodyClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("DeadBody"); if (pEntity->GetClass() == pDeadBodyClass) crapDollFilter = true; #endif //CRAPDOLLS if (!crapDollFilter) { IEntityPhysicalProxy* pPhysicsProxy = (IEntityPhysicalProxy*)pEntity->GetProxy(ENTITY_PROXY_PHYSICS); CActor* pActor = (CActor*)g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pEntity->GetId()); if (pActor) { SActorStats* pAS = pActor->GetActorStats(); if (pAS && pAS->isRagDoll) { //marcok: talk to me before touching this impulseScale = 1.0f; //jan: melee impulses were scaled down, I made sure it still "barely moves" #ifdef CRAPDOLLS crapDollFilter = true; #endif //CRAPDOLLS } } // scale impulse up a bit for player if (!crapDollFilter) pPhysicsProxy->AddImpulse(partId, pt, dir*m_meleeparams.impulse*impulseScale*m_meleeScale, true, 1.f); } } else { pe_action_impulse ai; ai.partid = partId; ai.ipart = ipart; ai.point = pt; ai.iApplyTime = 0; ai.impulse = dir*(m_meleeparams.impulse*impulseScale*m_meleeScale); pCollider->Action(&ai); } ISurfaceTypeManager *pSurfaceTypeManager = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeManager(); int invId = pSurfaceTypeManager->GetSurfaceTypeByName("mat_invulnerable")->GetId(); // create a physical collision to break trees pe_action_register_coll_event collision; collision.collMass = 0.005f; // this is actually ignored collision.partid[1] = partId; // collisions involving partId<-1 are to be ignored by game's damage calculations // usually created articially to make stuff break. collision.partid[0] = -2; collision.idmat[1] = surfaceIdx; collision.idmat[0] = invId; collision.n = normal; collision.pt = pt; // scar bullet // m = 0.0125 // v = 800 // energy: 4000 // in this case the mass of the active collider is a player part // so we must solve for v given the same energy as a scar bullet Vec3 v = dir; float speed = cry_sqrtf(4000.0f/(80.0f*0.5f)); // 80.0f is the mass of the player // [marco] Check if an object. Should take lots of time to break stuff if not in nanosuit strength mode; // and still creates a very low impulse for stuff that might depend on receiving an impulse. IRenderNode *pBrush = (IRenderNode*)pCollider->GetForeignData(PHYS_FOREIGN_ID_STATIC); if (pBrush) { CActor *pActor = m_pWeapon->GetOwnerActor(); if (pActor && (pActor->GetActorClass() == CPlayer::GetActorClassType())) { CPlayer *pPlayer = (CPlayer *)pActor; if (CNanoSuit *pSuit = pPlayer->GetNanoSuit()) { ENanoMode curMode = pSuit->GetMode(); if (curMode != NANOMODE_STRENGTH) speed =0.003f; } } } collision.vSelf = (v.normalized()*speed*m_meleeScale); collision.v = Vec3(0,0,0); collision.pCollider = pCollider; IEntity *pOwner = m_pWeapon->GetOwner(); if (pOwner && pOwner->GetCharacter(0) && pOwner->GetCharacter(0)->GetISkeletonPose()->GetCharacterPhysics()) { if (ISkeletonPose *pSkeletonPose=pOwner->GetCharacter(0)->GetISkeletonPose()) { if (pSkeletonPose && pSkeletonPose->GetCharacterPhysics()) pSkeletonPose->GetCharacterPhysics()->Action(&collision); } } } }
void CMelee::StartAttack() { bool canAttack = CanAttack(); MeleeDebugLog ("CMelee<%p> StartAttack canAttack=%s", this, canAttack ? "true" : "false"); if (!canAttack) return; CActor* pOwner = m_pWeapon->GetOwnerActor(); CPlayer *ownerPlayer = m_pWeapon->GetOwnerPlayer(); m_attacking = true; m_slideKick = false; m_attacked = false; m_pWeapon->RequireUpdate(eIUS_FireMode); m_pWeapon->ExitZoom(); bool isClient = pOwner ? pOwner->IsClient() : false; bool doingMultiMeleeAttack = true; if (!DoSlideMeleeAttack(pOwner)) { const float use_melee_weapon_delay = m_pMeleeParams->meleeparams.use_melee_weapon_delay; if( use_melee_weapon_delay >= 0.0f ) { if( !ownerPlayer || ownerPlayer->IsSliding() || ownerPlayer->IsExitingSlide() ) { m_attacking = false; return; } if( use_melee_weapon_delay == 0.0f ) { // instant switch: don't use the weapon's melee, send the event to the WeaponMelee weapon instead! if( SwitchToMeleeWeaponAndAttack() ) { m_useMeleeWeaponDelay = -1.0f; return; } } } if( IsMeleeWeapon() ) { doingMultiMeleeAttack = false; GenerateAndQueueMeleeAction(); } else if(!gEnv->bMultiplayer || !g_pGameCVars->pl_melee.mp_melee_system || !ownerPlayer || !StartMultiAnimMeleeAttack(ownerPlayer)) { const ItemString &meleeAction = SelectMeleeAction(); FragmentID fragmentId = m_pWeapon->GetFragmentID(meleeAction.c_str()); m_pWeapon->PlayAction(fragmentId, 0, false, CItem::eIPAF_Default); doingMultiMeleeAttack = false; } m_delayTimer = GetDelay(); m_attackTime = 0.f; if (ownerPlayer) { ownerPlayer->StateMachineHandleEventMovement( PLAYER_EVENT_FORCEEXITSLIDE ); } } else { CRY_ASSERT(pOwner && (pOwner->GetActorClass() == CPlayer::GetActorClassType())); doingMultiMeleeAttack = false; m_hitTypeID = CGameRules::EHitType::Melee; // Dispatch the event and the delay timer is magically set! ownerPlayer->StateMachineHandleEventMovement( SStateEventSlideKick(this) ); m_slideKick = true; } m_pWeapon->SetBusy(true); if(!doingMultiMeleeAttack) { // Set up a timer to disable the melee attack at the end of the first-person animation... uint32 durationInMilliseconds = static_cast<uint32>(GetDuration() * 1000.f); MeleeDebugLog ("CMelee<%p> Setting a timer to trigger StopAttackingAction (duration=%u)", this, durationInMilliseconds); // How much longer we need the animation to be than the damage delay, in seconds... const float k_requireAdditionalTime = 0.1f; if (durationInMilliseconds < (m_delayTimer + k_requireAdditionalTime) * 1000.0f) { if (!gEnv->IsDedicated()) { CRY_ASSERT_MESSAGE(false, string().Format("CMelee<%p> Warning! Melee attack timeout (%f seconds) needs to be substantially longer than the damage delay (%f seconds)! Increasing...", this, durationInMilliseconds / 1000.f, m_delayTimer)); } durationInMilliseconds = (uint32) ((m_delayTimer + k_requireAdditionalTime) * 1000.0f + 0.5f); // Add 0.5f to round up when turning into a uint32 } m_pWeapon->GetScheduler()->TimerAction(durationInMilliseconds, CSchedulerAction<StopAttackingAction>::Create(this), true); } m_pWeapon->OnMelee(m_pWeapon->GetOwnerId()); m_pWeapon->RequestStartMeleeAttack((m_pWeapon->GetMelee() == this), false); if (isClient) { s_fNextAttack = GetDuration() + gEnv->pTimer->GetFrameStartTime().GetSeconds(); if(s_meleeSnapTargetId = GetNearestTarget()) { IActor* pTargetActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(s_meleeSnapTargetId); s_bMeleeSnapTargetCrouched = pTargetActor && static_cast<CPlayer*>(pTargetActor)->GetStance() == STANCE_CROUCH; } CHANGED_NETWORK_STATE(pOwner, CPlayer::ASPECT_SNAP_TARGET); if (ownerPlayer) { if (ownerPlayer->IsThirdPerson()) { CAudioSignalPlayer::JustPlay(m_pMeleeParams->meleeparams.m_3PSignalId, ownerPlayer->GetEntityId()); } else { CAudioSignalPlayer::JustPlay(m_pMeleeParams->meleeparams.m_FPSignalId, ownerPlayer->GetEntityId()); } } CCCPOINT(Melee_LocalActorMelee); } else { CCCPOINT(Melee_NonLocalActorMelee); } }