From ace87397d72f0e36cb12d471a4afd4fc964d9465 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 13 Jun 2021 03:06:09 -0700 Subject: [PATCH] Knockback/Damage fixes --- Runtime/CStateManager.cpp | 20 ++++++++------------ Runtime/MP1/World/CMetroidPrimeEssence.cpp | 2 +- Runtime/MP1/World/CMetroidPrimeExo.cpp | 2 +- Runtime/MP1/World/CRidley.cpp | 10 +++++----- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 8f56ad6c2..ecab69e1d 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -1660,8 +1660,7 @@ void CStateManager::KnockBackPlayer(CPlayer& player, const zeus::CVector3f& pos, float usePower; if (player.GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed) { usePower = power * 1000.f; - const auto surface = - player.x2b0_outOfWaterTicks == 2 ? player.x2ac_surfaceRestraint : CPlayer::ESurfaceRestraints::Water; + const auto surface = player.GetSurfaceRestraint(); if (surface != CPlayer::ESurfaceRestraints::Normal && player.GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit) { usePower /= 7.f; @@ -1674,7 +1673,7 @@ void CStateManager::KnockBackPlayer(CPlayer& player, const zeus::CVector3f& pos, const float playerVel = player.x138_velocity.magnitude(); const float maxVel = std::max(playerVel, minVel); const zeus::CVector3f negVel = -player.x138_velocity; - usePower *= (1.f - 0.5f * zeus::CVector3f::getAngleDiff(pos, negVel) / M_PIF); + usePower *= (1.f - (0.5f * zeus::CVector3f::getAngleDiff(pos, negVel)) / M_PIF); player.ApplyImpulseWR(pos * usePower, zeus::CAxisAngle()); player.UseCollisionImpulses(); player.x2d4_accelerationChangeTimer = 0.25f; @@ -2019,9 +2018,9 @@ bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqu CEntity* ent1 = ObjectById(damageeId); const TCastToPtr damager = ent0; const TCastToPtr damagee = ent1; - const bool isPlayer = TCastToPtr(ent1); + const bool isPlayer = TCastToPtr(ent1) != nullptr; - if (damagee) { + if (damagee != nullptr) { if (CHealthInfo* hInfo = damagee->HealthInfo(*this)) { zeus::CVector3f position; zeus::CVector3f direction = zeus::skRight; @@ -2031,12 +2030,9 @@ bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqu direction = damager->GetTransform().basis[1]; } - const CDamageVulnerability* dVuln; - if (damager || isPlayer) { - dVuln = damagee->GetDamageVulnerability(position, direction, info); - } else { - dVuln = damagee->GetDamageVulnerability(); - } + const CDamageVulnerability* dVuln = (damager != nullptr || isPlayer) + ? damagee->GetDamageVulnerability(position, direction, info) + : damagee->GetDamageVulnerability(); if (info.GetWeaponMode().GetType() == EWeaponType::None || dVuln->WeaponHurts(info.GetWeaponMode(), false)) { if (info.GetDamage() > 0.f) { @@ -2052,7 +2048,7 @@ bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqu if (alive && damager && info.GetKnockBackPower() > 0.f) { zeus::CVector3f delta = knockbackVec.isZero() ? (damagee->GetTranslation() - damager->GetTranslation()) : knockbackVec; - delta.z() = FLT_EPSILON; + delta.z() = 0.0001f; ApplyKnockBack(*damagee, info, *dVuln, delta.normalized(), 0.f); } } diff --git a/Runtime/MP1/World/CMetroidPrimeEssence.cpp b/Runtime/MP1/World/CMetroidPrimeEssence.cpp index e59686c8f..a6a83c692 100644 --- a/Runtime/MP1/World/CMetroidPrimeEssence.cpp +++ b/Runtime/MP1/World/CMetroidPrimeEssence.cpp @@ -89,7 +89,7 @@ void CMetroidPrimeEssence::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o break; case EScriptObjectMessage::Touched: { if (TCastToPtr colAct = mgr.ObjectById(other)) { - if (colAct->GetLastTouchedObject() == mgr.GetPlayer().GetUniqueId()) { + if (colAct->GetLastTouchedObject() == mgr.GetPlayer().GetUniqueId() && x420_curDamageRemTime <= 0.f) { mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), GetContactDamage(), CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); x420_curDamageRemTime = x424_damageWaitTime; diff --git a/Runtime/MP1/World/CMetroidPrimeExo.cpp b/Runtime/MP1/World/CMetroidPrimeExo.cpp index b18e5d797..3c99b492a 100644 --- a/Runtime/MP1/World/CMetroidPrimeExo.cpp +++ b/Runtime/MP1/World/CMetroidPrimeExo.cpp @@ -1613,7 +1613,7 @@ void CMetroidPrimeExo::UpdateContactDamage(CStateManager& mgr) { (0.57735026f * mData->GetScale().magnitude()) * 2.f}; x8f8_ = zeus::CAABox{min, max}; - if (mgr.GetPlayer().GetTouchBounds()->intersects(x8f8_)) { + if (mgr.GetPlayer().GetTouchBounds()->intersects(x8f8_) && x420_curDamageRemTime <= 0.f) { mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), GetContactDamage(), CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); x420_curDamageRemTime = x424_damageWaitTime; diff --git a/Runtime/MP1/World/CRidley.cpp b/Runtime/MP1/World/CRidley.cpp index 207c571e3..6003d12f2 100644 --- a/Runtime/MP1/World/CRidley.cpp +++ b/Runtime/MP1/World/CRidley.cpp @@ -568,12 +568,12 @@ void CRidley::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateMan CDamageInfo(CWeaponMode(EWeaponType::AI), 1.f + plat->GetHealthInfo(mgr)->GetHP(), 0.f, 1.f), CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {}); } + } - if (mgr.GetPlayer().GetUniqueId() == colAct->GetLastTouchedObject()) { - mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), xc8c_, - CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {}); - x420_curDamageRemTime = x424_damageWaitTime; - } + if (mgr.GetPlayer().GetUniqueId() == colAct->GetLastTouchedObject() && x420_curDamageRemTime <= 0.f) { + mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), xc8c_, + CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {}); + x420_curDamageRemTime = x424_damageWaitTime; } } break;