PkmnLib/src/Battling/Pokemon/Pokemon.hpp

93 lines
4.4 KiB
C++

#ifndef PKMNLIB_POKEMON_HPP
#define PKMNLIB_POKEMON_HPP
#include <CreatureLib/Battling/Models/Creature.hpp>
#include "../../Library/Statistic.hpp"
#include "../Library/BattleLibrary.hpp"
#include "../PkmnScript.hpp"
#include "LearnedMove.hpp"
namespace PkmnLib::Battling {
class Pokemon : public CreatureLib::Battling::Creature {
private:
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31> _individualValues;
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252> _effortValues;
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> _nature;
uint8_t _friendship = 0;
bool _isEgg;
public:
Pokemon(ArbUt::BorrowedPtr<const BattleLibrary> library,
const ArbUt::BorrowedPtr<const Library::PokemonSpecies>& species,
const ArbUt::BorrowedPtr<const Library::PokemonForme>& forme, level_int_t level, uint32_t experience,
uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, const std::optional<std::string>& nickname,
const CreatureLib::Library::TalentIndex& talent,
const std::vector<CreatureLib::Battling::LearnedAttack*>& moves,
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 31> individualValues,
CreatureLib::Library::ClampedStatisticSet<uint8_t, 0, 252> effortValues,
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> nature, bool allowedExperienceGain = true,
bool isEgg = false)
: CreatureLib::Battling::Creature(
library.ForceAs<const CreatureLib::Battling::BattleLibrary>(),
species.ForceAs<const CreatureLib::Library::CreatureSpecies>(),
forme.ForceAs<const CreatureLib::Library::SpeciesVariant>(), level, experience, uid, gender, coloring,
heldItem.ForceAs<const CreatureLib::Library::Item>(), nickname, talent, moves, allowedExperienceGain),
_individualValues(individualValues), _effortValues(effortValues), _nature(nature),
_friendship(species->GetBaseHappiness()), _isEgg(isEgg) {}
const ArbUt::BorrowedPtr<const Library::PokemonForme> GetForme() const {
return _variant.ForceAs<const Library::PokemonForme>();
}
inline bool IsShiny() const noexcept { return _coloring == 1; }
const ArbUt::List<ArbUt::OptionalBorrowedPtr<LearnedMove>>& GetMoves() const {
return reinterpret_cast<const ArbUt::List<ArbUt::OptionalBorrowedPtr<LearnedMove>>&>(_attacks);
}
inline const ArbUt::BorrowedPtr<const PkmnLib::Library::Nature>& GetNature() const noexcept { return _nature; }
inline uint8_t GetIndividualValue(CreatureLib::Library::Statistic stat) const {
return _individualValues.GetStat(stat);
}
inline void SetIndividualValue(CreatureLib::Library::Statistic stat, uint8_t value) {
return _individualValues.SetStat(stat, value);
}
inline uint8_t GetEffortValue(CreatureLib::Library::Statistic stat) const {
return _effortValues.GetStat(stat);
}
inline void SetEffortValue(CreatureLib::Library::Statistic stat, uint8_t value) {
return _effortValues.SetStat(stat, value);
}
inline bool IsEgg() const noexcept { return _isEgg; }
inline void SetIsEgg(bool value) noexcept { _isEgg = value; }
inline ArbUt::BorrowedPtr<const PkmnLib::Library::PokemonSpecies> GetPokemonSpecies() const noexcept {
return _species.As<const PkmnLib::Library::PokemonSpecies>();
}
void Evolve(ArbUt::BorrowedPtr<const Library::PokemonSpecies> mon,
ArbUt::BorrowedPtr<const Library::PokemonForme> forme);
uint8_t GetFriendship() const noexcept { return _friendship; }
void SetFriendship(uint8_t value) noexcept { _friendship = value; }
void ChangeFriendship(int8_t amount) noexcept {
uint8_t newValue;
if (__builtin_add_overflow(_friendship, amount, &newValue)) {
if (amount < 0)
newValue = 0;
else
newValue = 255;
}
_friendship = newValue;
}
bool IsUsable() const noexcept override;
Creature* Clone() const override;
};
}
#endif // PKMNLIB_POKEMON_HPP