Implements missing Script functions.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-22 15:34:24 +02:00
parent b1442f25fb
commit 2e60096d57
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
5 changed files with 64 additions and 23 deletions

View File

@ -93,7 +93,7 @@ public:
arr = GetEffectParameters(ctx, parameters);
ctx->SetArgAddress(0, arr);
})
if (arr != nullptr){
if (arr != nullptr) {
arr->Release();
}
}
@ -102,11 +102,14 @@ public:
void OnRemove() override { CALL_HOOK(OnRemove, ); }
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override {
throw NotImplementedException(); // TODO
CALL_HOOK(OnBeforeTurn, { ctx->SetArgObject(0, (void*)choice); })
}
void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ConstString* outAttack) override {
throw NotImplementedException(); // TODO
CALL_HOOK(ChangeAttack, {
ctx->SetArgObject(0, (void*)choice);
ctx->SetArgAddress(0, outAttack);
})
}
void PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override {
@ -206,7 +209,10 @@ public:
}
void PreventSelfSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) override {
throw NotImplementedException(); // TODO
CALL_HOOK(PreventSelfSwitch, {
ctx->SetArgObject(0, (void*)choice);
ctx->SetArgAddress(1, outResult);
})
}
void ModifyEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,

View File

@ -82,6 +82,9 @@ public:
SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const array<EffectParameter@> &in parameters)");
SCRIPT_HOOK_FUNCTION(Stack, "void Stack()");
SCRIPT_HOOK_FUNCTION(OnRemove, "void OnRemove()");
SCRIPT_HOOK_FUNCTION(OnBeforeTurn, "void OnBeforeTurn(BaseTurnChoice@ choice)");
SCRIPT_HOOK_FUNCTION(ChangeAttack, "void ChangeAttack(MoveTurnChoice@ choice, constString& changedMove)");
SCRIPT_HOOK_FUNCTION(PreventAttack, "void PreventAttack(ExecutingMove@ attack, bool& result)");
SCRIPT_HOOK_FUNCTION(FailAttack, "void FailAttack(ExecutingMove@ attack, bool& result)");
SCRIPT_HOOK_FUNCTION(StopBeforeAttack, "void StopBeforeAttack(ExecutingMove@ attack, bool& result)");
@ -101,6 +104,8 @@ public:
SCRIPT_HOOK_FUNCTION(OnSecondaryEffect,
"void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit)");
SCRIPT_HOOK_FUNCTION(OnAfterHits, "void OnAfterHits(ExecutingMove@ attack, Pokemon@ target)");
SCRIPT_HOOK_FUNCTION(PreventSelfSwitch, "void PreventSelfSwitch(SwitchTurnChoice@ choice, bool& prevented)");
SCRIPT_HOOK_FUNCTION(ModifyEffectChance,
"void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance)");
SCRIPT_HOOK_FUNCTION(ModifyIncomingEffectChance,

View File

@ -2,14 +2,16 @@
#include <cassert>
void BasicScriptClass::Register(asIScriptEngine* engine) {
// As far as I am aware at the moment you can't create an abstract class with virtual members through the application
// registry interface. As such, we just create it from string.
// As far as I am aware at the moment you can't create an abstract class with virtual members through the
// application registry interface. As such, we just create it from string.
[[maybe_unused]] int r = engine->GetModuleByIndex(0)->AddScriptSection("PkmnScript", R"(
shared abstract class PkmnScript {
// CreatureLib methods
void OnInitialize(const array<EffectParameter@> &in parameters){};
void Stack(){};
void OnRemove(){};
void OnBeforeTurn(BaseTurnChoice@ choice){};
void ChangeAttack(MoveTurnChoice@ choice, constString& changedMove){};
void PreventAttack(ExecutingMove@ attack, bool& result){};
void FailAttack(ExecutingMove@ attack, bool& result){};
void StopBeforeAttack(ExecutingMove@ attack, bool& result){};
@ -22,6 +24,7 @@ shared abstract class PkmnScript {
void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult){};
void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit){};
void OnAfterHits(ExecutingMove@ attack, Pokemon@ target){};
void PreventSelfSwitch(SwitchTurnChoice@ choice, bool& prevented){};
void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance){};
void ModifyIncomingEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance){};

View File

@ -1,63 +1,89 @@
#include "RegisterTurnChoices.hpp"
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
#include <CreatureLib/Battling/TurnChoices/BaseTurnChoice.hpp>
#include <cassert>
#include <CreatureLib/Battling/TurnChoices/SwitchTurnChoice.hpp>
#include "../RefCast.hpp"
void RegisterTurnChoices::Register(asIScriptEngine* engine) {
RegisterTurnChoiceKindEnum(engine);
RegisterBaseTurnChoice(engine);
RegisterMoveTurnChoice(engine);
RegisterSwitchTurnChoice(engine);
}
void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind");
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Pass", (int)CreatureLib::Battling::TurnChoiceKind::Pass);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Attack", (int)CreatureLib::Battling::TurnChoiceKind::Attack);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Item", (int)CreatureLib::Battling::TurnChoiceKind::Item);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Switch", (int)CreatureLib::Battling::TurnChoiceKind::Switch);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Flee", (int)CreatureLib::Battling::TurnChoiceKind::Flee);
assert(r >= 0);
Assert(r >= 0);
}
void RegisterTurnChoices::RegisterBaseTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BaseTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("BaseTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::BaseTurnChoice, GetKind), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("BaseTurnChoice", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::BaseTurnChoice, GetUser), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
}
void RegisterTurnChoices::RegisterMoveTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetKind), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetUser), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "LearnedMove@ get_Move() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetAttack), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "int8 get_Priority() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetPriority), asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"BaseTurnChoice", "MoveTurnChoice@ opCast()",
asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::AttackTurnChoice>)),
asCALL_CDECL_OBJLAST);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"MoveTurnChoice", "BaseTurnChoice@ opImplCast()",
asFUNCTION((refCast<CreatureLib::Battling::AttackTurnChoice, CreatureLib::Battling::BaseTurnChoice>)),
asCALL_CDECL_OBJLAST);
assert(r >= 0);
Assert(r >= 0);
}
void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("SwitchTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetKind), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetUser), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetNewCreature), asCALL_THISCALL);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"SwitchTurnChoice", "MoveTurnChoice@ opCast()",
asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::SwitchTurnChoice>)),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
r = engine->RegisterObjectMethod(
"SwitchTurnChoice", "BaseTurnChoice@ opImplCast()",
asFUNCTION((refCast<CreatureLib::Battling::AttackTurnChoice, CreatureLib::Battling::SwitchTurnChoice>)),
asCALL_CDECL_OBJLAST);
Assert(r >= 0);
}

View File

@ -6,6 +6,7 @@ class RegisterTurnChoices {
static void RegisterTurnChoiceKindEnum(asIScriptEngine* engine);
static void RegisterBaseTurnChoice(asIScriptEngine* engine);
static void RegisterMoveTurnChoice(asIScriptEngine* engine);
static void RegisterSwitchTurnChoice(asIScriptEngine* engine);
public:
static void Register(asIScriptEngine* engine);
};