Fixes memory leak in struggle unit test, adds test for Ally Switch.
This commit is contained in:
parent
d44ba77795
commit
4b401e59d6
|
@ -0,0 +1,60 @@
|
|||
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
|
||||
#include <PkmnLib/Battling/Battle/Battle.hpp>
|
||||
#include <PkmnLib/Battling/Pokemon/CreatePokemon.hpp>
|
||||
#include "../../../../extern/doctest.hpp"
|
||||
#include "../../Macros/MoveMacros.hpp"
|
||||
|
||||
TEST_CASE("Ally Switch - Swaps two mons around") {
|
||||
auto library = Library::GetLibrary();
|
||||
auto userMon = PkmnLib::Battling::CreatePokemon(library, "charizard"_cnc, 50)
|
||||
.LearnMove("ally_switch"_cnc, CreatureLib::Battling::AttackLearnMethod::Unknown)
|
||||
.Build();
|
||||
auto userMon2 = PkmnLib::Battling::CreatePokemon(library, "blastoise"_cnc, 50).Build();
|
||||
auto foeMon = PkmnLib::Battling::CreatePokemon(library, "venusaur"_cnc, 50).Build();
|
||||
auto foeMon2 = PkmnLib::Battling::CreatePokemon(library, "pidgey"_cnc, 50).Build();
|
||||
|
||||
auto userParty = CreatureLib::Battling::CreatureParty({userMon, userMon2});
|
||||
auto targetParty = CreatureLib::Battling::CreatureParty({foeMon, foeMon2});
|
||||
auto battle = new PkmnLib::Battling::Battle(
|
||||
library,
|
||||
{
|
||||
new CreatureLib::Battling::BattleParty(
|
||||
&userParty, {CreatureLib::Battling::CreatureIndex(0, 0), CreatureLib::Battling::CreatureIndex(0, 1)}),
|
||||
new CreatureLib::Battling::BattleParty(
|
||||
&targetParty, {CreatureLib::Battling::CreatureIndex(1, 0), CreatureLib::Battling::CreatureIndex(1, 1)}),
|
||||
},
|
||||
false, 2, 2);
|
||||
|
||||
battle->SwitchCreature(0, 0, userMon);
|
||||
battle->SwitchCreature(0, 1, userMon2);
|
||||
battle->SwitchCreature(1, 0, foeMon);
|
||||
battle->SwitchCreature(1, 1, foeMon2);
|
||||
|
||||
auto moveData = library->GetMoveLibrary()->Get("ally_switch"_cnc);
|
||||
REQUIRE(moveData->HasSecondaryEffect());
|
||||
auto& effect = moveData->GetSecondaryEffect();
|
||||
auto script = library->LoadScript(ScriptCategory::Attack, effect->GetEffectName());
|
||||
REQUIRE(script != nullptr);
|
||||
script->OnInitialize(effect->GetParameters());
|
||||
|
||||
auto index1 = battle->GetSides()[0]->GetCreatureIndex(userMon);
|
||||
auto index2 = battle->GetSides()[0]->GetCreatureIndex(userMon2);
|
||||
CHECK(index1 == 0);
|
||||
CHECK(index2 == 1);
|
||||
CHECK(battle->GetCreature(0, 0).GetValue()->GetSpecies()->GetName() == "charizard"_cnc);
|
||||
CHECK(battle->GetCreature(0, 1).GetValue()->GetSpecies()->GetName() == "blastoise"_cnc);
|
||||
|
||||
auto executingMove = CreatureLib::Battling::ExecutingAttack(
|
||||
ArbUt::List<ArbUt::OptionalBorrowedPtr<CreatureLib::Battling::Creature>>{userMon2}, (uint8_t)1, userMon,
|
||||
userMon->GetMoves()[0], std::unique_ptr<AngelScriptScript::BattleScript>(script));
|
||||
script->OnSecondaryEffect(&executingMove, userMon2, 0);
|
||||
|
||||
index1 = battle->GetSides()[0]->GetCreatureIndex(userMon);
|
||||
index2 = battle->GetSides()[0]->GetCreatureIndex(userMon2);
|
||||
CHECK(index1 == 1);
|
||||
CHECK(index2 == 0);
|
||||
CHECK(battle->GetCreature(0, 0).GetValue()->GetSpecies()->GetName() == "blastoise"_cnc);
|
||||
CHECK(battle->GetCreature(0, 1).GetValue()->GetSpecies()->GetName() == "charizard"_cnc);
|
||||
|
||||
delete battle;
|
||||
}
|
|
@ -21,9 +21,9 @@ TEST_CASE("Struggle - Damages by 1/4th of users max health") {
|
|||
userMon->SetBattleData(battle, battle->GetSides()[0]);
|
||||
targetMon->SetBattleData(battle, battle->GetSides()[1]);
|
||||
|
||||
auto& script = ((CreatureLib::Battling::AttackTurnChoice*)library->GetMiscLibrary()->ReplacementAttack(
|
||||
userMon, CreatureLib::Battling::CreatureIndex(1, 0)))
|
||||
->GetAttackScript();
|
||||
auto move = ((CreatureLib::Battling::AttackTurnChoice*)library->GetMiscLibrary()->ReplacementAttack(
|
||||
userMon, CreatureLib::Battling::CreatureIndex(1, 0)));
|
||||
auto& script = move->GetAttackScript();
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
auto choice = (CreatureLib::Battling::AttackTurnChoice*)library->GetMiscLibrary()->ReplacementAttack(
|
||||
|
@ -37,4 +37,6 @@ TEST_CASE("Struggle - Damages by 1/4th of users max health") {
|
|||
delete targetParty;
|
||||
delete userParty;
|
||||
delete battle;
|
||||
delete move;
|
||||
delete choice;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ int main(int argc, char* argv[]) {
|
|||
{"workdir"});
|
||||
args::ValueFlag<std::string> _(parser, "Reporters", "List of reporters to use (default is console)",
|
||||
{'r', "reporters"});
|
||||
args::ValueFlag<std::string> __(parser, "", "", {'t', ""});
|
||||
|
||||
try {
|
||||
parser.ParseCLI(argc, argv);
|
||||
|
|
Loading…
Reference in New Issue