Support for specific PkmnLib functions in Scripts, added ModifyCriticalStage function.
This commit is contained in:
parent
83a49eee6c
commit
19cfcc9e32
|
@ -0,0 +1,20 @@
|
|||
#include "MiscLibrary.hpp"
|
||||
#include <CreatureLib/Battling/Models/Battle.hpp>
|
||||
#include "../PkmnScriptHook.hpp"
|
||||
|
||||
bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hit) const {
|
||||
uint8_t critStage = 0;
|
||||
PKMN_HOOK(ModifyCriticalStage, attack, attack, target, hit, &critStage);
|
||||
auto rand = target->GetBattle()->GetRandom();
|
||||
switch (critStage){
|
||||
case 0: return rand->Get(24) == 0;
|
||||
case 1: return rand->Get(8) == 0;
|
||||
case 2: return rand->Get(2) == 0;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool PkmnLib::Battling::MiscLibrary::CanFlee(CreatureLib::Battling::FleeTurnChoice* switchChoice) const {
|
||||
return CreatureLib::Battling::MiscLibrary::CanFlee(switchChoice);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef PKMNLIB_MISCLIBRARY_HPP
|
||||
#define PKMNLIB_MISCLIBRARY_HPP
|
||||
|
||||
#include <CreatureLib/Battling/Library/MiscLibrary.hpp>
|
||||
|
||||
namespace PkmnLib::Battling{
|
||||
class MiscLibrary : CreatureLib::Battling::MiscLibrary {
|
||||
~MiscLibrary() override = default;
|
||||
bool IsCritical(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||
uint8_t hit) const override;
|
||||
bool CanFlee(CreatureLib::Battling::FleeTurnChoice* switchChoice) const override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PKMNLIB_MISCLIBRARY_HPP
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef PKMNLIB_PKMNSCRIPT_HPP
|
||||
#define PKMNLIB_PKMNSCRIPT_HPP
|
||||
#include <CreatureLib/Battling/ScriptHandling/Script.hpp>
|
||||
#include "Pokemon/Pokemon.hpp"
|
||||
|
||||
namespace PkmnLib::Battling{
|
||||
class PkmnScript : public CreatureLib::Battling::Script{
|
||||
public:
|
||||
PkmnScript(const std::string& name) : Script(name) {}
|
||||
|
||||
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PKMNLIB_PKMNSCRIPT_HPP
|
|
@ -0,0 +1,13 @@
|
|||
#include "PkmnScript.hpp"
|
||||
|
||||
#define PKMN_HOOK(hookName, source, ...) \
|
||||
{ \
|
||||
auto aggregator = source->GetScriptIterator(); \
|
||||
while (aggregator.HasNext()) { \
|
||||
auto next = aggregator.GetNext(); \
|
||||
if (next == nullptr) \
|
||||
continue; \
|
||||
auto castNext = dynamic_cast<PkmnLib::Battling::PkmnScript*>(next); \
|
||||
castNext->hookName(__VA_ARGS__); \
|
||||
} \
|
||||
}
|
|
@ -4,10 +4,11 @@
|
|||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||
#include <CreatureLib/Core/Exceptions/NotImplementedException.hpp>
|
||||
#include <angelscript.h>
|
||||
#include "../../Battling/PkmnScript.hpp"
|
||||
#include "AngelScriptTypeInfo.hpp"
|
||||
#include "ContextPool.hpp"
|
||||
|
||||
class AngelScriptScript : public CreatureLib::Battling::Script {
|
||||
class AngelScriptScript : public PkmnLib::Battling::PkmnScript {
|
||||
private:
|
||||
AngelScriptTypeInfo* _type = nullptr;
|
||||
ContextPool* _ctxPool = nullptr;
|
||||
|
@ -16,7 +17,7 @@ private:
|
|||
|
||||
public:
|
||||
AngelScriptScript(const std::string& name, AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool)
|
||||
: CreatureLib::Battling::Script(name), _type(type), _ctxPool(ctxPool), _obj(obj) {}
|
||||
: PkmnLib::Battling::PkmnScript(name), _type(type), _ctxPool(ctxPool), _obj(obj) {}
|
||||
|
||||
~AngelScriptScript() override { _obj->Release(); }
|
||||
|
||||
|
@ -251,6 +252,20 @@ public:
|
|||
ctx->SetArgAddress(3, damage);
|
||||
})
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// PkmnLib methods//
|
||||
////////////////////
|
||||
|
||||
void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||
uint8_t hit, uint8_t* critStage) override {
|
||||
CALL_HOOK(ModifyCriticalStage, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgByte(2, hit);
|
||||
ctx->SetArgAddress(3, critStage);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
#undef CALL_HOOK
|
||||
|
|
|
@ -95,7 +95,8 @@ SCRIPT_HOOK_FUNCTION(ModifyIncomingEffectChance,
|
|||
|
||||
SCRIPT_HOOK_FUNCTION(OverrideBasePower,
|
||||
"void OverrideBasePower(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& chance)");
|
||||
SCRIPT_HOOK_FUNCTION(ChangeDamageStatsUser,
|
||||
SCRIPT_HOOK_FUNCTION(
|
||||
ChangeDamageStatsUser,
|
||||
"void ChangeDamageStatsUser(ExecutingMove@ attack, Pokemon@ target, uint8 hit, Pokemon@& user)");
|
||||
SCRIPT_HOOK_FUNCTION(BypassDefensiveStat,
|
||||
"void BypassDefensiveStat(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& bypass)");
|
||||
|
@ -103,11 +104,15 @@ SCRIPT_HOOK_FUNCTION(BypassOffensiveStat,
|
|||
"void BypassOffensiveStat(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& bypass)");
|
||||
SCRIPT_HOOK_FUNCTION(ModifyStatModifier,
|
||||
"void ModifyStatModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& modifier)");
|
||||
SCRIPT_HOOK_FUNCTION(ModifyDamageModifier,
|
||||
SCRIPT_HOOK_FUNCTION(
|
||||
ModifyDamageModifier,
|
||||
"void ModifyDamageModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& modifier)");
|
||||
SCRIPT_HOOK_FUNCTION(OverrideDamage,
|
||||
"void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage)");
|
||||
|
||||
SCRIPT_HOOK_FUNCTION(
|
||||
ModifyCriticalStage,
|
||||
"void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage)");
|
||||
};
|
||||
|
||||
#undef SCRIPT_HOOK_FUNCTION
|
||||
|
|
|
@ -6,6 +6,7 @@ void BasicScriptClass::Register(asIScriptEngine* engine) {
|
|||
// 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 Stack(){};
|
||||
void OnRemove(){};
|
||||
void PreventAttack(ExecutingMove@ attack, bool& result){};
|
||||
|
@ -31,6 +32,9 @@ shared abstract class PkmnScript {
|
|||
void ModifyStatModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& modifier){};
|
||||
void ModifyDamageModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& modifier){};
|
||||
void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage){};
|
||||
|
||||
// PkmnLib methods
|
||||
void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){};
|
||||
}
|
||||
)");
|
||||
assert(r >= 0);
|
||||
|
|
Loading…
Reference in New Issue