Further fixes for rounding errors in damage calculations.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
037ff590f0
commit
aee0f04d9c
|
@ -21,6 +21,30 @@ uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::Exec
|
|||
floatDamage = fl(floatDamage * statMod);
|
||||
floatDamage = fl(floatDamage / 50) + 2;
|
||||
floatDamage = fl(floatDamage * damageMod);
|
||||
|
||||
if (attack->GetTargetCount() > 1) {
|
||||
floatDamage = fl(floatDamage * 0.75f);
|
||||
}
|
||||
if (hitData.IsCritical()) {
|
||||
float critModifier = 1.5;
|
||||
PKMN_HOOK(OverrideCriticalModifier, attack, attack, target, hitIndex, &critModifier);
|
||||
floatDamage = fl(floatDamage * critModifier);
|
||||
}
|
||||
|
||||
if (_hasRandomness) {
|
||||
Ensure(attack->GetUser()->GetBattle().GetValue());
|
||||
float randPercentage = 85 + attack->GetUser()->GetBattle().GetValue()->GetRandom()->Get(0, 16);
|
||||
floatDamage = fl(floatDamage * (randPercentage / 100.0));
|
||||
}
|
||||
|
||||
if (attack->GetUser()->HasType(hitData.GetType())) {
|
||||
float stabModifier = 1.5;
|
||||
PKMN_HOOK(OverrideSTABModifier, attack, attack, target, hitIndex, &stabModifier);
|
||||
floatDamage = fl(floatDamage * stabModifier);
|
||||
}
|
||||
|
||||
floatDamage = fl(floatDamage * hitData.GetEffectiveness());
|
||||
|
||||
uint32_t damage = 0;
|
||||
if (floatDamage < 0) {
|
||||
damage = 0;
|
||||
|
@ -77,29 +101,10 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E
|
|||
|
||||
return offensiveValue / defensiveValue;
|
||||
}
|
||||
float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
||||
const HitData& hitData) const {
|
||||
float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling::ExecutingAttack*,
|
||||
CreatureLib::Battling::Creature*, uint8_t,
|
||||
const HitData&) const {
|
||||
float mod = 1;
|
||||
if (attack->GetTargetCount() > 1)
|
||||
mod *= 0.75;
|
||||
if (hitData.IsCritical()) {
|
||||
float critModifier = 1.5;
|
||||
PKMN_HOOK(OverrideCriticalModifier, attack, attack, target, hitIndex, &critModifier);
|
||||
mod *= critModifier;
|
||||
}
|
||||
if (_hasRandomness) {
|
||||
Ensure(attack->GetUser()->GetBattle().GetValue());
|
||||
float randPercentage = 85 + attack->GetUser()->GetBattle().GetValue()->GetRandom()->Get(0, 16);
|
||||
mod *= randPercentage / 100.0;
|
||||
}
|
||||
if (attack->GetUser()->HasType(hitData.GetType())) {
|
||||
float stabModifier = 1.5;
|
||||
PKMN_HOOK(OverrideSTABModifier, attack, attack, target, hitIndex, &stabModifier);
|
||||
mod *= stabModifier;
|
||||
}
|
||||
|
||||
mod *= hitData.GetEffectiveness();
|
||||
// HOOK: Modify damage modifier.
|
||||
return mod;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,10 @@ TEST_CASE("Correct rounding for damage.") {
|
|||
|
||||
auto damage = lib->GetDamageLibrary()->GetDamage(&executingAttack, mon2, 0, hit);
|
||||
REQUIRE_EQ(144, damage);
|
||||
|
||||
hit.SetBasePower(110);
|
||||
damage = lib->GetDamageLibrary()->GetDamage(&executingAttack, mon2, 0, hit);
|
||||
REQUIRE_EQ(284, damage);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue