Several fixes and improvements.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-12-28 15:11:06 +01:00
parent bbb2691b91
commit 31008c0107
7 changed files with 70 additions and 20 deletions

View File

@@ -1,6 +1,10 @@
#ifdef TESTS_BUILD
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
#include <CreatureLib/Battling/TurnChoices/PassTurnChoice.hpp>
#include "../../extern/doctest.hpp"
#include "../../src/Battling/Battle/Battle.hpp"
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
#include "../../src/Battling/Pokemon/PokemonParty.hpp"
#include "../TestLibrary/TestLibrary.hpp"
TEST_CASE("Create and delete Pokemon") {
@@ -31,4 +35,44 @@ TEST_CASE("Get Attack name from Pokemon") {
delete mon;
}
TEST_CASE("Heal pokemon after battle") {
auto library = TestLibrary::GetLibrary();
auto c1 = PkmnLib::Battling::CreatePokemon(library, "testSpecies"_cnc, 50)
.LearnMove("testMove"_cnc, CreatureLib::Battling::AttackLearnMethod::Unknown)
.Build();
PkmnLib::Battling::PokemonParty party1{c1};
auto battleParty1 = new CreatureLib::Battling::BattleParty(&party1, {CreatureLib::Battling::CreatureIndex(0, 0)});
auto c2 = PkmnLib::Battling::CreatePokemon(library, "testSpecies"_cnc, 50)
.LearnMove("testMove"_cnc, CreatureLib::Battling::AttackLearnMethod::Unknown)
.Build();
PkmnLib::Battling::PokemonParty party2{c2};
auto battleParty2 = new CreatureLib::Battling::BattleParty(&party2, {CreatureLib::Battling::CreatureIndex(1, 0)});
auto battle = new PkmnLib::Battling::Battle(library, {battleParty1, battleParty2});
REQUIRE_FALSE(battle->HasEnded());
battle->SwitchCreature(0, 0, c1);
battle->SwitchCreature(1, 0, c2);
REQUIRE_FALSE(battle->HasEnded());
REQUIRE(battle->TrySetChoice(new CreatureLib::Battling::AttackTurnChoice(
c1, c1->GetAttacks()[0].GetValue(), CreatureLib::Battling::CreatureIndex(1, 0))));
REQUIRE(battle->TrySetChoice(new CreatureLib::Battling::PassTurnChoice(c2)));
REQUIRE_FALSE(battle->HasEnded());
REQUIRE(c2->GetCurrentHealth() < c2->GetBoostedStat(PkmnLib::Library::Statistic::HealthPoints));
c2->Damage(c2->GetCurrentHealth(), CreatureLib::Battling::DamageSource::AttackDamage);
REQUIRE(battle->HasEnded());
auto result = battle->GetResult();
REQUIRE(result.IsConclusiveResult());
REQUIRE(result.GetWinningSide() == 0);
delete battle;
c2->Heal(1000, true);
REQUIRE(c2->GetCurrentHealth() == c2->GetMaxHealth());
}
#endif

View File

@@ -60,6 +60,7 @@ public:
static CreatureLib::Library::TypeLibrary* BuildTypeLibrary() {
auto lib = new CreatureLib::Library::TypeLibrary();
lib->RegisterType("testType1"_cnc);
return lib;
}