Rework AngelScript effect names to be not based on script names, but on attributes instead.
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:
@@ -5,7 +5,7 @@
|
||||
#include "../TestLibrary/TestLibrary.hpp"
|
||||
|
||||
#define AS_CLASS(name, contents) \
|
||||
{ #name, "namespace Pokemon{ class " #name " : PkmnScript { " contents "}}" }
|
||||
{ #name, "namespace Pokemon{ [Pokemon effect=" #name "] class " #name " : PkmnScript { " contents "}}" }
|
||||
|
||||
static std::unordered_map<const char*, const char*> _scripts = std::unordered_map<const char*, const char*>{
|
||||
AS_CLASS(blankScript, ),
|
||||
@@ -20,6 +20,7 @@ class doubleInheritanceScriptBase : PkmnScript {
|
||||
|
||||
int GetValue(){ return value; }
|
||||
}
|
||||
[Pokemon effect=doubleInheritanceScript]
|
||||
class doubleInheritanceScript : doubleInheritanceScriptBase {}
|
||||
)"},
|
||||
AS_CLASS(preventAttackScript,
|
||||
@@ -78,12 +79,16 @@ static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, c
|
||||
auto lib = GetScriptResolver(mainLib);
|
||||
auto s = lib->LoadScript(ScriptCategory::Creature, scriptName);
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
return script;
|
||||
}
|
||||
|
||||
TEST_CASE("Invoke non-implemented script function") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "blankScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
script->Stack();
|
||||
delete script;
|
||||
}
|
||||
@@ -91,6 +96,8 @@ TEST_CASE("Invoke non-implemented script function") {
|
||||
TEST_CASE("Invoke Stack script function") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "stackScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
script->Stack();
|
||||
|
||||
@@ -108,6 +115,8 @@ TEST_CASE("Invoke Stack script function") {
|
||||
TEST_CASE("Invoke OnRemove script function") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "onRemoveScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
script->OnRemove();
|
||||
|
||||
auto ctxPool = script->GetContextPool();
|
||||
@@ -160,6 +169,7 @@ TEST_CASE("Invoke StopBeforeAttack script function") {
|
||||
TEST_CASE("Invoke OnBeforeAttack script function") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "OnBeforeAttackScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
script->OnBeforeAttack(nullptr);
|
||||
|
||||
@@ -176,6 +186,7 @@ TEST_CASE("Invoke OnBeforeAttack script function") {
|
||||
TEST_CASE("Invoke FailIncomingAttack script function") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "FailIncomingAttackScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
bool b = false;
|
||||
script->FailIncomingAttack(nullptr, nullptr, &b);
|
||||
REQUIRE(b);
|
||||
@@ -186,6 +197,7 @@ TEST_CASE("Invoke FailIncomingAttack script function") {
|
||||
TEST_CASE("Invoke OnAttackMiss script function") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "OnAttackMissScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
script->OnAttackMiss(nullptr, nullptr);
|
||||
|
||||
@@ -202,6 +214,7 @@ TEST_CASE("Invoke OnAttackMiss script function") {
|
||||
TEST_CASE("Invoke ChangeAttackType script function") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "ChangeAttackTypeScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
uint8_t b = 0;
|
||||
script->ChangeAttackType(nullptr, nullptr, 0, &b);
|
||||
REQUIRE(b == 1);
|
||||
@@ -254,6 +267,7 @@ TEST_CASE("Invoke OnSecondaryEffect script function") {
|
||||
TEST_CASE("Invoke OnAfterHits script function") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "OnAfterHitsScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
script->OnAfterHits(nullptr, nullptr);
|
||||
|
||||
@@ -272,9 +286,21 @@ void TryException(AngelScriptScript* script) {
|
||||
script->PreventAttack(nullptr, &b);
|
||||
}
|
||||
|
||||
TEST_CASE("Get script name.") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "throwScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
INFO(script->GetName().c_str());
|
||||
INFO(script->GetName().std_str());
|
||||
CHECK(strcmp(script->GetName().c_str(), "throwScript") == 0);
|
||||
delete script;
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Handle script exceptions.") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "throwScript"_cnc);
|
||||
REQUIRE(script != nullptr);
|
||||
CHECK_THROWS_WITH(
|
||||
TryException(script),
|
||||
Catch::Matchers::Equals("Script exception in script 'throwScript', line 1. Message: 'test exception'."));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||
namespace Pokemon{
|
||||
[Pokemon effect=testScript1]
|
||||
class testScript1 {
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
@@ -54,6 +55,7 @@ TEST_CASE("Build script resolver, create object, invoke addition method") {
|
||||
|
||||
auto obj =
|
||||
dynamic_cast<AngelScriptScript*>(lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc));
|
||||
REQUIRE(obj != nullptr);
|
||||
auto ctxPool = obj->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||
namespace Pokemon{
|
||||
[Pokemon effect=testScript1]
|
||||
class testScript1 {
|
||||
bool testSpecies(Pokemon@ p, const Species@ species){ return p.Species is species; }
|
||||
bool testForme(Pokemon@ p, const Forme@ forme){ return p.Forme is forme; }
|
||||
@@ -55,6 +56,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
|
||||
auto lib = GetScriptResolver(mainLib);
|
||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
auto ctxPool = script->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||
namespace Pokemon{
|
||||
[Pokemon effect=testScript1]
|
||||
class testScript1 {
|
||||
bool testName(const Forme@ s, const constString &in name){ return s.Name == name; }
|
||||
bool testWeight(const Forme@ s, float weight){ return s.Weight == weight; }
|
||||
@@ -45,6 +46,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
|
||||
auto lib = GetScriptResolver(mainLib);
|
||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
auto ctxPool = script->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||
namespace Pokemon{
|
||||
[Pokemon effect=testScript1]
|
||||
class testScript1 {
|
||||
bool testName(const Item@ i, const constString &in name){ return i.Name == name; }
|
||||
bool testCategory(const Item@ i, ItemCategory category){ return i.Category == category; }
|
||||
@@ -41,6 +42,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
|
||||
auto lib = GetScriptResolver(mainLib);
|
||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
auto ctxPool = script->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||
namespace Pokemon{
|
||||
[Pokemon effect=testScript1]
|
||||
class testScript1 {
|
||||
bool testName(const MoveData@ s, const constString &in name){ return s.Name == name; }
|
||||
bool testType(const MoveData@ s, uint8 type){ return s.Type == type; }
|
||||
@@ -45,6 +46,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
|
||||
auto lib = GetScriptResolver(mainLib);
|
||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
auto ctxPool = script->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||
namespace Pokemon{
|
||||
[Pokemon effect=testScript1]
|
||||
class testScript1 {
|
||||
bool testName(const Species@ s, const constString &in name){ return s.Name == name; }
|
||||
bool testId(const Species@ s, uint16 id){ return s.Id == id; }
|
||||
@@ -43,6 +44,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
|
||||
auto lib = GetScriptResolver(mainLib);
|
||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
auto ctxPool = script->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
static std::unordered_map<const char*, const char*> _scripts =
|
||||
std::unordered_map<const char*, const char*>{{"testScript1", R"(
|
||||
namespace Pokemon{
|
||||
[Pokemon effect=testScript1]
|
||||
class testScript1 {
|
||||
bool testMaximumLevel(const StaticLibrary@ s, uint8 level){ return s.Settings.MaximalLevel == level; }
|
||||
bool testMaximumMoves(const StaticLibrary@ s, uint8 moveCount){ return s.Settings.MaximalMoves == moveCount; }
|
||||
@@ -44,6 +45,8 @@ static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const Con
|
||||
auto lib = GetScriptResolver(mainLib);
|
||||
auto s = lib->LoadScript(ScriptCategory::Creature, "testScript1"_cnc);
|
||||
auto script = dynamic_cast<AngelScriptScript*>(s);
|
||||
REQUIRE(script != nullptr);
|
||||
|
||||
auto ctxPool = script->GetContextPool();
|
||||
auto ctx = ctxPool->RequestContext();
|
||||
|
||||
|
||||
@@ -41,11 +41,11 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
|
||||
}
|
||||
PkmnLib::Library::MoveLibrary* TestLibrary::BuildMoveLibrary() {
|
||||
auto lib = new PkmnLib::Library::MoveLibrary();
|
||||
lib->Insert("testMove"_cnc,
|
||||
lib->Insert("testMove"_cnc.GetHash(),
|
||||
new PkmnLib::Library::MoveData("testMove"_cnc, 0, PkmnLib::Library::MoveCategory::Physical, 50, 100, 20,
|
||||
CreatureLib::Library::AttackTarget::Adjacent, 0,
|
||||
CreatureLib::Library::SecondaryEffect(), {}));
|
||||
lib->Insert("testMove2"_cnc,
|
||||
lib->Insert("testMove2"_cnc.GetHash(),
|
||||
new PkmnLib::Library::MoveData("testMove2"_cnc, 0, PkmnLib::Library::MoveCategory::Special, 30, 100, 10,
|
||||
CreatureLib::Library::AttackTarget::Adjacent, 0,
|
||||
CreatureLib::Library::SecondaryEffect(), {}));
|
||||
|
||||
@@ -24,8 +24,7 @@ public:
|
||||
auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
|
||||
auto lib = new PkmnLib::Battling::BattleLibrary(
|
||||
BuildStaticLibrary(), statCalc, new PkmnLib::Battling::DamageLibrary(),
|
||||
new CreatureLib::Battling::ExperienceLibrary(), scriptResolver,
|
||||
new CreatureLib::Battling::MiscLibrary());
|
||||
new CreatureLib::Battling::ExperienceLibrary(), scriptResolver, new CreatureLib::Battling::MiscLibrary());
|
||||
scriptResolver->Initialize(lib);
|
||||
return lib;
|
||||
}
|
||||
@@ -45,7 +44,7 @@ public:
|
||||
static CreatureLib::Library::GrowthRateLibrary* BuildGrowthRateLibrary() {
|
||||
auto lib = new CreatureLib::Library::GrowthRateLibrary();
|
||||
lib->AddGrowthRate(
|
||||
"testGrowthRate"_cnc,
|
||||
"testGrowthRate"_cnc.GetHash(),
|
||||
new CreatureLib::Library::LookupGrowthRate(
|
||||
{0, 15, 52, 122, 237, 406, 637, 942, 1326, 1800, 2369, 3041, 3822,
|
||||
4719, 5737, 6881, 8155, 9564, 11111, 12800, 14632, 16610, 18737, 21012, 23437, 26012,
|
||||
@@ -67,8 +66,9 @@ public:
|
||||
auto lib = new PkmnLib::Library::NatureLibrary();
|
||||
lib->LoadNature("neutralNature", PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
||||
PkmnLib::Library::Statistic::PhysicalDefense, 1, 1));
|
||||
lib->LoadNature("buffsAttackNerfsSpeed", PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
||||
PkmnLib::Library::Statistic::Speed, 1.1, 0.9));
|
||||
lib->LoadNature("buffsAttackNerfsSpeed",
|
||||
PkmnLib::Library::Nature(PkmnLib::Library::Statistic::PhysicalAttack,
|
||||
PkmnLib::Library::Statistic::Speed, 1.1, 0.9));
|
||||
return lib;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user