Add Pokemon Status.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-08-08 12:01:05 +02:00
parent d8e166e49a
commit 683f3ad08b
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
8 changed files with 67 additions and 11 deletions

View File

@ -25,11 +25,13 @@ export void PkmnLib_Pokemon_Destruct(const Pokemon* p) { delete p; }
SIMPLE_GET_FUNC(Pokemon, IsShiny, bool)
SIMPLE_GET_FUNC_SMART_PTR(Pokemon, GetNature, const PkmnLib::Library::Nature*)
#undef SIMPLE_GET_FUNC
export uint8_t PkmnLib_Pokemon_GetIndividualValue(const Pokemon* p, CreatureLib::Library::Statistic stat) {
return p->GetIndividualValue(stat);
}
export uint8_t PkmnLib_Pokemon_GetEffortValue(const Pokemon* p, CreatureLib::Library::Statistic stat) {
return p->GetEffortValue(stat);
}
export uint8_t PkmnLib_Battle_SetStatus(Pokemon* p, const char* name) { Try(p->SetStatus(ArbUt::StringView(name))); };
export uint8_t PkmnLib_Battle_ClearStatus(Pokemon* p) { Try(p->ClearStatus()); };
export const char* PkmnLib_Battle_GetStatusName(Pokemon* p) { return p->GetStatusName().c_str(); }

View File

@ -3,6 +3,6 @@
#include <Arbutils/Enum.hpp>
#include <CreatureLib/Battling/EventHooks/EventDataKind.hpp>
ENUM_WITH_START_VALUE(PkmnEventDataKind, uint8_t, 128, WeatherChange)
ENUM_WITH_START_VALUE(PkmnEventDataKind, uint8_t, 128, WeatherChange, StatusChange)
#endif // PKMNLIB_PKMNEVENTKIND_HPP

View File

@ -0,0 +1,27 @@
#ifndef PKMNLIB_STATUSCHANGEEVENT_HPP
#define PKMNLIB_STATUSCHANGEEVENT_HPP
#include <Arbutils/String/StringView.hpp>
#include <CreatureLib/Battling/EventHooks/EventData.hpp>
#include "../Pokemon/Pokemon.hpp"
#include "PkmnEventKind.hpp"
namespace PkmnLib::Battling {
class StatusChangeEvent : public CreatureLib::Battling::EventData {
ArbUt::BorrowedPtr<Pokemon> _pokemon;
ArbUt::StringView _statusName;
public:
explicit StatusChangeEvent(const ArbUt::BorrowedPtr<Pokemon>& pkmn, const ArbUt::StringView& name)
: _pokemon(pkmn), _statusName(name) {}
[[nodiscard]] CreatureLib::Battling::EventDataKind GetKind() const noexcept override {
return static_cast<CreatureLib::Battling::EventDataKind>(PkmnEventDataKind::StatusChange);
}
const ArbUt::BorrowedPtr<Pokemon>& GetPokemon() const noexcept { return _pokemon; }
const ArbUt::StringView& GetStatusName() const noexcept { return _statusName; }
};
}
#endif // PKMNLIB_STATUSCHANGEEVENT_HPP

View File

@ -3,6 +3,6 @@
#include <Arbutils/Enum.hpp>
#include <CreatureLib/Battling/ScriptHandling/ScriptCategory.hpp>
ENUM_WITH_START_VALUE(PkmnScriptCategory, uint8_t, ((uint8_t)ScriptCategoryHelper::Highest()) + 1, Weather)
ENUM_WITH_START_VALUE(PkmnScriptCategory, uint8_t, 128, Weather, Status)
#endif // PKMNLIB_PKMNSCRIPTCATEGORY_HPP

View File

@ -50,7 +50,7 @@ namespace PkmnLib::Battling {
}
AssertNotNull(forme);
CreatureLib::Library::TalentIndex ability;
if (this->_ability.Empty()) {
if (this->_ability.IsEmpty()) {
ability = forme->GetRandomTalent(rand);
} else {
ability = forme->GetTalentIndex(this->_ability);
@ -64,7 +64,7 @@ namespace PkmnLib::Battling {
gender = species->GetRandomGender(rand);
}
ArbUt::BorrowedPtr<const Library::Item> heldItem = nullptr;
if (!this->_heldItem.Empty()) {
if (!this->_heldItem.IsEmpty()) {
if (!_library->GetItemLibrary()->TryGet(this->_heldItem, heldItem)) {
THROW_CREATURE("Unknown Item: " << this->_heldItem.std_str());
}
@ -84,7 +84,7 @@ namespace PkmnLib::Battling {
auto ivs = CreatureLib::Library::StatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, _ivSpDef, _ivSpeed);
auto evs = CreatureLib::Library::StatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, _evSpDef, _evSpeed);
if (_nature.Empty()) {
if (_nature.IsEmpty()) {
_nature = _library->GetNatureLibrary()->GetRandomNatureName(rand);
}
auto nature = _library->GetNatureLibrary()->GetNatureByName(_nature);

View File

@ -1,5 +1,7 @@
#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) {
@ -25,3 +27,21 @@ void PkmnLib::Battling::Pokemon::Evolve(ArbUt::BorrowedPtr<const Library::Pokemo
// 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::Script>(
_library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Status), name));
if (_battle != nullptr) {
_battle->TriggerEventListener<StatusChangeEvent>(this, name);
}
}
void PkmnLib::Battling::Pokemon::ClearStatus() {
_statusScript->OnRemove();
_statusScript = nullptr;
if (_battle != nullptr) {
_battle->TriggerEventListener<StatusChangeEvent>(this, ""_cnc);
}
}

View File

@ -14,8 +14,7 @@ namespace PkmnLib::Battling {
CreatureLib::Library::StatisticSet<uint8_t> _effortValues;
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> _nature;
ArbUt::BorrowedPtr<const BattleLibrary> GetLibrary() const { return _library.ForceAs<const BattleLibrary>(); }
std::unique_ptr<CreatureLib::Battling::Script> _statusScript = nullptr;
public:
Pokemon(ArbUt::BorrowedPtr<const BattleLibrary> library,
@ -59,6 +58,14 @@ namespace PkmnLib::Battling {
void Evolve(ArbUt::BorrowedPtr<const Library::PokemonSpecies> mon,
ArbUt::BorrowedPtr<const Library::PokemonForme> forme);
void SetStatus(const ArbUt::StringView& name);
void ClearStatus();
const ArbUt::StringView& GetStatusName() noexcept {
if (_statusScript == nullptr)
return ArbUt::StringView::Empty();
return _statusScript->GetName();
}
};
}

View File

@ -173,7 +173,7 @@ void AngelScriptResolver::FinalizeModule() {
effectName = ArbUt::StringView(val.c_str(), val.length());
}
}
if (effectName.Empty()) {
if (effectName.IsEmpty()) {
continue;
}
switch (metadataKind) {