Knockback/Damage fixes

This commit is contained in:
Phillip Stephens 2021-06-13 03:06:09 -07:00
parent 12c38f57fa
commit ace87397d7
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
4 changed files with 15 additions and 19 deletions

View File

@ -1660,8 +1660,7 @@ void CStateManager::KnockBackPlayer(CPlayer& player, const zeus::CVector3f& pos,
float usePower; float usePower;
if (player.GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed) { if (player.GetMorphballTransitionState() != CPlayer::EPlayerMorphBallState::Morphed) {
usePower = power * 1000.f; usePower = power * 1000.f;
const auto surface = const auto surface = player.GetSurfaceRestraint();
player.x2b0_outOfWaterTicks == 2 ? player.x2ac_surfaceRestraint : CPlayer::ESurfaceRestraints::Water;
if (surface != CPlayer::ESurfaceRestraints::Normal && if (surface != CPlayer::ESurfaceRestraints::Normal &&
player.GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit) { player.GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit) {
usePower /= 7.f; 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 playerVel = player.x138_velocity.magnitude();
const float maxVel = std::max(playerVel, minVel); const float maxVel = std::max(playerVel, minVel);
const zeus::CVector3f negVel = -player.x138_velocity; 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.ApplyImpulseWR(pos * usePower, zeus::CAxisAngle());
player.UseCollisionImpulses(); player.UseCollisionImpulses();
player.x2d4_accelerationChangeTimer = 0.25f; player.x2d4_accelerationChangeTimer = 0.25f;
@ -2019,9 +2018,9 @@ bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqu
CEntity* ent1 = ObjectById(damageeId); CEntity* ent1 = ObjectById(damageeId);
const TCastToPtr<CActor> damager = ent0; const TCastToPtr<CActor> damager = ent0;
const TCastToPtr<CActor> damagee = ent1; 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)) { if (CHealthInfo* hInfo = damagee->HealthInfo(*this)) {
zeus::CVector3f position; zeus::CVector3f position;
zeus::CVector3f direction = zeus::skRight; zeus::CVector3f direction = zeus::skRight;
@ -2031,12 +2030,9 @@ bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqu
direction = damager->GetTransform().basis[1]; direction = damager->GetTransform().basis[1];
} }
const CDamageVulnerability* dVuln; const CDamageVulnerability* dVuln = (damager != nullptr || isPlayer)
if (damager || isPlayer) { ? damagee->GetDamageVulnerability(position, direction, info)
dVuln = damagee->GetDamageVulnerability(position, direction, info); : damagee->GetDamageVulnerability();
} else {
dVuln = damagee->GetDamageVulnerability();
}
if (info.GetWeaponMode().GetType() == EWeaponType::None || dVuln->WeaponHurts(info.GetWeaponMode(), false)) { if (info.GetWeaponMode().GetType() == EWeaponType::None || dVuln->WeaponHurts(info.GetWeaponMode(), false)) {
if (info.GetDamage() > 0.f) { if (info.GetDamage() > 0.f) {
@ -2052,7 +2048,7 @@ bool CStateManager::ApplyDamage(TUniqueId damagerId, TUniqueId damageeId, TUniqu
if (alive && damager && info.GetKnockBackPower() > 0.f) { if (alive && damager && info.GetKnockBackPower() > 0.f) {
zeus::CVector3f delta = zeus::CVector3f delta =
knockbackVec.isZero() ? (damagee->GetTranslation() - damager->GetTranslation()) : knockbackVec; knockbackVec.isZero() ? (damagee->GetTranslation() - damager->GetTranslation()) : knockbackVec;
delta.z() = FLT_EPSILON; delta.z() = 0.0001f;
ApplyKnockBack(*damagee, info, *dVuln, delta.normalized(), 0.f); ApplyKnockBack(*damagee, info, *dVuln, delta.normalized(), 0.f);
} }
} }

View File

@ -89,7 +89,7 @@ void CMetroidPrimeEssence::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o
break; break;
case EScriptObjectMessage::Touched: { case EScriptObjectMessage::Touched: {
if (TCastToPtr<CCollisionActor> colAct = mgr.ObjectById(other)) { 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(), mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), GetContactDamage(),
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f);
x420_curDamageRemTime = x424_damageWaitTime; x420_curDamageRemTime = x424_damageWaitTime;

View File

@ -1613,7 +1613,7 @@ void CMetroidPrimeExo::UpdateContactDamage(CStateManager& mgr) {
(0.57735026f * mData->GetScale().magnitude()) * 2.f}; (0.57735026f * mData->GetScale().magnitude()) * 2.f};
x8f8_ = zeus::CAABox{min, max}; 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(), mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), GetContactDamage(),
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f); CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f);
x420_curDamageRemTime = x424_damageWaitTime; x420_curDamageRemTime = x424_damageWaitTime;

View File

@ -568,14 +568,14 @@ void CRidley::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateMan
CDamageInfo(CWeaponMode(EWeaponType::AI), 1.f + plat->GetHealthInfo(mgr)->GetHP(), 0.f, 1.f), CDamageInfo(CWeaponMode(EWeaponType::AI), 1.f + plat->GetHealthInfo(mgr)->GetHP(), 0.f, 1.f),
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {}); CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
} }
}
if (mgr.GetPlayer().GetUniqueId() == colAct->GetLastTouchedObject()) { if (mgr.GetPlayer().GetUniqueId() == colAct->GetLastTouchedObject() && x420_curDamageRemTime <= 0.f) {
mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), xc8c_, mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), xc8c_,
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {}); CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
x420_curDamageRemTime = x424_damageWaitTime; x420_curDamageRemTime = x424_damageWaitTime;
} }
} }
}
break; break;
} }
default: default: