More tests for Pokemon class in AngelScript.
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:
@@ -40,7 +40,7 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
auto rand = CreatureLib::Core::Random();
|
||||
const PkmnLib::Library::PokemonSpecies* species = nullptr;
|
||||
if (!this->_library->GetSpeciesLibrary()->TryGetPkmnSpecies(this->_species, species)){
|
||||
if (!this->_library->GetSpeciesLibrary()->TryGetPkmnSpecies(this->_species, species)) {
|
||||
throw CreatureException("Invalid species: " + _species);
|
||||
}
|
||||
auto forme = species->GetForme(this->_forme);
|
||||
@@ -60,7 +60,7 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
}
|
||||
const Library::Item* heldItem = nullptr;
|
||||
if (!this->_heldItem.empty()) {
|
||||
if (!_library->GetItemLibrary()->TryGetItem(this->_heldItem, heldItem)){
|
||||
if (!_library->GetItemLibrary()->TryGetItem(this->_heldItem, heldItem)) {
|
||||
throw CreatureException("Unknown Item: " + this->_heldItem);
|
||||
}
|
||||
}
|
||||
@@ -79,10 +79,9 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||
}
|
||||
|
||||
auto shiny = false;
|
||||
if (_shininessSet){
|
||||
if (_shininessSet) {
|
||||
shiny = _isShiny;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
shiny = rand.Get(_library->GetSettings()->GetShinyRate()) == 0;
|
||||
}
|
||||
|
||||
@@ -134,3 +133,15 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem
|
||||
_heldItem = item;
|
||||
return this;
|
||||
}
|
||||
PkmnLib::Battling::CreatePokemon*
|
||||
PkmnLib::Battling::CreatePokemon::LearnMove(const std::string& moveName, CreatureLib::Battling::AttackLearnMethod method) {
|
||||
const PkmnLib::Library::MoveData* move;
|
||||
if (!_library->GetMoveLibrary()->TryGetMove(moveName, move)){
|
||||
throw CreatureException("Invalid Move given: " + moveName);
|
||||
}
|
||||
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()){
|
||||
throw CreatureException("This pokemon already has the maximal allowed moves.");
|
||||
}
|
||||
_attacks.emplace_back(move, method);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace PkmnLib::Battling {
|
||||
CreatePokemon* WithGender(CreatureLib::Library::Gender gender);
|
||||
CreatePokemon* IsShiny(bool value);
|
||||
CreatePokemon* WithHeldItem(const std::string& item);
|
||||
CreatePokemon* LearnMove(const std::string& move, CreatureLib::Battling::AttackLearnMethod method);
|
||||
|
||||
CreatePokemon* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random());
|
||||
CreatePokemon* WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value);
|
||||
|
||||
@@ -33,8 +33,10 @@ namespace PkmnLib::Battling {
|
||||
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
|
||||
}
|
||||
|
||||
const bool IsShiny() const{
|
||||
return _coloring == 1;
|
||||
const bool IsShiny() const { return _coloring == 1; }
|
||||
|
||||
const std::vector<const LearnedMove*>& GetMoves() const {
|
||||
return (const std::vector<const LearnedMove*>&)_attacks;
|
||||
}
|
||||
|
||||
const Library::Nature& GetNature() const;
|
||||
|
||||
@@ -68,6 +68,22 @@ CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) {
|
||||
asIScriptContext* ctx = asGetActiveContext();
|
||||
if (ctx) {
|
||||
asIScriptEngine* engine = ctx->GetEngine();
|
||||
asITypeInfo* t = engine->GetTypeInfoByDecl("array<LearnedMove@>");
|
||||
auto a = obj->GetMoves();
|
||||
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);
|
||||
assert(r >= 0);
|
||||
@@ -119,8 +135,8 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ get_Moves() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetAttacks), asCALL_THISCALL);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ GetMoves() const",
|
||||
asFUNCTION(GetMoves), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplaySpecies() const property",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplaySpecies), asCALL_THISCALL);
|
||||
|
||||
Reference in New Issue
Block a user