Implements missing Script functions.
All checks were successful
continuous-integration/drone/push Build is passing

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

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);
};