Skip to content

Commit

Permalink
Knockback/Damage fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Antidote committed Jun 13, 2021
1 parent f8627f5 commit c528304
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
20 changes: 8 additions & 12 deletions Runtime/CStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -2019,9 +2018,9 @@ bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqu
CEntity* ent1 = ObjectById(damageeId);
const TCastToPtr<CActor> damager = ent0;
const TCastToPtr<CActor> damagee = ent1;
const bool isPlayer = TCastToPtr<CPlayer>(ent1);
const bool isPlayer = TCastToPtr<CPlayer>(ent1) != nullptr;

if (damagee) {
if (damagee != nullptr) {
if (CHealthInfo* hInfo = damagee->HealthInfo(*this)) {
zeus::CVector3f position;
zeus::CVector3f direction = zeus::skRight;
Expand All @@ -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) {
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/MP1/World/CMetroidPrimeEssence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void CMetroidPrimeEssence::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o
break;
case EScriptObjectMessage::Touched: {
if (TCastToPtr<CCollisionActor> 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;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/MP1/World/CMetroidPrimeExo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions Runtime/MP1/World/CRidley.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c528304

Please sign in to comment.