//------------------------------------------------------------------------ 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 (!PerformRayTest(pos, dir, strength, true)) if(!PerformCylinderTest(pos, dir, strength, true)) { ApplyCameraShake(false); } m_ignoredEntity = 0; m_meleeScale = 1.0f; }
//------------------------------------------------------------------------ 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; }
//------------------------------------------------------------------------ void CMelee::NetShootEx(const Vec3 &pos, const Vec3 &dir, const Vec3 &vel, const Vec3 &hit, float extra, int ph) { float strength=GetOwnerStrength(); if (!PerformRayTest(pos, dir, strength, true)) if(!PerformCylinderTest(pos, dir, strength, true)) ApplyCameraShake(false); m_ignoredEntity = 0; m_meleeScale = 1.0f; }
//------------------------------------------------------------------------ void CMelee::Update(float frameTime, uint32 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(); 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. bool ok = true; if(pTarget) { CActor *pActor = m_pWeapon->GetOwnerActor(); if(!gEnv->bMultiplayer && pActor && pActor->IsPlayer()) { if (IActor *pAITarget = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTarget->GetId())) { if (IAIObject *pAITargetObject = pTarget->GetAI()) { if (pAITargetObject->IsFriendly(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_pShared->meleeparams.damage * damageScale * m_meleeScale, 0.0f, pGameRules->GetHitMaterialIdFromSurfaceId(surfaceIdx), partId, pGameRules->GetHitTypeId(m_pShared->meleeparams.hit_type.c_str()), pt, dir, normal); info.remote = remote; pGameRules->ClientHit(info); } } // play effects if(ok) { if(IMaterialEffects *pMaterialEffects = gEnv->pGame->GetIGameFramework()->GetIMaterialEffects()) { TMFXEffectId effectId = pMaterialEffects->GetEffectId("melee", surfaceIdx); if (effectId != InvalidEffectId) { SMFXRunTimeEffectParams params; params.pos = pt; params.normal = -dir; params.playflags = MFX_PLAY_ALL | MFX_DISABLE_DELAY; params.soundSemantic = eSoundSemantic_Player_Foley; pMaterialEffects->ExecuteEffect(effectId, params); } } } ApplyCameraShake(true); m_pWeapon->PlayAction(m_pShared->meleeactions.hit.c_str()); }
//------------------------------------------------------------------------ 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()); }