Fixes for damage calculation: Adds missing + 2, and handles rounding correctly.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
42
tests/BattleTests/DamageTests.cpp
Normal file
42
tests/BattleTests/DamageTests.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include "../../extern/doctest.hpp"
|
||||
#include "../../src/Battling/Library/DamageLibrary.hpp"
|
||||
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||
#include "../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
using namespace PkmnLib::Battling;
|
||||
|
||||
TEST_CASE("Correct rounding for damage.") {
|
||||
auto lib = TestLibrary::GetLibrary();
|
||||
auto mon1 = CreatePokemon(lib, "testCharizard"_cnc, 100)
|
||||
.WithIndividualValues(31, 31, 31, 31, 31, 31)
|
||||
.WithEffortValues(0, 0, 0, 0, 0, 0)
|
||||
.WithNature("neutralNature"_cnc)
|
||||
.WithGender(CreatureLib::Library::Gender::Male)
|
||||
.IsAllowedExperienceGain(false)
|
||||
.Build();
|
||||
auto mon2 = CreatePokemon(lib, "testVenusaur"_cnc, 100)
|
||||
.WithIndividualValues(31, 31, 31, 31, 31, 31)
|
||||
.WithEffortValues(0, 0, 0, 0, 0, 0)
|
||||
.WithNature("neutralNature"_cnc)
|
||||
.WithGender(CreatureLib::Library::Gender::Male)
|
||||
.IsAllowedExperienceGain(false)
|
||||
.Build();
|
||||
|
||||
auto move = PkmnLib::Library::MoveData("test", 0, PkmnLib::Library::MoveCategory::Physical, 55, 100, 10,
|
||||
CreatureLib::Library::AttackTarget::All, 0, nullptr, {});
|
||||
|
||||
auto attack = PkmnLib::Battling::LearnedMove(&move, CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||
|
||||
auto executingAttack = CreatureLib::Battling::ExecutingAttack({mon2}, 1, mon1, &attack, &move, nullptr);
|
||||
|
||||
auto hit = executingAttack.GetHitData(mon2, 0);
|
||||
hit.SetBasePower(55);
|
||||
hit.SetEffectiveness(2.0f);
|
||||
hit.SetCritical(0);
|
||||
|
||||
auto damage = lib->GetDamageLibrary()->GetDamage(&executingAttack, mon2, 0, hit);
|
||||
REQUIRE_EQ(144, damage);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -37,6 +37,23 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
|
||||
{"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)),
|
||||
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
|
||||
|
||||
lib->Insert("testCharizard"_cnc.GetHash(),
|
||||
new PkmnLib::Library::PokemonSpecies(
|
||||
5, "testCharizard"_cnc,
|
||||
new PkmnLib::Library::PokemonForme(
|
||||
"default"_cnc, 1.7f, 90.5f, 240, {0, 4},
|
||||
CreatureLib::Library::StatisticSet<uint16_t>(78, 84, 78, 109, 85, 100), {"testAbility"_cnc},
|
||||
{"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)),
|
||||
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
|
||||
lib->Insert("testVenusaur"_cnc.GetHash(),
|
||||
new PkmnLib::Library::PokemonSpecies(
|
||||
6, "testVenusaur"_cnc,
|
||||
new PkmnLib::Library::PokemonForme(
|
||||
"default"_cnc, 2.0f, 100.0f, 236, {0, 4},
|
||||
CreatureLib::Library::StatisticSet<uint16_t>(80, 82, 83, 100, 100, 80), {"testAbility"_cnc},
|
||||
{"testHiddenAbility"_cnc}, new PkmnLib::Library::LearnableMoves(100)),
|
||||
0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}));
|
||||
|
||||
return lib;
|
||||
}
|
||||
PkmnLib::Library::MoveLibrary* TestLibrary::BuildMoveLibrary() {
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
auto statCalc = new PkmnLib::Battling::StatCalculator();
|
||||
auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
|
||||
auto lib = new PkmnLib::Battling::BattleLibrary(
|
||||
BuildStaticLibrary(), statCalc, new PkmnLib::Battling::DamageLibrary(),
|
||||
BuildStaticLibrary(), statCalc, new PkmnLib::Battling::DamageLibrary(false),
|
||||
new PkmnLib::Battling::ExperienceLibrary(), scriptResolver, new PkmnLib::Battling::MiscLibrary(GetTime));
|
||||
scriptResolver->Initialize(lib);
|
||||
return lib;
|
||||
|
||||
Reference in New Issue
Block a user