diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index 49eff8a..9a6e77f 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -4,6 +4,7 @@ #define ANGELSCRIPT_DLL_LIBRARY_IMPORT #include #include +#include #include "../../../extern/angelscript_addons/scriptarray/scriptarray.h" #include "../../Battling/PkmnScript.hpp" #include "AngelScriptTypeInfo.hpp" @@ -167,6 +168,16 @@ public: }) } + void ChangeEffectiveness(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, + uint8_t hitNumber, float* effectiveness) override { + CALL_HOOK(ChangeEffectiveness, { + ctx->SetArgObject(0, (void*)attack); + ctx->SetArgObject(1, (void*)target); + ctx->SetArgByte(2, hitNumber); + ctx->SetArgAddress(3, effectiveness); + }) + } + void PreventSecondaryEffects(const CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t hitNumber, bool* outResult) override { CALL_HOOK(PreventSecondaryEffects, { diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index cadab39..1022636 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -45,9 +45,7 @@ public: const ConstString& GetName() const noexcept { return _name; } - const char* GetDecl(){ - return _type->GetName(); - } + const char* GetDecl() { return _type->GetName(); } asIScriptFunction* GetFunction(const ConstString& functionName) { asIScriptFunction* func; @@ -94,6 +92,9 @@ public: SCRIPT_HOOK_FUNCTION(OnAttackMiss, "void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target)"); SCRIPT_HOOK_FUNCTION(ChangeAttackType, "void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType)"); + SCRIPT_HOOK_FUNCTION( + ChangeEffectiveness, + "void ChangeEffectiveness(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& effectiveness)"); SCRIPT_HOOK_FUNCTION( PreventSecondaryEffects, "void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult)"); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp index 42aa0b2..4c147a8 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp @@ -18,6 +18,7 @@ shared abstract class PkmnScript { void IsInvulnerable(ExecutingMove@ attack, Pokemon@ target, bool& result){}; void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target){}; void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType){}; + void ChangeEffectiveness(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& effectiveness){}; void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult){}; void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit){}; void OnAfterHits(ExecutingMove@ attack, Pokemon@ target){}; diff --git a/tests/ScriptTests/BaseScriptClassTests.cpp b/tests/ScriptTests/BaseScriptClassTests.cpp index 6ee5e4b..d484a0f 100644 --- a/tests/ScriptTests/BaseScriptClassTests.cpp +++ b/tests/ScriptTests/BaseScriptClassTests.cpp @@ -58,6 +58,9 @@ void StopBeforeAttack(ExecutingMove@ attack, bool& result) override{ AS_CLASS( ChangeAttackTypeScript, R"(void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType) override{outType = 1; };)"), + AS_CLASS( + ChangeEffectivenessScript, + R"(void ChangeEffectiveness(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& eff) override{eff = 0.75; };)"), AS_CLASS( PreventSecondaryEffectsScript, R"(void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& result) override{ result = !result; })"), @@ -271,6 +274,17 @@ TEST_CASE("Invoke ChangeAttackType script function") { delete script; } +TEST_CASE("Invoke ChangeEffectiveness script function") { + auto mainLib = TestLibrary::GetLibrary(); + auto script = GetScript(mainLib, "ChangeEffectivenessScript"_cnc); + REQUIRE(script != nullptr); + float b = 0; + script->ChangeEffectiveness(nullptr, nullptr, 0, &b); + REQUIRE(b == Approx(0.75)); + + delete script; +} + TEST_CASE("Invoke PreventSecondaryEffects script function") { auto mainLib = TestLibrary::GetLibrary(); auto script = GetScript(mainLib, "PreventSecondaryEffectsScript"_cnc);