Implements Change Effectiveness script hook in AngelScript.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
95209e51a4
commit
6abef0ddc8
|
@ -4,6 +4,7 @@
|
||||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||||
#include <CreatureLib/Library/Exceptions/NotImplementedException.hpp>
|
#include <CreatureLib/Library/Exceptions/NotImplementedException.hpp>
|
||||||
#include <angelscript.h>
|
#include <angelscript.h>
|
||||||
|
#include <cstdint>
|
||||||
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||||
#include "../../Battling/PkmnScript.hpp"
|
#include "../../Battling/PkmnScript.hpp"
|
||||||
#include "AngelScriptTypeInfo.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,
|
void PreventSecondaryEffects(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target, uint8_t hitNumber, bool* outResult) override {
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber, bool* outResult) override {
|
||||||
CALL_HOOK(PreventSecondaryEffects, {
|
CALL_HOOK(PreventSecondaryEffects, {
|
||||||
|
|
|
@ -45,9 +45,7 @@ public:
|
||||||
|
|
||||||
const ConstString& GetName() const noexcept { return _name; }
|
const ConstString& GetName() const noexcept { return _name; }
|
||||||
|
|
||||||
const char* GetDecl(){
|
const char* GetDecl() { return _type->GetName(); }
|
||||||
return _type->GetName();
|
|
||||||
}
|
|
||||||
|
|
||||||
asIScriptFunction* GetFunction(const ConstString& functionName) {
|
asIScriptFunction* GetFunction(const ConstString& functionName) {
|
||||||
asIScriptFunction* func;
|
asIScriptFunction* func;
|
||||||
|
@ -94,6 +92,9 @@ public:
|
||||||
SCRIPT_HOOK_FUNCTION(OnAttackMiss, "void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target)");
|
SCRIPT_HOOK_FUNCTION(OnAttackMiss, "void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target)");
|
||||||
SCRIPT_HOOK_FUNCTION(ChangeAttackType,
|
SCRIPT_HOOK_FUNCTION(ChangeAttackType,
|
||||||
"void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType)");
|
"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(
|
SCRIPT_HOOK_FUNCTION(
|
||||||
PreventSecondaryEffects,
|
PreventSecondaryEffects,
|
||||||
"void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult)");
|
"void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult)");
|
||||||
|
|
|
@ -18,6 +18,7 @@ shared abstract class PkmnScript {
|
||||||
void IsInvulnerable(ExecutingMove@ attack, Pokemon@ target, bool& result){};
|
void IsInvulnerable(ExecutingMove@ attack, Pokemon@ target, bool& result){};
|
||||||
void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target){};
|
void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target){};
|
||||||
void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType){};
|
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 PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult){};
|
||||||
void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit){};
|
void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit){};
|
||||||
void OnAfterHits(ExecutingMove@ attack, Pokemon@ target){};
|
void OnAfterHits(ExecutingMove@ attack, Pokemon@ target){};
|
||||||
|
|
|
@ -58,6 +58,9 @@ void StopBeforeAttack(ExecutingMove@ attack, bool& result) override{
|
||||||
AS_CLASS(
|
AS_CLASS(
|
||||||
ChangeAttackTypeScript,
|
ChangeAttackTypeScript,
|
||||||
R"(void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType) override{outType = 1; };)"),
|
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(
|
AS_CLASS(
|
||||||
PreventSecondaryEffectsScript,
|
PreventSecondaryEffectsScript,
|
||||||
R"(void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& result) override{ result = !result; })"),
|
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;
|
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") {
|
TEST_CASE("Invoke PreventSecondaryEffects script function") {
|
||||||
auto mainLib = TestLibrary::GetLibrary();
|
auto mainLib = TestLibrary::GetLibrary();
|
||||||
auto script = GetScript(mainLib, "PreventSecondaryEffectsScript"_cnc);
|
auto script = GetScript(mainLib, "PreventSecondaryEffectsScript"_cnc);
|
||||||
|
|
Loading…
Reference in New Issue