Support Pokemon style experience gain.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-05-20 16:05:52 +02:00
parent a19965c1c3
commit 6c7c460640
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
17 changed files with 116 additions and 30 deletions

View File

@ -4,9 +4,9 @@ using namespace PkmnLib::Battling;
export uint8_t PkmnLib_BattleLibrary_Construct(BattleLibrary*& out, PkmnLib::Library::PokemonLibrary* staticLib, export uint8_t PkmnLib_BattleLibrary_Construct(BattleLibrary*& out, PkmnLib::Library::PokemonLibrary* staticLib,
StatCalculator* statCalculator, DamageLibrary* damageLibrary, StatCalculator* statCalculator, DamageLibrary* damageLibrary,
CreatureLib::Battling::ExperienceLibrary* experienceLibrary, ExperienceLibrary* experienceLibrary,
CreatureLib::Battling::ScriptResolver* scriptResolver, CreatureLib::Battling::ScriptResolver* scriptResolver,
PkmnLib::Battling::MiscLibrary* miscLibrary) { MiscLibrary* miscLibrary) {
Try(out = new BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary, scriptResolver, Try(out = new BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary, scriptResolver,
miscLibrary)); miscLibrary));
} }

View File

@ -0,0 +1,15 @@
#include "../../src/Battling/Library/ExperienceLibrary.hpp"
#include "../Core.hpp"
using namespace PkmnLib::Battling;
export ExperienceLibrary* PkmnLib_ExperienceLibrary_Construct() { return new ExperienceLibrary(); }
export uint8_t PkmnLib_ExperienceLibrary_HandleExperienceGain(ExperienceLibrary* p,
CreatureLib::Battling::Creature* faintedMon,
CreatureLib::Battling::Creature* const* opponents,
size_t numberOfOpponents) {
Try(p->HandleExperienceGain(
faintedMon, std::unordered_set<CreatureLib::Battling::Creature*>(opponents, opponents + numberOfOpponents));)
}
export void PkmnLib_ExperienceLibrary_Destruct(ExperienceLibrary* p) { delete p; }

View File

@ -4,10 +4,12 @@ using namespace PkmnLib::Library;
export uint8_t PkmnLib_PokemonSpecies_Construct(const PokemonSpecies*& out, uint16_t id, const char* name, export uint8_t PkmnLib_PokemonSpecies_Construct(const PokemonSpecies*& out, uint16_t id, const char* name,
const PokemonForme* defaultForme, float genderRatio, const PokemonForme* defaultForme, float genderRatio,
const char* growthRate, uint8_t captureRate, uint8_t baseHappiness) { const char* growthRate, uint8_t captureRate, uint8_t baseHappiness,
uint16_t experienceGain) {
Try(auto cName = Arbutils::CaseInsensitiveConstString(name); Try(auto cName = Arbutils::CaseInsensitiveConstString(name);
auto cGrowthRate = Arbutils::CaseInsensitiveConstString(growthRate); auto cGrowthRate = Arbutils::CaseInsensitiveConstString(growthRate);
out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness);) out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness,
experienceGain);)
} }
export void PkmnLib_PokemonSpecies_Destruct(const PokemonSpecies* p) { delete p; } export void PkmnLib_PokemonSpecies_Destruct(const PokemonSpecies* p) { delete p; }

View File

@ -4,6 +4,7 @@
#include <CreatureLib/Battling/Library/BattleLibrary.hpp> #include <CreatureLib/Battling/Library/BattleLibrary.hpp>
#include "../../Library/PokemonLibrary.hpp" #include "../../Library/PokemonLibrary.hpp"
#include "DamageLibrary.hpp" #include "DamageLibrary.hpp"
#include "ExperienceLibrary.hpp"
#include "MiscLibrary.hpp" #include "MiscLibrary.hpp"
#include "StatCalculator.hpp" #include "StatCalculator.hpp"
@ -11,7 +12,7 @@ namespace PkmnLib::Battling {
class BattleLibrary : public CreatureLib::Battling::BattleLibrary { class BattleLibrary : public CreatureLib::Battling::BattleLibrary {
public: public:
BattleLibrary(Library::PokemonLibrary* staticLib, StatCalculator* statCalculator, DamageLibrary* damageLibrary, BattleLibrary(Library::PokemonLibrary* staticLib, StatCalculator* statCalculator, DamageLibrary* damageLibrary,
CreatureLib::Battling::ExperienceLibrary* experienceLibrary, PkmnLib::Battling::ExperienceLibrary* experienceLibrary,
CreatureLib::Battling::ScriptResolver* scriptResolver, CreatureLib::Battling::ScriptResolver* scriptResolver,
PkmnLib::Battling::MiscLibrary* miscLibrary) PkmnLib::Battling::MiscLibrary* miscLibrary)
: CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary, : CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary,

View File

@ -0,0 +1,23 @@
#include "ExperienceLibrary.hpp"
#include "../PkmnScriptHook.hpp"
#include "../Pokemon/Pokemon.hpp"
void PkmnLib::Battling::ExperienceLibrary::HandleExperienceGain(
CreatureLib::Battling::Creature* faintedMon,
const std::unordered_set<CreatureLib::Battling::Creature*>& opponents) const {
auto fainted = dynamic_cast<Pokemon*>(faintedMon);
auto expGain = fainted->GetPokemonSpecies()->GetExperienceGains();
auto level = fainted->GetLevel();
// TODO exp share
auto v1 = (expGain * level) / 5;
for (auto op : opponents) {
auto v2 = pow(2 * level + 10, 2.5) / pow(level + op->GetLevel() + 10, 2.5);
uint32_t experienceGain = v1 * v2 + 1;
// TODO: Check owner and international
PKMN_HOOK(ModifyExperienceGain, op, faintedMon, op, experienceGain);
op->AddExperience(experienceGain);
}
}

View File

@ -0,0 +1,13 @@
#ifndef PKMNLIB_EXPERIENCELIBRARY_HPP
#define PKMNLIB_EXPERIENCELIBRARY_HPP
#include <CreatureLib/Battling/Library/ExperienceLibrary.hpp>
namespace PkmnLib::Battling {
class ExperienceLibrary : public CreatureLib::Battling::ExperienceLibrary {
public:
void HandleExperienceGain(CreatureLib::Battling::Creature* faintedMon,
const std::unordered_set<CreatureLib::Battling::Creature*>& opponents) const override;
};
}
#endif // PKMNLIB_EXPERIENCELIBRARY_HPP

View File

@ -1,13 +1,14 @@
#ifndef PKMNLIB_PKMNSCRIPT_HPP #ifndef PKMNLIB_PKMNSCRIPT_HPP
#define PKMNLIB_PKMNSCRIPT_HPP #define PKMNLIB_PKMNSCRIPT_HPP
#include <CreatureLib/Battling/ScriptHandling/Script.hpp> #include <CreatureLib/Battling/ScriptHandling/Script.hpp>
#include "Pokemon/Pokemon.hpp"
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
class PkmnScript : public CreatureLib::Battling::Script { class PkmnScript : public CreatureLib::Battling::Script {
public: public:
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){}; CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){};
virtual void ModifyExperienceGain(CreatureLib::Battling::Creature* faintedMon,
CreatureLib::Battling::Creature* winningMon, uint32_t experienceGain){};
}; };
} }

View File

@ -97,7 +97,7 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
} }
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, shiny, heldItem, auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, shiny, heldItem,
_nickname, ability, attacks, ivs, evs, nature); _nickname, ability, attacks, ivs, evs, nature, _allowedExperienceGain);
pkmn->Initialize(); pkmn->Initialize();
return pkmn; return pkmn;
} }
@ -161,3 +161,7 @@ PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConst
_attacks.Append(ToLearnMethod(move, method)); _attacks.Append(ToLearnMethod(move, method));
return *this; return *this;
} }
PkmnLib::Battling::CreatePokemon PkmnLib::Battling::CreatePokemon::IsAllowedExperienceGain(bool value) {
_allowedExperienceGain = value;
return *this;
}

View File

@ -44,6 +44,7 @@ namespace PkmnLib::Battling {
bool _shininessSet = false; bool _shininessSet = false;
bool _isShiny = false; bool _isShiny = false;
bool _allowedExperienceGain = true;
public: public:
CreatePokemon(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level) CreatePokemon(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level)
@ -66,6 +67,7 @@ namespace PkmnLib::Battling {
uint8_t speed); uint8_t speed);
CreatePokemon WithNature(const Arbutils::CaseInsensitiveConstString& nature); CreatePokemon WithNature(const Arbutils::CaseInsensitiveConstString& nature);
CreatePokemon IsAllowedExperienceGain(bool value);
Pokemon* Build(); Pokemon* Build();
}; };

View File

@ -24,9 +24,10 @@ namespace PkmnLib::Battling {
const std::string& nickname, const CreatureLib::Library::TalentIndex& talent, const std::string& nickname, const CreatureLib::Library::TalentIndex& talent,
const List<CreatureLib::Battling::LearnedAttack*>& moves, const List<CreatureLib::Battling::LearnedAttack*>& moves,
CreatureLib::Library::StatisticSet<uint8_t> individualValues, CreatureLib::Library::StatisticSet<uint8_t> individualValues,
CreatureLib::Library::StatisticSet<uint8_t> effortValues, const PkmnLib::Library::Nature* nature) CreatureLib::Library::StatisticSet<uint8_t> effortValues, const PkmnLib::Library::Nature* nature,
bool allowedExperienceGain = true)
: CreatureLib::Battling::Creature(library, species, forme, level, experience, uid, gender, coloring, : CreatureLib::Battling::Creature(library, species, forme, level, experience, uid, gender, coloring,
heldItem, nickname, talent, moves), heldItem, nickname, talent, moves, allowedExperienceGain),
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {} _individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
const Library::PokemonForme* GetForme() const { const Library::PokemonForme* GetForme() const {
@ -46,6 +47,10 @@ namespace PkmnLib::Battling {
inline uint8_t GetEffortValue(CreatureLib::Library::Statistic stat) const { inline uint8_t GetEffortValue(CreatureLib::Library::Statistic stat) const {
return _effortValues.GetStat(stat); return _effortValues.GetStat(stat);
} }
inline const PkmnLib::Library::PokemonSpecies* GetPokemonSpecies() const noexcept {
return dynamic_cast<const Library::PokemonSpecies*>(_species);
}
}; };
} }

View File

@ -9,13 +9,14 @@ namespace PkmnLib::Library {
private: private:
uint8_t _baseHappiness; uint8_t _baseHappiness;
Arbutils::Collections::List<const EvolutionData*> _evolutions; Arbutils::Collections::List<const EvolutionData*> _evolutions;
uint16_t _experienceGain;
public: public:
PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, const PokemonForme* defaultForme, PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, const PokemonForme* defaultForme,
float genderRatio, const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate, float genderRatio, const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate,
uint8_t baseHappiness) noexcept uint8_t baseHappiness, uint16_t experienceGain) noexcept
: CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate), : CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate),
_baseHappiness(baseHappiness) {} _baseHappiness(baseHappiness), _experienceGain(experienceGain) {}
~PokemonSpecies() override { ~PokemonSpecies() override {
for (auto evo : _evolutions) { for (auto evo : _evolutions) {
@ -41,6 +42,8 @@ namespace PkmnLib::Library {
inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); } inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); }
const Arbutils::Collections::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; } const Arbutils::Collections::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; }
inline uint16_t GetExperienceGains() const noexcept { return _experienceGain; }
}; };
} }

View File

@ -18,7 +18,7 @@ private:
ContextPool* _ctxPool = nullptr; ContextPool* _ctxPool = nullptr;
asIScriptObject* _obj = nullptr; asIScriptObject* _obj = nullptr;
CScriptArray* GetEffectParameters(const List<CreatureLib::Library::EffectParameter*>& ls); CScriptArray* GetEffectParameters(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& ls);
public: public:
AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj, AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,

View File

@ -17,7 +17,7 @@ TEST_CASE("Able to build, destroy and insert library", "library") {
"default"_cnc, 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100, 100));
delete lib; delete lib;
} }
@ -30,7 +30,7 @@ TEST_CASE("Able to insert and retrieve from library", "library") {
"default"_cnc, 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100, 100));
auto val = lib->Get("foo"_cnc); auto val = lib->Get("foo"_cnc);
REQUIRE(val->GetName() == "foo"); REQUIRE(val->GetName() == "foo");
delete lib; delete lib;

View File

@ -9,7 +9,7 @@ TEST_CASE("Able to create and destroy species", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
delete species; delete species;
} }
@ -20,7 +20,7 @@ TEST_CASE("Able to get default forme", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
auto forme = species->GetDefaultForme(); auto forme = species->GetDefaultForme();
REQUIRE(forme != nullptr); REQUIRE(forme != nullptr);
@ -35,7 +35,7 @@ TEST_CASE("Able to get default forme name", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
auto forme = species->GetDefaultForme(); auto forme = species->GetDefaultForme();
REQUIRE(forme != nullptr); REQUIRE(forme != nullptr);
@ -51,7 +51,7 @@ TEST_CASE("Able to get species name", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
REQUIRE(species->GetName() == "foo"); REQUIRE(species->GetName() == "foo");
@ -65,7 +65,7 @@ TEST_CASE("Able to get species id", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
REQUIRE(species->GetId() == 1); REQUIRE(species->GetId() == 1);
@ -79,7 +79,7 @@ TEST_CASE("Able to get species gender ratio", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
REQUIRE(species->GetGenderRate() == 0.5f); REQUIRE(species->GetGenderRate() == 0.5f);
@ -93,7 +93,7 @@ TEST_CASE("Able to get species growth rate", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
REQUIRE(species->GetGrowthRate() == "testGrowthRate"); REQUIRE(species->GetGrowthRate() == "testGrowthRate");
@ -107,7 +107,7 @@ TEST_CASE("Able to get species capture rate", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
REQUIRE(species->GetCaptureRate() == 100); REQUIRE(species->GetCaptureRate() == 100);
@ -121,7 +121,7 @@ TEST_CASE("Able to get species base happiness", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
REQUIRE(species->GetBaseHappiness() == 100); REQUIRE(species->GetBaseHappiness() == 100);
@ -135,14 +135,14 @@ TEST_CASE("Able to set and get evolution", "library") {
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
auto species2 = new PkmnLib::Library::PokemonSpecies( auto species2 = new PkmnLib::Library::PokemonSpecies(
2, "bar"_cnc, 2, "bar"_cnc,
new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100),
{"testAbility"_cnc}, {"testHiddenAbility"_cnc}, {"testAbility"_cnc}, {"testHiddenAbility"_cnc},
new CreatureLib::Library::LearnableAttacks(100)), new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100); 0.5f, "testGrowthRate"_cnc, 100, 100, 100);
species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2)); species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2));
auto evolutions = species->GetEvolutions(); auto evolutions = species->GetEvolutions();

View File

@ -0,0 +1,17 @@
#ifdef TESTS_BUILD
#include "../../extern/catch.hpp"
#include "../../src/Battling/Library/ExperienceLibrary.hpp"
#include "../../src/Battling/Pokemon/CreatePokemon.hpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace PkmnLib::Battling;
TEST_CASE("Basic Experience gain test", "battling") {
auto lib = TestLibrary::GetLibrary();
auto mon1 = CreatePokemon(lib, "testSpecies"_cnc, 55).Build();
auto initialExp = mon1->GetExperience();
auto mon2 = CreatePokemon(lib, "testSpecies2"_cnc, 62).Build();
auto expLib = lib->GetExperienceLibrary();
expLib->HandleExperienceGain(mon2, {mon1});
REQUIRE(mon1->GetExperience() - initialExp == 4339);
}
#endif

View File

@ -11,7 +11,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
"default"_cnc, 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100, 236));
lib->Insert("testSpecies2"_cnc, lib->Insert("testSpecies2"_cnc,
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
2, "testSpecies2"_cnc, 2, "testSpecies2"_cnc,
@ -19,7 +19,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
"default"_cnc, 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100, 306));
lib->Insert("statTestSpecies1"_cnc, lib->Insert("statTestSpecies1"_cnc,
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
3, "statTestSpecies1"_cnc, 3, "statTestSpecies1"_cnc,
@ -27,7 +27,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
"default"_cnc, 1.0f, 1.0f, 100, {0}, "default"_cnc, 1.0f, 1.0f, 100, {0},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100, 236));
lib->Insert("testSpecies3"_cnc, lib->Insert("testSpecies3"_cnc,
new PkmnLib::Library::PokemonSpecies( new PkmnLib::Library::PokemonSpecies(
2, "testSpecies3"_cnc, 2, "testSpecies3"_cnc,
@ -35,7 +35,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
"default"_cnc, 1.0f, 1.0f, 100, {0, 4}, "default"_cnc, 1.0f, 1.0f, 100, {0, 4},
CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, CreatureLib::Library::StatisticSet<uint16_t>(100, 100, 100, 100, 100, 100), {"testAbility"_cnc},
{"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)),
0.5f, "testGrowthRate"_cnc, 100, 100)); 0.5f, "testGrowthRate"_cnc, 100, 100, 236));
return lib; return lib;
} }

View File

@ -25,7 +25,7 @@ public:
auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver(); auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
auto lib = new PkmnLib::Battling::BattleLibrary( auto lib = new PkmnLib::Battling::BattleLibrary(
BuildStaticLibrary(), statCalc, new PkmnLib::Battling::DamageLibrary(), BuildStaticLibrary(), statCalc, new PkmnLib::Battling::DamageLibrary(),
new CreatureLib::Battling::ExperienceLibrary(), scriptResolver, new PkmnLib::Battling::MiscLibrary()); new PkmnLib::Battling::ExperienceLibrary(), scriptResolver, new PkmnLib::Battling::MiscLibrary());
scriptResolver->Initialize(lib); scriptResolver->Initialize(lib);
return lib; return lib;
} }