Update PkmnLib, several new tests.

This commit is contained in:
Deukhoofd 2020-02-27 19:50:49 +01:00
parent d0b3e1aec2
commit 525c748b91
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
14 changed files with 96 additions and 63 deletions

View File

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

View File

@ -12,16 +12,23 @@ using json = nlohmann::json;
return nullptr; \
}
static CreatureLib::Library::ItemCategory ParseItemCategory(std::string& in){
std::transform(in.begin(),in.end(),in.end(), tolower);
if (in == "item") return CreatureLib::Library::ItemCategory::MiscItem;
if (in == "medicine") return CreatureLib::Library::ItemCategory::Medicine;
if (in == "berry") return CreatureLib::Library::ItemCategory::Berry;
if (in == "mail") return CreatureLib::Library::ItemCategory::Mail;
if (in == "key") return CreatureLib::Library::ItemCategory::KeyItem;
if (in == "pokeball") return CreatureLib::Library::ItemCategory::CaptureDevice;
if (in == "tm") return CreatureLib::Library::ItemCategory::MoveLearner;
std::cout << "Unknown Item Type: '" << in <<"'\n";
static CreatureLib::Library::ItemCategory ParseItemCategory(std::string& in) {
std::transform(in.begin(), in.end(), in.end(), tolower);
if (in == "item")
return CreatureLib::Library::ItemCategory::MiscItem;
if (in == "medicine")
return CreatureLib::Library::ItemCategory::Medicine;
if (in == "berry")
return CreatureLib::Library::ItemCategory::Berry;
if (in == "mail")
return CreatureLib::Library::ItemCategory::Mail;
if (in == "key")
return CreatureLib::Library::ItemCategory::KeyItem;
if (in == "pokeball")
return CreatureLib::Library::ItemCategory::CaptureDevice;
if (in == "tm")
return CreatureLib::Library::ItemCategory::MoveLearner;
std::cout << "Unknown Item Type: '" << in << "'\n";
return static_cast<CreatureLib::Library::ItemCategory>(255);
}
@ -43,12 +50,18 @@ PkmnLib::Library::ItemLibrary* BuildItems::Build(const std::string& path) {
GET(val, flingPower, i);
auto itemTypeStr = _itemType.get<std::string>();
CreatureLib::Library::ItemCategory itemType = ParseItemCategory(itemTypeStr);
if (static_cast<int>(itemType) == 255) return nullptr;
if (static_cast<int>(itemType) == 255)
return nullptr;
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->Insert(item->GetName().c_str(), item);
auto flags = std::unordered_set<Arbutils::CaseInsensitiveConstString>();
for (auto flagIndex : _flags.items()) {
flags.insert(Arbutils::CaseInsensitiveConstString(flagIndex.value().get<std::string>()));
}
auto item = new PkmnLib::Library::Item(Arbutils::CaseInsensitiveConstString(_name.get<std::string>()), itemType,
CreatureLib::Library::BattleItemCategory::None, _price.get<int32_t>(),
flags, _flingPower.get<uint8_t>());
lib->Insert(item->GetName(), item);
}
return lib;
}

View File

@ -51,16 +51,21 @@ PkmnLib::Library::MoveLibrary* BuildMoves::Build(const std::string& path,
if (static_cast<int>(category) == 255)
return nullptr;
CreatureLib::Library::AttackTarget target;
if (!CreatureLib::Library::AttackTargetHelper::TryParse(_target.get<std::string>().c_str(), target)){
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;
}
auto flags = std::unordered_set<Arbutils::CaseInsensitiveConstString>();
for (auto flagIndex : _flags.items()) {
flags.insert(Arbutils::CaseInsensitiveConstString(flagIndex.value().get<std::string>()));
}
auto move = new PkmnLib::Library::MoveData(
_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>>());
_pp.get<uint8_t>(), target, _priority.get<int8_t>(), flags);
lib->Insert(move->GetName().c_str(), move);
lib->Insert(Arbutils::CaseInsensitiveConstString(move->GetName()), move);
}
return lib;

View File

@ -41,10 +41,11 @@ PkmnLib::Library::SpeciesLibrary* BuildSpecies::BuildLibrary(const std::string&
auto defaultForme = _formes["default"];
if (!defaultForme.is_null()) {
auto forme = BuildForme("default", defaultForme, it.key(), path, types);
species = new PkmnLib::Library::PokemonSpecies(_id.get<uint16_t>(), _species.get<std::string>(), forme,
_genderRatio.get<int8_t>() / static_cast<float>(100),
_growthRate.get<std::string>(), _catchRate.get<uint8_t>(),
_baseHappiness.get<uint8_t>());
species = new PkmnLib::Library::PokemonSpecies(
_id.get<uint16_t>(), Arbutils::CaseInsensitiveConstString(_species.get<std::string>()), forme,
_genderRatio.get<int8_t>() / static_cast<float>(100),
Arbutils::CaseInsensitiveConstString(_growthRate.get<std::string>()), _catchRate.get<uint8_t>(),
_baseHappiness.get<uint8_t>());
}
for (json::iterator formeIt = _formes.begin(); formeIt != _formes.end(); ++formeIt) {
@ -56,23 +57,25 @@ PkmnLib::Library::SpeciesLibrary* BuildSpecies::BuildLibrary(const std::string&
return nullptr;
if (species == nullptr) {
species = new PkmnLib::Library::PokemonSpecies(
_id.get<uint16_t>(), _species.get<std::string>(), forme,
_id.get<uint16_t>(), Arbutils::CaseInsensitiveConstString(_species.get<std::string>()), forme,
static_cast<float>(_genderRatio.get<int8_t>()) / static_cast<float>(100),
_growthRate.get<std::string>(), _catchRate.get<uint8_t>(), _baseHappiness.get<uint8_t>());
Arbutils::CaseInsensitiveConstString(_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";
if (species->HasForme(Arbutils::CaseInsensitiveConstString(formeIt.key()))) {
std::cout << "Species '" << it.key() << "' has duplicate forme '" << formeIt.key()
<< "'. Skipping.\n";
delete forme;
continue;
}
species->SetVariant(formeIt.key(), forme);
species->SetVariant(Arbutils::CaseInsensitiveConstString(formeIt.key()), forme);
}
}
if (species == nullptr) {
std::cout << "Pokemon with key '" << it.key() << "' does not have any formes.\n";
return nullptr;
}
lib->Insert(it.key().c_str(), species);
lib->Insert(Arbutils::CaseInsensitiveConstString(it.key()), species);
}
return lib;
}

View File

@ -4,7 +4,6 @@
#include "../../extern/json.hpp"
using json = nlohmann::json;
CreatureLib::Library::GrowthRateLibrary* GrowthRatesBuilder::Build(const std::string& path) {
std::ifstream fileStream(path.c_str());
if (fileStream.fail()) {
@ -18,7 +17,8 @@ CreatureLib::Library::GrowthRateLibrary* GrowthRatesBuilder::Build(const std::st
for (const auto& i : j.items()) {
const auto& name = i.key();
auto values = i.value();
lib->AddGrowthRate(name, new LookupGrowthRate(values.get<std::vector<uint32_t >>()));
lib->AddGrowthRate(Arbutils::CaseInsensitiveConstString(name),
new LookupGrowthRate(values.get<std::vector<uint32_t>>()));
}
return lib;

View File

@ -2,7 +2,7 @@
#include "../Library.hpp"
#define ENSURE_SPECIES_EXISTS(species) \
CHECK(library->GetSpeciesLibrary()->Get(#species)->GetName() == #species);
CHECK(library->GetSpeciesLibrary()->Get(Arbutils::CaseInsensitiveConstString(#species))->GetName() == #species);
TEST_CASE("Species - Ensure relevant species exist", "[species]") {
@ -21,8 +21,8 @@ TEST_CASE("Species - Ensure each species has a default forme", "[species]") {
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");
REQUIRE(v.second->HasVariant("default"_cnc));
CHECK(v.second->GetVariant("default"_cnc)->GetName() == "default");
i++;
}
REQUIRE(i == 802);

View File

@ -8,10 +8,11 @@
#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 userMon = \
PkmnLib::Battling::CreatePokemon(library, "charizard"_cnc, 50) \
.LearnMove(Arbutils::CaseInsensitiveConstString(#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}); \
@ -83,13 +84,35 @@
MOVE_EFFECT_CHANCE(moveName, chance)
#define INCREASED_CRITICAL_RATE(moveName, expectedStage) \
TEST_CASE(#moveName " - Increased critical ratio", "[moves]") { \
SETUP_MOVE_TEST(moveName) \
TEST_CASE(#moveName " - Increased critical ratio", "[moves]") { \
SETUP_MOVE_TEST(moveName) \
\
auto pkmnScript = dynamic_cast<PkmnLib::Battling::PkmnScript*>(script); \
uint8_t critStage = 0; \
pkmnScript->ModifyCriticalStage(executingMove, userMon, 0, &critStage); \
CHECK(critStage == expectedStage); \
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 \
}

View File

@ -20,7 +20,7 @@ TEST_CASE("Absorb - Heals more with big root", "[moves]") {
userMon->Damage(50, CreatureLib::Battling::DamageSource::AttackDamage);
executingMove->GetAttackDataForTarget(targetMon)->GetHit(0)->SetDamage(50);
userMon->SetHeldItem("big_root");
userMon->SetHeldItem("big_root"_cnc);
script->OnSecondaryEffect(executingMove, targetMon, 0);
CHECK(userMon->GetCurrentHealth() == userMon->GetMaxHealth() - 18);

View File

@ -1,12 +1,3 @@
#include "../../Macros/MoveMacros.hpp"
using Stats = PkmnLib::Library::Statistic;
TEST_CASE("AcidArmor - Increases defense by 2", "[moves]") {
SETUP_MOVE_TEST(Acid_Armor)
CHECK(userMon->GetStatBoost(Stats::PhysicalDefense) == 0);
script->OnStatusMove(executingMove, userMon, 0);
CHECK(userMon->GetStatBoost(Stats::PhysicalDefense) == 2);
CLEANUP_MOVE_TEST
}
CHANGE_USER_STAT_MOVE(Acid_Armor, PhysicalDefense, 2, OnStatusMove);

View File

@ -1,12 +1,3 @@
#include "../../Macros/MoveMacros.hpp"
using Stats = PkmnLib::Library::Statistic;
TEST_CASE("AcidSpray - Increases defense by 2", "[moves]") {
SETUP_MOVE_TEST(Acid_Spray)
CHECK(userMon->GetStatBoost(Stats::SpecialDefense) == 0);
script->OnSecondaryEffect(executingMove, userMon, 0);
CHECK(userMon->GetStatBoost(Stats::SpecialDefense) == -2);
CLEANUP_MOVE_TEST
}
CHANGE_TARGET_STAT_MOVE(Acid_Spray, SpecialDefense, -2, OnSecondaryEffect);

View File

@ -25,7 +25,7 @@ TEST_CASE("Acrobatics - doesn't overflow", "[moves]") {
TEST_CASE("Acrobatics - doesn't double base power when no held item", "[moves]") {
SETUP_MOVE_TEST(Acrobatics)
userMon->SetHeldItem("poke_ball");
userMon->SetHeldItem("poke_ball"_cnc);
uint8_t basePower = 40;
script->OverrideBasePower(executingMove, userMon, 0, &basePower);
REQUIRE(basePower == 40);

View File

@ -0,0 +1 @@
// TODO: After You tests

View File

@ -0,0 +1,3 @@
#include "../../Macros/MoveMacros.hpp"
CHANGE_USER_STAT_MOVE(Agility, Speed, 2, OnStatusMove);

View File

@ -0,0 +1,3 @@
#include "../../Macros/MoveMacros.hpp"
INCREASED_CRITICAL_RATE(Air_Cutter, 1)