Support Pokemon style experience gain.
Some checks failed
continuous-integration/drone/push Build is failing

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

View File

@@ -4,6 +4,7 @@
#include <CreatureLib/Battling/Library/BattleLibrary.hpp>
#include "../../Library/PokemonLibrary.hpp"
#include "DamageLibrary.hpp"
#include "ExperienceLibrary.hpp"
#include "MiscLibrary.hpp"
#include "StatCalculator.hpp"
@@ -11,7 +12,7 @@ namespace PkmnLib::Battling {
class BattleLibrary : public CreatureLib::Battling::BattleLibrary {
public:
BattleLibrary(Library::PokemonLibrary* staticLib, StatCalculator* statCalculator, DamageLibrary* damageLibrary,
CreatureLib::Battling::ExperienceLibrary* experienceLibrary,
PkmnLib::Battling::ExperienceLibrary* experienceLibrary,
CreatureLib::Battling::ScriptResolver* scriptResolver,
PkmnLib::Battling::MiscLibrary* miscLibrary)
: 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
#define PKMNLIB_PKMNSCRIPT_HPP
#include <CreatureLib/Battling/ScriptHandling/Script.hpp>
#include "Pokemon/Pokemon.hpp"
namespace PkmnLib::Battling {
class PkmnScript : public CreatureLib::Battling::Script {
public:
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
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,
_nickname, ability, attacks, ivs, evs, nature);
_nickname, ability, attacks, ivs, evs, nature, _allowedExperienceGain);
pkmn->Initialize();
return pkmn;
}
@@ -161,3 +161,7 @@ PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConst
_attacks.Append(ToLearnMethod(move, method));
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 _isShiny = false;
bool _allowedExperienceGain = true;
public:
CreatePokemon(const BattleLibrary* library, const Arbutils::CaseInsensitiveConstString& species, uint8_t level)
@@ -66,6 +67,7 @@ namespace PkmnLib::Battling {
uint8_t speed);
CreatePokemon WithNature(const Arbutils::CaseInsensitiveConstString& nature);
CreatePokemon IsAllowedExperienceGain(bool value);
Pokemon* Build();
};

View File

@@ -24,9 +24,10 @@ namespace PkmnLib::Battling {
const std::string& nickname, const CreatureLib::Library::TalentIndex& talent,
const List<CreatureLib::Battling::LearnedAttack*>& moves,
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,
heldItem, nickname, talent, moves),
heldItem, nickname, talent, moves, allowedExperienceGain),
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
const Library::PokemonForme* GetForme() const {
@@ -46,6 +47,10 @@ namespace PkmnLib::Battling {
inline uint8_t GetEffortValue(CreatureLib::Library::Statistic stat) const {
return _effortValues.GetStat(stat);
}
inline const PkmnLib::Library::PokemonSpecies* GetPokemonSpecies() const noexcept {
return dynamic_cast<const Library::PokemonSpecies*>(_species);
}
};
}