PkmnLib/src/Battling/Pokemon/Pokemon.hpp

91 lines
4.3 KiB
C++
Raw Normal View History

#ifndef PKMNLIB_POKEMON_HPP
#define PKMNLIB_POKEMON_HPP
#include <CreatureLib/Battling/Models/Creature.hpp>
2020-01-05 14:18:30 +00:00
#include "../../Library/Statistic.hpp"
#include "../Library/BattleLibrary.hpp"
2021-03-07 10:12:18 +00:00
#include "../PkmnScript.hpp"
#include "LearnedMove.hpp"
namespace PkmnLib::Battling {
class Pokemon : public CreatureLib::Battling::Creature {
private:
CreatureLib::Library::ClampedStatisticSet<u8, 0, 31> _individualValues;
CreatureLib::Library::ClampedStatisticSet<u8, 0, 252> _effortValues;
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> _nature;
u8 _friendship = 0;
bool _isEgg;
2020-01-02 19:26:01 +00:00
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, u32 experience,
u32 uid, CreatureLib::Library::Gender gender, u8 coloring,
ArbUt::OptionalBorrowedPtr<const Library::Item> heldItem, const std::optional<std::string>& nickname,
2020-05-27 15:26:25 +00:00
const CreatureLib::Library::TalentIndex& talent,
const std::vector<CreatureLib::Battling::LearnedAttack*>& moves,
CreatureLib::Library::ClampedStatisticSet<u8, 0, 31> individualValues,
CreatureLib::Library::ClampedStatisticSet<u8, 0, 252> effortValues,
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> nature, bool allowedExperienceGain = true,
bool isEgg = false)
2021-03-07 10:12:18 +00:00
: 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),
2020-08-08 15:52:57 +00:00
_individualValues(individualValues), _effortValues(effortValues), _nature(nature),
_friendship(species->GetBaseHappiness()), _isEgg(isEgg) {}
2020-01-02 19:26:01 +00:00
2020-05-27 15:26:25 +00:00
const ArbUt::BorrowedPtr<const Library::PokemonForme> GetForme() const {
2020-08-17 16:23:25 +00:00
return _variant.ForceAs<const Library::PokemonForme>();
2020-01-05 14:18:30 +00:00
}
2020-04-18 11:43:05 +00:00
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 u8 GetIndividualValue(CreatureLib::Library::Statistic stat) const {
return _individualValues.GetStat(stat);
}
inline void SetIndividualValue(CreatureLib::Library::Statistic stat, u8 value) {
2020-08-08 15:52:57 +00:00
return _individualValues.SetStat(stat, value);
}
inline u8 GetEffortValue(CreatureLib::Library::Statistic stat) const { return _effortValues.GetStat(stat); }
inline void SetEffortValue(CreatureLib::Library::Statistic stat, u8 value) {
2020-08-08 15:52:57 +00:00
return _effortValues.SetStat(stat, value);
}
inline bool IsEgg() const noexcept { return _isEgg; }
2021-06-27 10:21:02 +00:00
inline void SetIsEgg(bool value) noexcept { _isEgg = value; }
2020-05-20 14:05:52 +00:00
2020-05-27 15:26:25 +00:00
inline ArbUt::BorrowedPtr<const PkmnLib::Library::PokemonSpecies> GetPokemonSpecies() const noexcept {
return _species.As<const PkmnLib::Library::PokemonSpecies>();
2020-05-20 14:05:52 +00:00
}
2020-06-10 10:33:51 +00:00
void Evolve(ArbUt::BorrowedPtr<const Library::PokemonSpecies> mon,
ArbUt::BorrowedPtr<const Library::PokemonForme> forme);
2020-08-08 10:01:05 +00:00
u8 GetFriendship() const noexcept { return _friendship; }
void SetFriendship(u8 value) noexcept { _friendship = value; }
void ChangeFriendship(i8 amount) noexcept {
u8 newValue;
2020-08-08 15:52:57 +00:00
if (__builtin_add_overflow(_friendship, amount, &newValue)) {
if (amount < 0)
newValue = 0;
else
newValue = 255;
}
_friendship = newValue;
}
bool IsUsable() const noexcept override;
Creature* non_null Clone() const override;
};
}
#endif // PKMNLIB_POKEMON_HPP