PkmnLib/src/Battling/Pokemon/Pokemon.cpp

49 lines
2.1 KiB
C++

#include "Pokemon.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp>
#include "../EventHooks/StatusChangeEvent.hpp"
#include "../PkmnScriptCategory.hpp"
void PkmnLib::Battling::Pokemon::Evolve(ArbUt::BorrowedPtr<const Library::PokemonSpecies> mon,
ArbUt::BorrowedPtr<const Library::PokemonForme> forme) {
// Set species and variant
_species = mon.ForceAs<const CreatureLib::Library::CreatureSpecies>();
ChangeVariant(forme.ForceAs<const CreatureLib::Library::SpeciesVariant>());
// If the pokemon is genderless, but it's new evolution is not, we want to set its gender
if (_gender != CreatureLib::Library::Gender::Genderless && _species->GetGenderRate() != -1) {
// If we are currently in battle, use the battle random so we can get predictable events.
if (_battle.HasValue()) {
_gender = _species->GetRandomGender(_battle.GetValue()->GetRandom()->GetRNG());
}
// Else create a new random.
else {
ArbUt::Random rand;
_gender = _species->GetRandomGender(rand);
}
// Else if the new pokemon species is genderless, but the pokemon has a gender, make the Pokemon genderless.
} else if (_species->GetGenderRate() == -1 && _gender != CreatureLib::Library::Gender::Genderless) {
_gender = CreatureLib::Library::Gender::Genderless;
}
// TODO: Learn moves?
// TODO: Event hook
}
void PkmnLib::Battling::Pokemon::SetStatus(const ArbUt::StringView& name) {
if (_statusScript != nullptr) {
_statusScript->OnRemove();
}
_statusScript = std::unique_ptr<CreatureLib::Battling::BattleScript>(
_library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Status), name));
if (_battle.HasValue()) {
_battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, name);
}
}
void PkmnLib::Battling::Pokemon::ClearStatus() {
if (_statusScript == nullptr)
return;
_statusScript->OnRemove();
_statusScript = nullptr;
if (_battle.HasValue()) {
_battle.GetValue()->TriggerEventListener<StatusChangeEvent>(this, ""_cnc);
}
}