From 9e587b3d0b60fe731086f7301943ca3c03db2b07 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 10 Jun 2020 12:33:51 +0200 Subject: [PATCH] Support for evolving a mon. --- src/Battling/Pokemon/Pokemon.cpp | 37 ++++++++++++++++++++++++++++++++ src/Battling/Pokemon/Pokemon.hpp | 3 +++ 2 files changed, 40 insertions(+) diff --git a/src/Battling/Pokemon/Pokemon.cpp b/src/Battling/Pokemon/Pokemon.cpp index 71f641f..16e01fd 100644 --- a/src/Battling/Pokemon/Pokemon.cpp +++ b/src/Battling/Pokemon/Pokemon.cpp @@ -1 +1,38 @@ #include "Pokemon.hpp" +#include + +void PkmnLib::Battling::Pokemon::Evolve(ArbUt::BorrowedPtr mon, + ArbUt::BorrowedPtr forme) { + _species = mon.ForceAs(); + _variant = forme.ForceAs(); + + ArbUt::Random* rand; + if (!_battle.IsNull()) { + rand = &_battle->GetRandom()->GetRNG(); + } else { + rand = new ArbUt::Random(); + } + + if (_gender != CreatureLib::Library::Gender::Genderless && _species->GetGenderRate() != -1) { + _gender = _species->GetRandomGender(*rand); + } else if (_species->GetGenderRate() == -1 && _gender != CreatureLib::Library::Gender::Genderless) { + _gender = CreatureLib::Library::Gender::Genderless; + } + + _types.clear(); + for (auto t : forme->GetTypes()) { + _types.insert(t); + } + + _activeTalent = + std::unique_ptr(_library->LoadScript(ScriptCategory::Talent, GetActiveTalent())); + + auto currentMaxHealth = GetBoostedStat(PkmnLib::Library::Statistic::HealthPoints); + RecalculateFlatStats(); + auto diffHealth = GetBoostedStat(PkmnLib::Library::Statistic::HealthPoints) - currentMaxHealth; + _currentHealth += diffHealth; + if (_currentHealth < 0) + _currentHealth = 0; + + // TODO: Learn moves? +} diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index a6d60c3..18d8933 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -56,6 +56,9 @@ namespace PkmnLib::Battling { inline ArbUt::BorrowedPtr GetPokemonSpecies() const noexcept { return _species.As(); } + + void Evolve(ArbUt::BorrowedPtr mon, + ArbUt::BorrowedPtr forme); }; }