Many tweaks and fixes relating to AngelScript, implements shininess.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -26,7 +26,9 @@ public:
|
||||
return find->second;
|
||||
}
|
||||
auto func = _type->GetMethodByName(functionName.c_str());
|
||||
func->AddRef();
|
||||
if (func != nullptr){
|
||||
func->AddRef();
|
||||
}
|
||||
_functions.insert({functionName, func});
|
||||
return func;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "RegisterPokemonClass.hpp"
|
||||
#include <Battling/Models/LearnedAttack.hpp>
|
||||
#include <cassert>
|
||||
#include "../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||
#include "../../../Battling/Pokemon/Pokemon.hpp"
|
||||
|
||||
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
||||
@@ -52,8 +53,23 @@ void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) {
|
||||
|
||||
ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender)
|
||||
|
||||
CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) {
|
||||
asIScriptContext* ctx = asGetActiveContext();
|
||||
if (ctx) {
|
||||
asIScriptEngine* engine = ctx->GetEngine();
|
||||
asITypeInfo* t = engine->GetTypeInfoByDecl("array<uint8>");
|
||||
auto a = obj->GetTypes();
|
||||
CScriptArray* arr = CScriptArray::Create(t, a.size());
|
||||
for (size_t i = 0; i < a.size(); i++){
|
||||
arr->SetValue(i, &a[i]);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]]int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetSpecies), asCALL_THISCALL);
|
||||
@@ -73,6 +89,9 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "bool get_Shiny() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
@@ -89,7 +108,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "uint8[]@ GetTypes() const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetTypes), asCALL_THISCALL);
|
||||
asFUNCTION(GetTypes), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL);
|
||||
|
||||
@@ -20,7 +20,7 @@ void RegisterStaticLibraryTypes::RegisterLibrarySettingsType(asIScriptEngine* en
|
||||
void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings& get_Settings() const property",
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings@ get_Settings() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetSettings), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
|
||||
|
||||
@@ -17,6 +17,10 @@ namespace PkmnLib::Battling {
|
||||
: CreatureLib::Battling::BattleLibrary(staticLib, statCalculator, damageLibrary, experienceLibrary,
|
||||
scriptResolver, miscLibrary) {}
|
||||
|
||||
const Library::LibrarySettings* GetSettings() const{
|
||||
return static_cast<const Library::LibrarySettings*>(_staticLib->GetSettings());
|
||||
}
|
||||
|
||||
const Library::PokemonLibrary* GetStaticLib() const{
|
||||
return dynamic_cast<const Library::PokemonLibrary*>(CreatureLib::Battling::BattleLibrary::_staticLib);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "CreatePokemon.hpp"
|
||||
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) {
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) {
|
||||
_ivHp = rand.Get(0, 32);
|
||||
_ivAttack = rand.Get(0, 32);
|
||||
_ivDefense = rand.Get(0, 32);
|
||||
@@ -10,7 +11,8 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIn
|
||||
return this;
|
||||
}
|
||||
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value) {
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value) {
|
||||
switch (stat) {
|
||||
case PkmnLib::Library::Statistic::HealthPoints: _ivHp = value; break;
|
||||
case PkmnLib::Library::Statistic::PhysicalAttack: _ivAttack = value; break;
|
||||
@@ -22,7 +24,8 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividu
|
||||
return this;
|
||||
}
|
||||
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortValue(CreatureLib::Core::Statistic stat, uint8_t value) {
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortValue(CreatureLib::Core::Statistic stat,
|
||||
uint8_t value) {
|
||||
switch (stat) {
|
||||
case PkmnLib::Library::Statistic::HealthPoints: _evHp = value; break;
|
||||
case PkmnLib::Library::Statistic::PhysicalAttack: _evAttack = value; break;
|
||||
@@ -36,8 +39,11 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||
|
||||
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
auto rand = CreatureLib::Core::Random();
|
||||
auto species = this->_library->GetSpeciesLibrary()->GetPkmnSpecies(this->_species);
|
||||
auto forme = species->GetForme(this->_variant);
|
||||
const PkmnLib::Library::PokemonSpecies* species = nullptr;
|
||||
if (!this->_library->GetSpeciesLibrary()->TryGetPkmnSpecies(this->_species, species)){
|
||||
throw CreatureException("Invalid species: " + _species);
|
||||
}
|
||||
auto forme = species->GetForme(this->_forme);
|
||||
int8_t ability;
|
||||
if (this->_ability.empty()) {
|
||||
ability = forme->GetRandomTalent(&rand);
|
||||
@@ -54,7 +60,9 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
}
|
||||
const Library::Item* heldItem = nullptr;
|
||||
if (!this->_heldItem.empty()) {
|
||||
heldItem = _library->GetItemLibrary()->GetItem(this->_heldItem);
|
||||
if (!_library->GetItemLibrary()->TryGetItem(this->_heldItem, heldItem)){
|
||||
throw CreatureException("Unknown Item: " + this->_heldItem);
|
||||
}
|
||||
}
|
||||
auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level);
|
||||
|
||||
@@ -66,12 +74,20 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
auto ivs = CreatureLib::Core::StatisticSet(_ivHp, _ivAttack, _ivDefense, _ivSpAtt, _ivSpDef, _ivSpeed);
|
||||
auto evs = CreatureLib::Core::StatisticSet(_evHp, _evAttack, _evDefense, _evSpAtt, _evSpDef, _evSpeed);
|
||||
|
||||
if (_nature == 255){
|
||||
if (_nature == 255) {
|
||||
_nature = _library->GetNatureLibrary()->GetRandomNature(rand);
|
||||
}
|
||||
|
||||
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, _coloring, heldItem, _nickname,
|
||||
ability, attacks, ivs, evs,_nature);
|
||||
auto shiny = false;
|
||||
if (_shininessSet){
|
||||
shiny = _isShiny;
|
||||
}
|
||||
else{
|
||||
shiny = rand.Get(_library->GetSettings()->GetShinyRate()) == 0;
|
||||
}
|
||||
|
||||
auto pkmn = new Pokemon(_library, species, forme, _level, experience, identifier, gender, shiny, heldItem,
|
||||
_nickname, ability, attacks, ivs, evs, _nature);
|
||||
pkmn->Initialize();
|
||||
return pkmn;
|
||||
}
|
||||
@@ -85,7 +101,7 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithIndividu
|
||||
_ivHp = hp;
|
||||
_ivAttack = att;
|
||||
_ivDefense = def;
|
||||
_ivSpAtt = spAtt;
|
||||
_ivSpAtt = spAtt;
|
||||
_ivSpDef = spDef;
|
||||
_ivSpeed = speed;
|
||||
return this;
|
||||
@@ -96,8 +112,25 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||
_evHp = hp;
|
||||
_evAttack = att;
|
||||
_evDefense = def;
|
||||
_evSpAtt = spAtt;
|
||||
_evSpAtt = spAtt;
|
||||
_evSpDef = spDef;
|
||||
_evSpeed = speed;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithForme(const std::string& forme) {
|
||||
_forme = forme;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithGender(CreatureLib::Library::Gender gender) {
|
||||
_gender = gender;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::IsShiny(bool value) {
|
||||
_shininessSet = true;
|
||||
_isShiny = value;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem(const std::string& item) {
|
||||
_heldItem = item;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -8,14 +8,13 @@ namespace PkmnLib::Battling {
|
||||
private:
|
||||
const BattleLibrary* _library;
|
||||
std::string _species;
|
||||
std::string _variant = "default";
|
||||
std::string _forme = "default";
|
||||
uint8_t _level;
|
||||
std::string _nickname = "";
|
||||
|
||||
std::string _ability = "";
|
||||
uint8_t _nature = 255;
|
||||
CreatureLib::Library::Gender _gender = static_cast<CreatureLib::Library::Gender>(-1);
|
||||
uint8_t _coloring = 0;
|
||||
std::string _heldItem = "";
|
||||
uint32_t _identifier = 0;
|
||||
std::vector<std::tuple<const Library::MoveData*, CreatureLib::Battling::AttackLearnMethod>> _attacks = {};
|
||||
@@ -34,10 +33,18 @@ namespace PkmnLib::Battling {
|
||||
uint8_t _evSpDef = 0;
|
||||
uint8_t _evSpeed = 0;
|
||||
|
||||
bool _shininessSet = false;
|
||||
bool _isShiny = false;
|
||||
|
||||
public:
|
||||
CreatePokemon(const BattleLibrary* library, std::string species, uint8_t level)
|
||||
: _library(library), _species(std::move(species)), _level(level) {}
|
||||
|
||||
CreatePokemon* WithForme(const std::string& forme);
|
||||
CreatePokemon* WithGender(CreatureLib::Library::Gender gender);
|
||||
CreatePokemon* IsShiny(bool value);
|
||||
CreatePokemon* WithHeldItem(const std::string& item);
|
||||
|
||||
CreatePokemon* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random());
|
||||
CreatePokemon* WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value);
|
||||
CreatePokemon* WithIndividualValues(uint8_t hp, uint8_t att, uint8_t def, uint8_t spAtt, uint8_t spDef,
|
||||
|
||||
@@ -33,6 +33,10 @@ namespace PkmnLib::Battling {
|
||||
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
|
||||
}
|
||||
|
||||
const bool IsShiny() const{
|
||||
return _coloring == 1;
|
||||
}
|
||||
|
||||
const Library::Nature& GetNature() const;
|
||||
uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const { return _individualValues.GetStat(stat); }
|
||||
uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); }
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
namespace PkmnLib::Library {
|
||||
class ItemLibrary : public CreatureLib::Library::ItemLibrary {
|
||||
public:
|
||||
inline bool TryGetItem(const std::string& name, const Item*& item) const {
|
||||
return CreatureLib::Library::ItemLibrary::TryGetItem(name, (const CreatureLib::Library::Item*&)item);
|
||||
}
|
||||
const Item* GetItem(const std::string& name) const {
|
||||
return reinterpret_cast<const Item*>(CreatureLib::Library::ItemLibrary::GetItem(name));
|
||||
}
|
||||
|
||||
18
src/Library/LibrarySettings.hpp
Normal file
18
src/Library/LibrarySettings.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef PKMNLIB_LIBRARYSETTINGS_HPP
|
||||
#define PKMNLIB_LIBRARYSETTINGS_HPP
|
||||
|
||||
#include <Library/LibrarySettings.hpp>
|
||||
|
||||
namespace PkmnLib::Library {
|
||||
class LibrarySettings : public CreatureLib::Library::LibrarySettings {
|
||||
uint16_t _shinyRate;
|
||||
|
||||
public:
|
||||
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves, uint16_t shinyRate)
|
||||
: CreatureLib::Library::LibrarySettings(maximalLevel, maximalMoves), _shinyRate(shinyRate) {}
|
||||
|
||||
uint16_t GetShinyRate() const { return _shinyRate; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PKMNLIB_LIBRARYSETTINGS_HPP
|
||||
@@ -10,6 +10,9 @@ namespace PkmnLib::Library {
|
||||
|
||||
virtual const MoveData* operator[](const std::string& name) const { return GetAttack(name); }
|
||||
|
||||
inline bool TryGetMove(const std::string& name, const MoveData*& move) const{
|
||||
return TryGetAttack(name, (const CreatureLib::Library::AttackData*&)move);
|
||||
}
|
||||
const MoveData* GetMove(const std::string& name) const { return GetAttack(name); }
|
||||
|
||||
const MoveData* GetAttack(const std::string& name) const {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <Library/DataLibrary.hpp>
|
||||
#include "Items/ItemLibrary.hpp"
|
||||
#include "LibrarySettings.hpp"
|
||||
#include "Moves/MoveLibrary.hpp"
|
||||
#include "Natures/NatureLibrary.hpp"
|
||||
#include "Species/SpeciesLibrary.hpp"
|
||||
@@ -17,11 +18,15 @@ namespace PkmnLib::Library {
|
||||
delete _natures;
|
||||
}
|
||||
|
||||
PokemonLibrary(CreatureLib::Library::LibrarySettings settings, SpeciesLibrary* species, MoveLibrary* moves,
|
||||
PokemonLibrary(PkmnLib::Library::LibrarySettings* settings, SpeciesLibrary* species, MoveLibrary* moves,
|
||||
ItemLibrary* items, CreatureLib::Library::GrowthRateLibrary* growthRates,
|
||||
CreatureLib::Library::TypeLibrary* typeLibrary, NatureLibrary* natures)
|
||||
: DataLibrary(settings, species, moves, items, growthRates, typeLibrary), _natures(natures) {}
|
||||
|
||||
const PkmnLib::Library::LibrarySettings* GetSettings() const{
|
||||
return static_cast<const LibrarySettings*>(CreatureLib::Library::DataLibrary::GetSettings());
|
||||
}
|
||||
|
||||
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const {
|
||||
return (const SpeciesLibrary*)(CreatureLib::Library::DataLibrary::GetSpeciesLibrary());
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
namespace PkmnLib::Library {
|
||||
class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary {
|
||||
public:
|
||||
|
||||
inline bool TryGetPkmnSpecies(const std::string& name, const PokemonSpecies*& outSpecies) const{
|
||||
return TryGetSpecies(name, (const CreatureLib::Library::CreatureSpecies*&)outSpecies);
|
||||
}
|
||||
|
||||
inline const PokemonSpecies* GetPkmnSpecies(const std::string& name) const {
|
||||
return reinterpret_cast<const PokemonSpecies*>(CreatureLib::Library::SpeciesLibrary::GetSpecies(name));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user