More tests, initial tests for Absorb

This commit is contained in:
Deukhoofd 2020-02-16 13:08:04 +01:00
parent 380086d358
commit b931819aee
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
7 changed files with 161 additions and 11 deletions

View File

@ -26,4 +26,4 @@ class PkmnLibConan(ConanFile):
self.copy("*.dll", "bin", "bin")
def requirements(self):
self.requires("PkmnLib/eeedbdac030b9dc72b5e70b215f4fe7173a42f46@pkmnlib/master")
self.requires("PkmnLib/a31477d4cb787ae81dce63cda23e48a3635570ef@pkmnlib/master")

View File

@ -48,7 +48,7 @@ PkmnLib::Library::ItemLibrary* BuildItems::Build(const std::string& path) {
auto item = new PkmnLib::Library::Item(
_name.get<std::string>(), itemType, CreatureLib::Library::BattleItemCategory::None, _price.get<int32_t>(),
_flags.get<std::unordered_set<std::string>>(), _flingPower.get<uint8_t>());
lib->LoadItem(item->GetName(), item);
lib->Insert(item->GetName().c_str(), item);
}
return lib;
}

View File

@ -51,9 +51,7 @@ PkmnLib::Library::MoveLibrary* BuildMoves::Build(const std::string& path,
if (static_cast<int>(category) == 255)
return nullptr;
CreatureLib::Library::AttackTarget target;
try {
target = CreatureLib::Library::AttackTargetHelper::Parse(_target.get<std::string>(), true);
} catch (const CreatureException& e) {
if (!CreatureLib::Library::AttackTargetHelper::TryParse(_target.get<std::string>().c_str(), target)){
std::cout << "Invalid target: '" << _target.get<std::string>() << "' for move with name '"
<< _name.get<std::string>() << "'\n";
return nullptr;
@ -62,7 +60,7 @@ PkmnLib::Library::MoveLibrary* BuildMoves::Build(const std::string& path,
_name.get<std::string>(), type, category, _power.get<uint8_t>(), _accuracy.get<uint8_t>(),
_pp.get<uint8_t>(), target, _priority.get<int8_t>(), _flags.get<std::unordered_set<std::string>>());
lib->LoadAttack(move->GetName(), move);
lib->Insert(move->GetName().c_str(), move);
}
return lib;

View File

@ -60,6 +60,11 @@ PkmnLib::Library::SpeciesLibrary* BuildSpecies::BuildLibrary(const std::string&
static_cast<float>(_genderRatio.get<int8_t>()) / static_cast<float>(100),
_growthRate.get<std::string>(), _catchRate.get<uint8_t>(), _baseHappiness.get<uint8_t>());
} else {
if (species->HasForme(formeIt.key())){
std::cout << "Species '" << it.key() << "' has duplicate forme '" << formeIt.key() << "'. Skipping.\n";
delete forme;
continue;
}
species->SetVariant(formeIt.key(), forme);
}
}
@ -67,7 +72,7 @@ PkmnLib::Library::SpeciesLibrary* BuildSpecies::BuildLibrary(const std::string&
std::cout << "Pokemon with key '" << it.key() << "' does not have any formes.\n";
return nullptr;
}
lib->LoadSpecies(it.key(), species);
lib->Insert(it.key().c_str(), species);
}
return lib;
}

View File

@ -0,0 +1,43 @@
#include "../../extern/catch.hpp"
#include "../Library.hpp"
#define ENSURE_SPECIES_EXISTS(species) \
CHECK(library->GetSpeciesLibrary()->Get(#species)->GetName() == #species);
TEST_CASE("Species - Ensure relevant species exist", "[species]") {
auto library = Library::GetLibrary();
ENSURE_SPECIES_EXISTS(charizard);
ENSURE_SPECIES_EXISTS(pikachu);
}
TEST_CASE("Species - Ensure species count is valid", "[species]") {
auto library = Library::GetLibrary();
CHECK(library->GetSpeciesLibrary()->GetCount() == 802);
}
TEST_CASE("Species - Ensure each species has a default forme", "[species]") {
auto library = Library::GetLibrary();
auto iterator = library->GetSpeciesLibrary()->GetIterator();
size_t i = 0;
for (const auto& v: iterator){
REQUIRE(v.second->HasVariant("default"));
CHECK(v.second->GetVariant("default")->GetName() == "default");
i++;
}
REQUIRE(i == 802);
}
TEST_CASE("Species - Ensure each forme has abilities", "[species]") {
auto library = Library::GetLibrary();
auto iterator = library->GetSpeciesLibrary()->GetIterator();
size_t i = 0;
for (const auto& v: iterator){
for (const auto& forme: v.second->GetVariantsIterator()){
auto abilities = forme.second->GetTalents();
CHECK(!abilities.empty());
}
i++;
}
REQUIRE(i == 802);
}

View File

@ -0,0 +1,57 @@
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
#include <PkmnLib/Battling/Pokemon/CreatePokemon.hpp>
#include "../../../extern/catch.hpp"
#include "../../Library.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);
auto script = library->LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, "Absorb");
REQUIRE(script != nullptr);
try{
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;
}
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);
auto script = library->LoadScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, "Absorb");
REQUIRE(script != nullptr);
try{
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;
}

View File

@ -1,4 +1,5 @@
#define CATCH_CONFIG_RUNNER
#include <PkmnLib/ScriptResolving/AngelScript/AngelScripResolver.hpp>
#include "../extern/catch.hpp"
#include "BuildData/BuildItems.hpp"
#include "BuildData/BuildMoves.hpp"
@ -8,6 +9,35 @@
#include "BuildData/GrowthRatesBuilder.hpp"
#include "Library.hpp"
static const char* ScriptsPath = nullptr;
static constexpr const char* GetCategoryPath(CreatureLib::Battling::ScriptResolver::ScriptCategory category){
switch (category){
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack: return "Moves";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Talent: return "Abilities";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Status: return "Status";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Creature: return "Pokemon";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Battle: return "Battle";
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Side: return "Side";
}
}
static const char* LoadFunc(CreatureLib::Battling::ScriptResolver::ScriptCategory category, const char* scriptName){
auto categoryStr = GetCategoryPath(category);
char fullPath[strlen(ScriptsPath) + 1 + strlen(categoryStr) + 1 + strlen(scriptName) + 3];
strcpy(fullPath, ScriptsPath);
strcat(fullPath, "/");
strcat(fullPath, categoryStr);
strcat(fullPath, "/");
strcat(fullPath, scriptName);
strcat(fullPath, ".as");
std::ifstream in(fullPath);
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
char res[contents.size()];
return strcpy(res, contents.c_str());
}
int main(int argc, char* argv[]) {
Catch::Session session;
@ -17,6 +47,7 @@ int main(int argc, char* argv[]) {
std::string moveFile = "Moves.json";
std::string itemsFile = "Items.json";
std::string growthRatesFile = "GrowthRates.json";
std::string scriptsPath = "Scripts";
using namespace Catch::clara;
auto cli = session.cli() | Opt(pokemonFile, "Species")["--species"]("Which species file to load.") |
@ -24,7 +55,8 @@ int main(int argc, char* argv[]) {
Opt(naturesFile, "Natures")["--natures"]("Which Natures file to load.") |
Opt(moveFile, "Moves")["--moves"]("Which Moves file to load.") |
Opt(itemsFile, "Items")["--items"]("Which Items file to load.") |
Opt(growthRatesFile, "Growthrates")["--growthrates"]("Which Growthrates file to load.");
Opt(growthRatesFile, "Growthrates")["--growthrates"]("Which Growthrates file to load.") |
Opt(scriptsPath, "Scripts")["--scripts"]("Which Scripts path to load scripts from.");
session.cli(cli);
@ -38,16 +70,31 @@ int main(int argc, char* argv[]) {
auto movesLibrary = BuildMoves::Build(moveFile, typesLibrary);
auto itemsLibrary = BuildItems::Build(itemsFile);
auto growthRates = GrowthRatesBuilder::Build(growthRatesFile);
ScriptsPath = scriptsPath.c_str();
if (typesLibrary == nullptr || speciesLibrary == nullptr || natureLibrary == nullptr || movesLibrary == nullptr ||
itemsLibrary == nullptr || growthRates == nullptr)
return 1;
auto settings = new PkmnLib::Library::LibrarySettings(100, 4, 4096);
auto library = new PkmnLib::Library::PokemonLibrary(settings, speciesLibrary, movesLibrary, itemsLibrary,
growthRates, typesLibrary, natureLibrary);
auto staticLibrary = new PkmnLib::Library::PokemonLibrary(settings, speciesLibrary, movesLibrary, itemsLibrary,
growthRates, typesLibrary, natureLibrary);
Library::SetStaticLib(library);
auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
auto battleLib = new PkmnLib::Battling::BattleLibrary(
staticLibrary, new PkmnLib::Battling::StatCalculator(), new PkmnLib::Battling::DamageLibrary(),
new CreatureLib::Battling::ExperienceLibrary(), scriptResolver, new CreatureLib::Battling::MiscLibrary());
scriptResolver->Initialize(battleLib);
auto asScriptResolver = dynamic_cast<AngelScripResolver*>(scriptResolver);
asScriptResolver->SetCreateFunction(LoadFunc);
asScriptResolver->CreateScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, "absorb");
asScriptResolver->FinalizeModule();
Library::SetStaticLib(staticLibrary);
Library::SetLibrary(battleLib);
return session.run();
}