#include #include #include #include #include #include "../../../extern/catch.hpp" #include "../../Library.hpp" #define SETUP_MOVE_TEST(move) \ auto library = Library::GetLibrary(); \ auto userMon = PkmnLib::Battling::CreatePokemon(library, "charizard"_cnc, 50) \ .LearnMove(ArbUt::StringView(#move), CreatureLib::Battling::AttackLearnMethod::Unknown) \ .Build(); \ auto targetMon = PkmnLib::Battling::CreatePokemon(library, "venusaur"_cnc, 50).Build(); \ \ auto userParty = new CreatureLib::Battling::CreatureParty({userMon}); \ auto targetParty = new CreatureLib::Battling::CreatureParty({targetMon}); \ auto battle = new PkmnLib::Battling::Battle( \ library, \ { \ new CreatureLib::Battling::BattleParty(userParty, {CreatureLib::Battling::CreatureIndex(0, 0)}), \ new CreatureLib::Battling::BattleParty(targetParty, {CreatureLib::Battling::CreatureIndex(1, 0)}), \ }); \ \ userMon->SetBattleData(battle, battle->GetSides()[0]); \ targetMon->SetBattleData(battle, battle->GetSides()[1]); \ \ auto moveData = library->GetMoveLibrary()->Get(ArbUt::StringView(#move)); \ REQUIRE(moveData->HasSecondaryEffect()); \ auto& effect = moveData->GetSecondaryEffect(); \ auto script = library->LoadScript(ScriptCategory::Attack, effect->GetEffectName()); \ REQUIRE(script != nullptr); \ script->OnInitialize(effect->GetParameters()); \ \ auto executingMove = new CreatureLib::Battling::ExecutingAttack( \ ArbUt::List>{targetMon}, (uint8_t)1, userMon, \ userMon->GetMoves()[0], std::unique_ptr(script)); #define CLEANUP_MOVE_TEST \ delete executingMove; \ delete targetParty; \ delete userParty; \ delete battle; #define ON_MOVE_EFFECT_TRIGGER(move, onAfterCheck) \ TEST_CASE(#move " - On Effect Trigger", "[moves]") { \ SETUP_MOVE_TEST(move) \ \ battle->AddVolatileScript("TriggerEffectChance"_cnc); \ script->OnSecondaryEffect(executingMove, targetMon, 0); \ onAfterCheck; \ \ CLEANUP_MOVE_TEST \ } #define ON_MOVE_EFFECT_NO_TRIGGER(move, onAfterCheck) \ TEST_CASE(#move " - On Effect No Trigger", "[moves]") { \ SETUP_MOVE_TEST(move) \ \ battle->AddVolatileScript("BlockEffectChance"_cnc); \ script->OnSecondaryEffect(executingMove, targetMon, 0); \ onAfterCheck; \ \ CLEANUP_MOVE_TEST \ } #define MOVE_EFFECT_CHANCE(move, chance) \ TEST_CASE(#move " - Effect Chance = " #chance, "[moves]") { \ auto library = Library::GetLibrary(); \ auto move = library->GetMoveLibrary()->Get(ArbUt::StringView(#move)); \ REQUIRE(move->HasSecondaryEffect()); \ CHECK(move->GetSecondaryEffect()->GetChance() == chance); \ } #define CHANCE_BASED_MOVE(moveName, chance, onEffectCheck) \ ON_MOVE_EFFECT_TRIGGER(moveName, onEffectCheck) \ MOVE_EFFECT_CHANCE(moveName, chance) #define INCREASED_CRITICAL_RATE(moveName, expectedStage) \ TEST_CASE(#moveName " - Increased critical ratio", "[moves]") { \ SETUP_MOVE_TEST(moveName) \ \ auto pkmnScript = dynamic_cast(script); \ uint8_t critStage = 0; \ pkmnScript->ModifyCriticalStage(executingMove, userMon, 0, &critStage); \ CHECK(critStage == expectedStage); \ \ CLEANUP_MOVE_TEST \ } #define CHANGE_USER_STAT_MOVE(moveName, stat, stage, function) \ TEST_CASE(#moveName " - Change " #stat " by " #stage, "[moves]") { \ SETUP_MOVE_TEST(moveName) \ \ CHECK(userMon->GetStatBoost(PkmnLib::Library::Statistic::stat) == 0); \ script->function(executingMove, userMon, 0); \ CHECK(userMon->GetStatBoost(PkmnLib::Library::Statistic::stat) == stage); \ \ CLEANUP_MOVE_TEST \ } #define CHANGE_TARGET_STAT_MOVE(moveName, stat, stage, function) \ TEST_CASE(#moveName " - Change " #stat " by " #stage, "[moves]") { \ SETUP_MOVE_TEST(moveName) \ \ CHECK(targetMon->GetStatBoost(PkmnLib::Library::Statistic::stat) == 0); \ script->function(executingMove, targetMon, 0); \ CHECK(targetMon->GetStatBoost(PkmnLib::Library::Statistic::stat) == stage); \ \ CLEANUP_MOVE_TEST \ }