Reorganization and cleanup of tests
This commit is contained in:
parent
3b6f6886e2
commit
0f49d03c6e
|
@ -26,4 +26,4 @@ class PkmnLibConan(ConanFile):
|
|||
self.copy("*.dll", "bin", "bin")
|
||||
|
||||
def requirements(self):
|
||||
self.requires("PkmnLib/f9f83f892dab1557b801d4db9d382d9283cfc3cd@pkmnlib/master")
|
||||
self.requires("PkmnLib/93be2ee8a1a11cd106136f703ac0c2b2e0cb9e60@pkmnlib/master")
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
#include <PkmnLib/Battling/Battle/Battle.hpp>
|
||||
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
|
||||
#include <PkmnLib/Battling/Pokemon/CreatePokemon.hpp>
|
||||
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptScript.hpp>
|
||||
#include "../../Library.hpp"
|
||||
#include "../../../extern/catch.hpp"
|
||||
|
||||
#define SETUP_MOVE_TEST(move) \
|
||||
auto library = Library::GetLibrary(); \
|
||||
auto userMon = PkmnLib::Battling::CreatePokemon(library, "charizard", 50) \
|
||||
.LearnMove(#move, CreatureLib::Battling::AttackLearnMethod::Unknown) \
|
||||
->Build(); \
|
||||
auto targetMon = PkmnLib::Battling::CreatePokemon(library, "venusaur", 50).Build(); \
|
||||
\
|
||||
auto userParty = new CreatureLib::Battling::CreatureParty({userMon}); \
|
||||
auto targetParty = new CreatureLib::Battling::CreatureParty({targetMon}); \
|
||||
auto battle = new PkmnLib::Battling::Battle( \
|
||||
library, { \
|
||||
CreatureLib::Battling::BattleParty(userParty, {CreatureLib::Battling::CreatureIndex(0, 0)}), \
|
||||
CreatureLib::Battling::BattleParty(targetParty, {CreatureLib::Battling::CreatureIndex(1, 0)}), \
|
||||
}); \
|
||||
\
|
||||
userMon->SetBattleData(battle, battle->GetSides()[0]); \
|
||||
targetMon->SetBattleData(battle, battle->GetSides()[1]); \
|
||||
\
|
||||
auto script = library->LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, #move); \
|
||||
REQUIRE(script != nullptr); \
|
||||
\
|
||||
auto executingMove = \
|
||||
new CreatureLib::Battling::ExecutingAttack({targetMon}, 1, userMon, userMon->GetMoves()[0], 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"); \
|
||||
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"); \
|
||||
script->OnSecondaryEffect(executingMove, targetMon, 0); \
|
||||
onAfterCheck; \
|
||||
\
|
||||
CLEANUP_MOVE_TEST \
|
||||
}
|
||||
|
||||
#define MOVE_EFFECT_CHANCE(move, chance) \
|
||||
TEST_CASE(#move " - Effect Chance = " #chance, "[moves]") { \
|
||||
SETUP_MOVE_TEST(move) \
|
||||
\
|
||||
battle->AddVolatileScript("SaveEffectChance"); \
|
||||
script->OnSecondaryEffect(executingMove, targetMon, 0); \
|
||||
\
|
||||
auto saveScript = dynamic_cast<AngelScriptScript*>(battle->GetVolatileScript("SaveEffectChance")); \
|
||||
\
|
||||
auto ctx = saveScript->GetContextPool()->RequestContext(); \
|
||||
saveScript->PrepareMethod("GetChance", ctx); \
|
||||
ctx->Execute(); \
|
||||
auto result = ctx->GetReturnFloat(); \
|
||||
CHECK(result == Approx(chance)); \
|
||||
saveScript->GetContextPool()->ReturnContextToPool(ctx); \
|
||||
\
|
||||
CLEANUP_MOVE_TEST \
|
||||
}
|
||||
|
||||
#define CHANCE_BASED_MOVE(moveName, chance, onEffectCheck, onNoEffectCheck) \
|
||||
ON_MOVE_EFFECT_TRIGGER(moveName, onEffectCheck) \
|
||||
ON_MOVE_EFFECT_NO_TRIGGER(moveName, onNoEffectCheck) \
|
||||
MOVE_EFFECT_CHANCE(moveName, chance)
|
|
@ -1,57 +1,28 @@
|
|||
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
|
||||
#include <PkmnLib/Battling/Pokemon/CreatePokemon.hpp>
|
||||
#include <PkmnLib/Battling/Battle/Battle.hpp>
|
||||
#include "../../../extern/catch.hpp"
|
||||
#include "../../Library.hpp"
|
||||
#include "../Macros/MoveMacros.hpp"
|
||||
|
||||
TEST_CASE("Absorb - Heals on use", "[moves]") {
|
||||
auto library = Library::GetLibrary();
|
||||
auto userMon = PkmnLib::Battling::CreatePokemon(library, "charizard", 50)
|
||||
.LearnMove("absorb", CreatureLib::Battling::AttackLearnMethod::Unknown)
|
||||
->Build();
|
||||
userMon->Damage(50, CreatureLib::Battling::DamageSource::AttackDamage);
|
||||
auto targetMon = PkmnLib::Battling::CreatePokemon(library, "venusaur", 50).Build();
|
||||
auto executingMove =
|
||||
new CreatureLib::Battling::ExecutingAttack({targetMon}, 1, userMon, userMon->GetMoves()[0], nullptr);
|
||||
executingMove->GetAttackDataForTarget(targetMon)->GetHit(0)->SetDamage(50);
|
||||
SETUP_MOVE_TEST(Absorb)
|
||||
|
||||
auto script = library->LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, "Absorb");
|
||||
REQUIRE(script != nullptr);
|
||||
try{
|
||||
userMon->Damage(50, CreatureLib::Battling::DamageSource::AttackDamage);
|
||||
executingMove->GetAttackDataForTarget(targetMon)->GetHit(0)->SetDamage(50);
|
||||
script->OnSecondaryEffect(executingMove, targetMon, 0);
|
||||
}
|
||||
catch (const CreatureException& e){
|
||||
FAIL(e.what());
|
||||
}
|
||||
CHECK(userMon->GetCurrentHealth() == userMon->GetMaxHealth() - 25);
|
||||
delete script;
|
||||
delete executingMove;
|
||||
delete targetMon;
|
||||
delete userMon;
|
||||
|
||||
CLEANUP_MOVE_TEST
|
||||
}
|
||||
|
||||
TEST_CASE("Absorb - Heals more with big root", "[moves]") {
|
||||
auto library = Library::GetLibrary();
|
||||
auto userMon = PkmnLib::Battling::CreatePokemon(library, "charizard", 50)
|
||||
.LearnMove("absorb", CreatureLib::Battling::AttackLearnMethod::Unknown)
|
||||
->WithHeldItem("big_root")
|
||||
->Build();
|
||||
userMon->Damage(50, CreatureLib::Battling::DamageSource::AttackDamage);
|
||||
auto targetMon = PkmnLib::Battling::CreatePokemon(library, "venusaur", 50).Build();
|
||||
auto executingMove =
|
||||
new CreatureLib::Battling::ExecutingAttack({targetMon}, 1, userMon, userMon->GetMoves()[0], nullptr);
|
||||
executingMove->GetAttackDataForTarget(targetMon)->GetHit(0)->SetDamage(50);
|
||||
SETUP_MOVE_TEST(Absorb)
|
||||
|
||||
auto script = library->LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, "Absorb");
|
||||
REQUIRE(script != nullptr);
|
||||
try{
|
||||
userMon->Damage(50, CreatureLib::Battling::DamageSource::AttackDamage);
|
||||
executingMove->GetAttackDataForTarget(targetMon)->GetHit(0)->SetDamage(50);
|
||||
userMon->SetHeldItem("big_root");
|
||||
script->OnSecondaryEffect(executingMove, targetMon, 0);
|
||||
}
|
||||
catch (const CreatureException& e){
|
||||
FAIL(e.what());
|
||||
}
|
||||
CHECK(userMon->GetCurrentHealth() == userMon->GetMaxHealth() - 18);
|
||||
delete script;
|
||||
delete executingMove;
|
||||
delete targetMon;
|
||||
delete userMon;
|
||||
|
||||
CLEANUP_MOVE_TEST
|
||||
}
|
||||
|
|
|
@ -1,60 +1,9 @@
|
|||
#include <CreatureLib/Battling/Models/Battle.hpp>
|
||||
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
|
||||
#include <PkmnLib/Battling/Pokemon/CreatePokemon.hpp>
|
||||
#include "../../../extern/catch.hpp"
|
||||
#include "../../Library.hpp"
|
||||
#include "../Macros/MoveMacros.hpp"
|
||||
|
||||
#define SETUP_MOVE_TEST(move) \
|
||||
auto library = Library::GetLibrary(); \
|
||||
auto userMon = PkmnLib::Battling::CreatePokemon(library, "charizard", 50) \
|
||||
.LearnMove(#move, CreatureLib::Battling::AttackLearnMethod::Unknown) \
|
||||
->Build(); \
|
||||
auto targetMon = PkmnLib::Battling::CreatePokemon(library, "venusaur", 50).Build(); \
|
||||
\
|
||||
auto userParty = new CreatureLib::Battling::CreatureParty({userMon}); \
|
||||
auto targetParty = new CreatureLib::Battling::CreatureParty({targetMon}); \
|
||||
auto battle = new CreatureLib::Battling::Battle( \
|
||||
library, { \
|
||||
CreatureLib::Battling::BattleParty(userParty, {CreatureLib::Battling::CreatureIndex(0, 0)}), \
|
||||
CreatureLib::Battling::BattleParty(targetParty, {CreatureLib::Battling::CreatureIndex(1, 0)}), \
|
||||
}); \
|
||||
\
|
||||
userMon->SetBattleData(battle, battle->GetSides()[0]); \
|
||||
targetMon->SetBattleData(battle, battle->GetSides()[1]); \
|
||||
\
|
||||
auto script = library->LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, #move); \
|
||||
REQUIRE(script != nullptr); \
|
||||
\
|
||||
auto executingMove = \
|
||||
new CreatureLib::Battling::ExecutingAttack({targetMon}, 1, userMon, userMon->GetMoves()[0], script);
|
||||
using Stats = PkmnLib::Library::Statistic;
|
||||
|
||||
#define ON_MOVE_EFFECT_TRIGGER(move, onAfterCheck) \
|
||||
TEST_CASE(#move " - On Effect Trigger", "[moves]") { \
|
||||
SETUP_MOVE_TEST(move) \
|
||||
executingMove->GetAttackDataForTarget(targetMon)->GetHit(0)->SetDamage(50); \
|
||||
\
|
||||
battle->AddVolatileScript("TriggerEffectChance"); \
|
||||
script->OnSecondaryEffect(executingMove, targetMon, 0); \
|
||||
onAfterCheck; \
|
||||
\
|
||||
delete executingMove; \
|
||||
delete targetParty; \
|
||||
delete userParty; \
|
||||
}
|
||||
|
||||
#define ON_MOVE_EFFECT_NO_TRIGGER(move, onAfterCheck) \
|
||||
TEST_CASE(#move " - On Effect No Trigger", "[moves]") { \
|
||||
SETUP_MOVE_TEST(move) \
|
||||
executingMove->GetAttackDataForTarget(targetMon)->GetHit(0)->SetDamage(50); \
|
||||
\
|
||||
battle->AddVolatileScript("BlockEffectChance"); \
|
||||
script->OnSecondaryEffect(executingMove, targetMon, 0); \
|
||||
onAfterCheck; \
|
||||
\
|
||||
delete executingMove; \
|
||||
delete targetParty; \
|
||||
delete userParty; \
|
||||
}
|
||||
|
||||
ON_MOVE_EFFECT_TRIGGER(Acid, { CHECK(targetMon->GetStatBoost(PkmnLib::Library::Statistic::SpecialDefense) == -1); })
|
||||
ON_MOVE_EFFECT_NO_TRIGGER(Acid, { CHECK(targetMon->GetStatBoost(PkmnLib::Library::Statistic::SpecialDefense) == 0); })
|
||||
CHANCE_BASED_MOVE(
|
||||
Acid, 10,
|
||||
{ CHECK(targetMon->GetStatBoost(Stats::SpecialDefense) == -1); },
|
||||
{ CHECK(targetMon->GetStatBoost(Stats::SpecialDefense) == 0); }
|
||||
);
|
|
@ -113,7 +113,7 @@ namespace Battle{ class BlockEffectChance : PkmnScript {
|
|||
})");
|
||||
asScriptResolver->CreateScript("SaveEffectChance", R"(
|
||||
namespace Battle{ class SaveEffectChance : PkmnScript {
|
||||
float _chance;
|
||||
float _chance = 0;
|
||||
void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance) override{_chance = chance;}
|
||||
float GetChance() { return _chance; }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue