Initial work on easy handling of chance based move testing.
This commit is contained in:
parent
b931819aee
commit
3b6f6886e2
|
@ -26,4 +26,4 @@ class PkmnLibConan(ConanFile):
|
||||||
self.copy("*.dll", "bin", "bin")
|
self.copy("*.dll", "bin", "bin")
|
||||||
|
|
||||||
def requirements(self):
|
def requirements(self):
|
||||||
self.requires("PkmnLib/a31477d4cb787ae81dce63cda23e48a3635570ef@pkmnlib/master")
|
self.requires("PkmnLib/f9f83f892dab1557b801d4db9d382d9283cfc3cd@pkmnlib/master")
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#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"
|
||||||
|
|
||||||
|
#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);
|
||||||
|
|
||||||
|
#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); })
|
81
src/main.cpp
81
src/main.cpp
|
@ -1,5 +1,6 @@
|
||||||
#define CATCH_CONFIG_RUNNER
|
#define CATCH_CONFIG_RUNNER
|
||||||
#include <PkmnLib/ScriptResolving/AngelScript/AngelScripResolver.hpp>
|
#include <PkmnLib/ScriptResolving/AngelScript/AngelScripResolver.hpp>
|
||||||
|
#include <filesystem>
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/catch.hpp"
|
||||||
#include "BuildData/BuildItems.hpp"
|
#include "BuildData/BuildItems.hpp"
|
||||||
#include "BuildData/BuildMoves.hpp"
|
#include "BuildData/BuildMoves.hpp"
|
||||||
|
@ -11,32 +12,32 @@
|
||||||
|
|
||||||
static const char* ScriptsPath = nullptr;
|
static const char* ScriptsPath = nullptr;
|
||||||
|
|
||||||
static constexpr const char* GetCategoryPath(CreatureLib::Battling::ScriptResolver::ScriptCategory category){
|
//static constexpr const char* GetCategoryPath(CreatureLib::Battling::ScriptResolver::ScriptCategory category){
|
||||||
switch (category){
|
// switch (category){
|
||||||
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack: return "Moves";
|
// case CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack: return "Moves";
|
||||||
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Talent: return "Abilities";
|
// case CreatureLib::Battling::ScriptResolver::ScriptCategory::Talent: return "Abilities";
|
||||||
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Status: return "Status";
|
// case CreatureLib::Battling::ScriptResolver::ScriptCategory::Status: return "Status";
|
||||||
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Creature: return "Pokemon";
|
// case CreatureLib::Battling::ScriptResolver::ScriptCategory::Creature: return "Pokemon";
|
||||||
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Battle: return "Battle";
|
// case CreatureLib::Battling::ScriptResolver::ScriptCategory::Battle: return "Battle";
|
||||||
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Side: return "Side";
|
// case CreatureLib::Battling::ScriptResolver::ScriptCategory::Side: return "Side";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
static const char* LoadFunc(CreatureLib::Battling::ScriptResolver::ScriptCategory category, const char* scriptName){
|
//static const char* LoadFunc(CreatureLib::Battling::ScriptResolver::ScriptCategory category, const char* scriptName){
|
||||||
auto categoryStr = GetCategoryPath(category);
|
// auto categoryStr = GetCategoryPath(category);
|
||||||
char fullPath[strlen(ScriptsPath) + 1 + strlen(categoryStr) + 1 + strlen(scriptName) + 3];
|
// char fullPath[strlen(ScriptsPath) + 1 + strlen(categoryStr) + 1 + strlen(scriptName) + 3];
|
||||||
strcpy(fullPath, ScriptsPath);
|
// strcpy(fullPath, ScriptsPath);
|
||||||
strcat(fullPath, "/");
|
// strcat(fullPath, "/");
|
||||||
strcat(fullPath, categoryStr);
|
// strcat(fullPath, categoryStr);
|
||||||
strcat(fullPath, "/");
|
// strcat(fullPath, "/");
|
||||||
strcat(fullPath, scriptName);
|
// strcat(fullPath, scriptName);
|
||||||
strcat(fullPath, ".as");
|
// strcat(fullPath, ".as");
|
||||||
std::ifstream in(fullPath);
|
// std::ifstream in(fullPath);
|
||||||
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
// std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
||||||
char res[contents.size()];
|
// char res[contents.size()];
|
||||||
return strcpy(res, contents.c_str());
|
// return strcpy(res, contents.c_str());
|
||||||
}
|
//}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
Catch::Session session;
|
Catch::Session session;
|
||||||
|
@ -89,8 +90,36 @@ int main(int argc, char* argv[]) {
|
||||||
scriptResolver->Initialize(battleLib);
|
scriptResolver->Initialize(battleLib);
|
||||||
|
|
||||||
auto asScriptResolver = dynamic_cast<AngelScripResolver*>(scriptResolver);
|
auto asScriptResolver = dynamic_cast<AngelScripResolver*>(scriptResolver);
|
||||||
asScriptResolver->SetCreateFunction(LoadFunc);
|
|
||||||
asScriptResolver->CreateScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, "absorb");
|
for (const auto& dirEntry : std::filesystem::recursive_directory_iterator(ScriptsPath)){
|
||||||
|
if (dirEntry.is_directory())
|
||||||
|
continue;
|
||||||
|
if (dirEntry.path().parent_path().stem() == "Interfaces")
|
||||||
|
continue;
|
||||||
|
if (dirEntry.path().extension() != ".as")
|
||||||
|
continue;
|
||||||
|
std::ifstream in(dirEntry.path());
|
||||||
|
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
||||||
|
asScriptResolver->CreateScript(dirEntry.path().filename().c_str(), contents.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
asScriptResolver->CreateScript("TriggerEffectChance", R"(
|
||||||
|
namespace Battle{ class TriggerEffectChance : PkmnScript {
|
||||||
|
void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance) override{chance = 10000;} }
|
||||||
|
})");
|
||||||
|
asScriptResolver->CreateScript("BlockEffectChance", R"(
|
||||||
|
namespace Battle{ class BlockEffectChance : PkmnScript {
|
||||||
|
void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance) override{chance = -10000;} }
|
||||||
|
})");
|
||||||
|
asScriptResolver->CreateScript("SaveEffectChance", R"(
|
||||||
|
namespace Battle{ class SaveEffectChance : PkmnScript {
|
||||||
|
float _chance;
|
||||||
|
void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance) override{_chance = chance;}
|
||||||
|
float GetChance() { return _chance; }
|
||||||
|
}
|
||||||
|
})");
|
||||||
|
|
||||||
|
|
||||||
asScriptResolver->FinalizeModule();
|
asScriptResolver->FinalizeModule();
|
||||||
|
|
||||||
Library::SetStaticLib(staticLibrary);
|
Library::SetStaticLib(staticLibrary);
|
||||||
|
|
Loading…
Reference in New Issue