More tests for Pokemon class in AngelScript.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
aae96333b1
commit
419e573bbe
|
@ -40,7 +40,7 @@ class PkmnLibConan(ConanFile):
|
||||||
self.options["AngelScript"].link_std_statically = True
|
self.options["AngelScript"].link_std_statically = True
|
||||||
|
|
||||||
def requirements(self):
|
def requirements(self):
|
||||||
self.requires("CreatureLib/bb9b9609a6e595ff8e6d4f4682b4be5b5e8d9d7e@creaturelib/master")
|
self.requires("CreatureLib/fc5826edb1d164a261a33aebb164af7df8ab7ef4@creaturelib/master")
|
||||||
if self.options.script_handler == "angelscript":
|
if self.options.script_handler == "angelscript":
|
||||||
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
|
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -40,7 +40,7 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithEffortVa
|
||||||
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||||
auto rand = CreatureLib::Core::Random();
|
auto rand = CreatureLib::Core::Random();
|
||||||
const PkmnLib::Library::PokemonSpecies* species = nullptr;
|
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);
|
throw CreatureException("Invalid species: " + _species);
|
||||||
}
|
}
|
||||||
auto forme = species->GetForme(this->_forme);
|
auto forme = species->GetForme(this->_forme);
|
||||||
|
@ -60,7 +60,7 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||||
}
|
}
|
||||||
const Library::Item* heldItem = nullptr;
|
const Library::Item* heldItem = nullptr;
|
||||||
if (!this->_heldItem.empty()) {
|
if (!this->_heldItem.empty()) {
|
||||||
if (!_library->GetItemLibrary()->TryGetItem(this->_heldItem, heldItem)){
|
if (!_library->GetItemLibrary()->TryGetItem(this->_heldItem, heldItem)) {
|
||||||
throw CreatureException("Unknown Item: " + this->_heldItem);
|
throw CreatureException("Unknown Item: " + this->_heldItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,9 @@ PkmnLib::Battling::Pokemon* PkmnLib::Battling::CreatePokemon::Build() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto shiny = false;
|
auto shiny = false;
|
||||||
if (_shininessSet){
|
if (_shininessSet) {
|
||||||
shiny = _isShiny;
|
shiny = _isShiny;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
shiny = rand.Get(_library->GetSettings()->GetShinyRate()) == 0;
|
shiny = rand.Get(_library->GetSettings()->GetShinyRate()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,3 +133,15 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem
|
||||||
_heldItem = item;
|
_heldItem = item;
|
||||||
return this;
|
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* WithGender(CreatureLib::Library::Gender gender);
|
||||||
CreatePokemon* IsShiny(bool value);
|
CreatePokemon* IsShiny(bool value);
|
||||||
CreatePokemon* WithHeldItem(const std::string& item);
|
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* WithRandomIndividualValues(CreatureLib::Core::Random rand = CreatureLib::Core::Random());
|
||||||
CreatePokemon* WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value);
|
CreatePokemon* WithIndividualValue(CreatureLib::Core::Statistic stat, uint8_t value);
|
||||||
|
|
|
@ -33,8 +33,10 @@ namespace PkmnLib::Battling {
|
||||||
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
|
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool IsShiny() const{
|
const bool IsShiny() const { return _coloring == 1; }
|
||||||
return _coloring == 1;
|
|
||||||
|
const std::vector<const LearnedMove*>& GetMoves() const {
|
||||||
|
return (const std::vector<const LearnedMove*>&)_attacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Library::Nature& GetNature() const;
|
const Library::Nature& GetNature() const;
|
||||||
|
|
|
@ -68,6 +68,22 @@ CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) {
|
||||||
return nullptr;
|
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) {
|
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);
|
assert(r >= 0);
|
||||||
|
@ -119,8 +135,8 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||||
r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)",
|
r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)",
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
|
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ get_Moves() const property",
|
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ GetMoves() const",
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, GetAttacks), asCALL_THISCALL);
|
asFUNCTION(GetMoves), asCALL_CDECL_OBJLAST);
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplaySpecies() const property",
|
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplaySpecies() const property",
|
||||||
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplaySpecies), asCALL_THISCALL);
|
asMETHOD(PkmnLib::Battling::Pokemon, GetDisplaySpecies), asCALL_THISCALL);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifdef TESTS_BUILD
|
#ifdef TESTS_BUILD
|
||||||
#include "../../../../extern/catch.hpp"
|
#include "../../../../extern/catch.hpp"
|
||||||
#include "../../../../src/ScriptResolving/AngelScript/AngelScripResolver.hpp"
|
|
||||||
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
#include "../../../../src/Battling/Pokemon/CreatePokemon.hpp"
|
||||||
|
#include "../../../../src/ScriptResolving/AngelScript/AngelScripResolver.hpp"
|
||||||
#include "../../../TestLibrary/TestLibrary.hpp"
|
#include "../../../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
||||||
static std::unordered_map<const char*, const char*> _scripts =
|
static std::unordered_map<const char*, const char*> _scripts =
|
||||||
|
@ -19,6 +19,10 @@ class testScript1 {
|
||||||
bool testActiveAbility(Pokemon@ p, const string &in ability){ return p.ActiveAbility == ability; }
|
bool testActiveAbility(Pokemon@ p, const string &in ability){ return p.ActiveAbility == ability; }
|
||||||
bool testIsFainted(Pokemon@ p, bool b){ return p.IsFainted == b; }
|
bool testIsFainted(Pokemon@ p, bool b){ return p.IsFainted == b; }
|
||||||
bool testType(Pokemon@ p, uint index, uint8 type){ return p.GetTypes()[index] == type; }
|
bool testType(Pokemon@ p, uint index, uint8 type){ return p.GetTypes()[index] == type; }
|
||||||
|
bool testHasType(Pokemon@ p, uint8 type){ return p.HasType(type); }
|
||||||
|
void testDamage(Pokemon@ p, uint32 damage, DamageSource source){ p.Damage(damage, source); }
|
||||||
|
bool testMove(Pokemon@ p, uint index, LearnedMove@ move){ return p.GetMoves()[index] is move; }
|
||||||
|
|
||||||
}
|
}
|
||||||
)"}};
|
)"}};
|
||||||
|
|
||||||
|
@ -232,10 +236,10 @@ TEST_CASE("Validate Pokemon GetTypes in Script") {
|
||||||
auto mainLib = TestLibrary::GetLibrary();
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
|
||||||
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3", 30)
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3", 30)
|
||||||
.WithForme("default")
|
.WithForme("default")
|
||||||
->WithGender(CreatureLib::Library::Gender::Male)
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
->Build();
|
->Build();
|
||||||
for (size_t i = 0; i < mon->GetTypes().size(); i++){
|
for (size_t i = 0; i < mon->GetTypes().size(); i++) {
|
||||||
auto data = GetScript(mainLib, "testType");
|
auto data = GetScript(mainLib, "testType");
|
||||||
|
|
||||||
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
@ -244,12 +248,71 @@ TEST_CASE("Validate Pokemon GetTypes in Script") {
|
||||||
|
|
||||||
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
REQUIRE((bool)data.Context->GetReturnWord());
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon HasType in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
for (size_t i = 0; i < mon->GetTypes().size(); i++) {
|
||||||
|
auto data = GetScript(mainLib, "testHasType");
|
||||||
|
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgByte(1, mon->GetTypes()[i]);
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
}
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon Damage in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->WithGender(CreatureLib::Library::Gender::Male)
|
||||||
|
->Build();
|
||||||
|
auto data = GetScript(mainLib, "testDamage");
|
||||||
|
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgDWord(1, 30);
|
||||||
|
data.Context->SetArgDWord(2, (asDWORD)CreatureLib::Battling::DamageSource::AttackDamage);
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE(mon->GetCurrentHealth() == mon->GetBoostedStat(PkmnLib::Library::Statistic::HealthPoints) - 30);
|
||||||
|
|
||||||
|
delete mon;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Validate Pokemon GetMoves in Script") {
|
||||||
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
|
|
||||||
|
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3", 30)
|
||||||
|
.WithForme("default")
|
||||||
|
->LearnMove("testMove", CreatureLib::Battling::AttackLearnMethod::Level)
|
||||||
|
->LearnMove("testMove2", CreatureLib::Battling::AttackLearnMethod::Unknown)
|
||||||
|
->Build();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < mon->GetMoves().size(); i++) {
|
||||||
|
auto data = GetScript(mainLib, "testMove");
|
||||||
|
|
||||||
|
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
|
||||||
|
data.Context->SetArgDWord(1, i);
|
||||||
|
data.Context->SetArgObject(2, (void*)mon->GetMoves()[i]);
|
||||||
|
|
||||||
|
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||||
|
REQUIRE((bool)data.Context->GetReturnWord());
|
||||||
|
}
|
||||||
|
|
||||||
delete mon;
|
delete mon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -43,6 +43,9 @@ PkmnLib::Library::MoveLibrary* TestLibrary::BuildMoveLibrary() {
|
||||||
lib->LoadMove("testMove",
|
lib->LoadMove("testMove",
|
||||||
new PkmnLib::Library::MoveData("testMove", 0, PkmnLib::Library::MoveCategory::Physical, 50, 100, 20,
|
new PkmnLib::Library::MoveData("testMove", 0, PkmnLib::Library::MoveCategory::Physical, 50, 100, 20,
|
||||||
CreatureLib::Library::AttackTarget::Adjacent, 0, {}));
|
CreatureLib::Library::AttackTarget::Adjacent, 0, {}));
|
||||||
|
lib->LoadMove("testMove2",
|
||||||
|
new PkmnLib::Library::MoveData("testMove2", 0, PkmnLib::Library::MoveCategory::Special, 30, 100, 10,
|
||||||
|
CreatureLib::Library::AttackTarget::Adjacent, 0, {}));
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
PkmnLib::Library::ItemLibrary* TestLibrary::BuildItemLibrary() {
|
PkmnLib::Library::ItemLibrary* TestLibrary::BuildItemLibrary() {
|
||||||
|
|
Loading…
Reference in New Issue