2020-01-11 21:30:23 +00:00
|
|
|
#ifndef PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|
|
|
|
#define PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|
|
|
|
|
2020-01-12 17:20:59 +00:00
|
|
|
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
2021-10-30 12:29:57 +00:00
|
|
|
#include <Arbutils/Collections/Dictionary.hpp>
|
2020-04-06 18:03:44 +00:00
|
|
|
#include <CreatureLib/Library/Exceptions/CreatureException.hpp>
|
2020-01-11 21:30:23 +00:00
|
|
|
#include <angelscript.h>
|
|
|
|
|
|
|
|
class AngelScriptTypeInfo {
|
|
|
|
private:
|
|
|
|
asITypeInfo* _type = nullptr;
|
2020-05-27 15:26:25 +00:00
|
|
|
ArbUt::Dictionary<uint32_t, asIScriptFunction*> _functions;
|
2020-07-04 13:50:30 +00:00
|
|
|
ArbUt::StringView _name;
|
2020-01-11 21:30:23 +00:00
|
|
|
|
2020-02-04 18:34:30 +00:00
|
|
|
struct FunctionInfo {
|
|
|
|
bool Exists = false;
|
|
|
|
asIScriptFunction* Function = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
FunctionInfo Initialize(const std::string& decl) {
|
|
|
|
auto val = _type->GetMethodByDecl(decl.c_str(), false);
|
2020-02-05 16:06:15 +00:00
|
|
|
if (val == nullptr) {
|
2020-02-04 18:34:30 +00:00
|
|
|
return FunctionInfo{.Exists = false, .Function = nullptr};
|
|
|
|
}
|
|
|
|
return FunctionInfo{.Exists = true, .Function = val};
|
|
|
|
}
|
|
|
|
|
2020-01-11 21:30:23 +00:00
|
|
|
public:
|
2020-07-04 13:50:30 +00:00
|
|
|
explicit AngelScriptTypeInfo(const ArbUt::StringView& name, asITypeInfo* type) : _type(type), _name(name) {}
|
|
|
|
|
2020-02-04 18:34:30 +00:00
|
|
|
~AngelScriptTypeInfo() {
|
|
|
|
for (const auto& f : _functions) {
|
2020-01-11 21:30:23 +00:00
|
|
|
f.second->Release();
|
|
|
|
}
|
2020-04-06 18:03:44 +00:00
|
|
|
_functions.Clear();
|
2020-01-11 21:30:23 +00:00
|
|
|
}
|
|
|
|
|
2020-07-04 13:50:30 +00:00
|
|
|
const ArbUt::StringView& GetName() const noexcept { return _name; }
|
2020-02-23 15:02:27 +00:00
|
|
|
|
2021-10-29 21:54:44 +00:00
|
|
|
inline asITypeInfo* GetType() const { return _type; }
|
|
|
|
inline const char* GetDecl() { return _type->GetName(); }
|
2020-04-11 12:42:49 +00:00
|
|
|
|
2020-07-04 13:50:30 +00:00
|
|
|
asIScriptFunction* GetFunction(const ArbUt::BasicStringView& functionName) {
|
2020-12-12 13:25:27 +00:00
|
|
|
auto v = _functions.TryGet(functionName);
|
|
|
|
if (v.has_value()) {
|
|
|
|
return v.value();
|
2020-01-11 21:30:23 +00:00
|
|
|
}
|
2020-12-12 13:25:27 +00:00
|
|
|
auto func = _type->GetMethodByName(functionName.c_str());
|
2020-02-04 18:34:30 +00:00
|
|
|
if (func != nullptr) {
|
2020-02-01 15:56:09 +00:00
|
|
|
func->AddRef();
|
|
|
|
}
|
2020-04-06 18:03:44 +00:00
|
|
|
_functions.Insert(functionName, func);
|
2020-01-11 21:30:23 +00:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2020-02-04 18:34:30 +00:00
|
|
|
asIScriptObject* Instantiate(asIScriptContext* ctx) {
|
2021-03-27 12:33:56 +00:00
|
|
|
auto* factory = _type->GetFactoryByIndex(0);
|
2020-01-11 21:30:23 +00:00
|
|
|
ctx->Prepare(factory);
|
|
|
|
auto result = ctx->Execute();
|
2020-02-04 18:34:30 +00:00
|
|
|
if (result != asEXECUTION_FINISHED) {
|
2020-08-16 09:12:04 +00:00
|
|
|
throw ArbUt::Exception("Instantiation failed.");
|
2020-01-11 21:30:23 +00:00
|
|
|
}
|
|
|
|
asIScriptObject* obj = *(asIScriptObject**)ctx->GetAddressOfReturnValue();
|
|
|
|
obj->AddRef();
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2020-02-05 16:06:15 +00:00
|
|
|
#define SCRIPT_HOOK_FUNCTION(name, decl) \
|
|
|
|
private: \
|
|
|
|
FunctionInfo __##name = Initialize(decl); \
|
|
|
|
\
|
|
|
|
public: \
|
|
|
|
const FunctionInfo& Get##name() const { return __##name; }
|
2020-02-04 18:34:30 +00:00
|
|
|
|
2021-10-29 21:54:44 +00:00
|
|
|
private:
|
2021-10-30 12:29:57 +00:00
|
|
|
FunctionInfo InitializeGetOwner() {
|
2021-10-29 21:54:44 +00:00
|
|
|
auto t = _type;
|
2021-10-30 12:29:57 +00:00
|
|
|
while (t != nullptr) {
|
2021-10-30 09:44:16 +00:00
|
|
|
auto val = t->GetMethodByDecl("ref@& GetOwner()", true);
|
2021-10-30 12:29:57 +00:00
|
|
|
if (val != nullptr) {
|
2021-10-29 21:54:44 +00:00
|
|
|
return FunctionInfo{.Exists = true, .Function = val};
|
|
|
|
}
|
|
|
|
t = t->GetBaseType();
|
|
|
|
}
|
|
|
|
return FunctionInfo{.Exists = false, .Function = nullptr};
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionInfo __GetOwner = InitializeGetOwner();
|
2021-10-30 12:29:57 +00:00
|
|
|
|
2021-10-29 21:54:44 +00:00
|
|
|
public:
|
|
|
|
const FunctionInfo& GetGetOwner() const { return __GetOwner; }
|
|
|
|
|
2022-02-12 16:27:39 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnInitialize,
|
|
|
|
"void OnInitialize(const BattleLibrary@ library, const narray<EffectParameter@>@ parameters)");
|
2020-02-05 16:06:15 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(Stack, "void Stack()");
|
2020-02-06 15:25:55 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnRemove, "void OnRemove()");
|
2020-04-28 12:48:56 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnBeforeTurn, "void OnBeforeTurn(BaseTurnChoice@ choice)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(ChangeAttack, "void ChangeAttack(MoveTurnChoice@ choice, constString& changedMove)");
|
2020-04-22 13:34:24 +00:00
|
|
|
|
2021-03-28 17:58:08 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(ModifyNumberOfHits, "void ModifyNumberOfHits(MoveTurnChoice@ choice, uint8& result)");
|
2020-02-05 16:06:15 +00:00
|
|
|
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)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(OnBeforeAttack, "void OnBeforeAttack(ExecutingMove@ attack)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(FailIncomingAttack,
|
|
|
|
"void FailIncomingAttack(ExecutingMove@ attack, Pokemon@ target, bool& result)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(IsInvulnerable, "void IsInvulnerable(ExecutingMove@ attack, Pokemon@ target, bool& result)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(OnAttackMiss, "void OnAttackMiss(ExecutingMove@ attack, Pokemon@ target)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(ChangeAttackType,
|
|
|
|
"void ChangeAttackType(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& outType)");
|
2020-04-19 11:41:41 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
ChangeEffectiveness,
|
|
|
|
"void ChangeEffectiveness(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& effectiveness)");
|
2021-11-21 09:55:54 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(BlockCritical,
|
|
|
|
"void BlockCritical(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& blockCritical)");
|
2022-02-12 14:59:16 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(PreventStatBoostChange,
|
|
|
|
"void PreventStatBoostChange(Pokemon@ target, Statistic stat, int8 amount, bool& prevent)");
|
2022-02-12 14:24:50 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(ModifyStatBoostChange,
|
|
|
|
"void ModifyStatBoostChange(Pokemon@ target, Statistic stat, int8& amount)");
|
2020-02-05 16:06:15 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
PreventSecondaryEffects,
|
|
|
|
"void PreventSecondaryEffects(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& outResult)");
|
2021-11-19 17:07:21 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnIncomingHit, "void OnIncomingHit(ExecutingMove@ attack, Pokemon@ target, uint8 hit)");
|
2021-11-21 12:37:26 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnFaintingOpponent,
|
|
|
|
"void OnFaintingOpponent(ExecutingMove@ attack, Pokemon@ target, uint8 hit)");
|
2020-02-05 16:06:15 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnSecondaryEffect,
|
|
|
|
"void OnSecondaryEffect(ExecutingMove@ attack, Pokemon@ target, uint8 hit)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(OnAfterHits, "void OnAfterHits(ExecutingMove@ attack, Pokemon@ target)");
|
2020-04-22 13:34:24 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(PreventSelfSwitch, "void PreventSelfSwitch(SwitchTurnChoice@ choice, bool& prevented)");
|
|
|
|
|
2020-02-16 14:21:58 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(ModifyEffectChance,
|
2020-02-17 09:55:42 +00:00
|
|
|
"void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance)");
|
2020-02-20 12:28:31 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(ModifyIncomingEffectChance,
|
|
|
|
"void ModifyIncomingEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance)");
|
2020-02-19 09:25:27 +00:00
|
|
|
|
2020-02-20 12:28:31 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OverrideBasePower,
|
|
|
|
"void OverrideBasePower(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& chance)");
|
|
|
|
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)");
|
|
|
|
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,
|
|
|
|
"void ModifyDamageModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& modifier)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(OverrideDamage,
|
|
|
|
"void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage)");
|
2021-10-29 16:29:30 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OverrideIncomingDamage,
|
|
|
|
"void OverrideIncomingDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage)");
|
2020-02-19 09:25:27 +00:00
|
|
|
|
2022-02-12 12:03:40 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
PreventIncomingCritical,
|
|
|
|
"void PreventIncomingCritical(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& preventCrit)");
|
2020-02-20 12:28:31 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
ModifyCriticalStage,
|
|
|
|
"void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage)");
|
2020-06-05 11:49:12 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
OverrideCriticalModifier,
|
|
|
|
"void OverrideCriticalModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& critModifier)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
OverrideSTABModifier,
|
|
|
|
"void OverrideSTABModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& stabModifier)");
|
2020-05-24 11:36:45 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(ModifyExperienceGain,
|
|
|
|
"void ModifyExperienceGain(Pokemon@ faintedMon, Pokemon@ winningMon, uint32& critStage)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(DoesShareExperience,
|
|
|
|
"void DoesShareExperience(Pokemon@ faintedMon, Pokemon@ winningMon, bool& shareExperience)");
|
2021-03-27 12:33:56 +00:00
|
|
|
|
|
|
|
SCRIPT_HOOK_FUNCTION(ChangePriority, "void ChangePriority(MoveTurnChoice@ choice, int8& priority)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(OnFail, "void OnFail(Pokemon@ user)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(OnOpponentFail, "void OnOpponentFail(Pokemon@ user)");
|
2021-03-27 14:34:04 +00:00
|
|
|
|
|
|
|
SCRIPT_HOOK_FUNCTION(PreventRunAway, "void PreventRunAway(FleeTurnChoice@ choice, bool& result)");
|
2021-03-28 14:54:41 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(PreventOpponentRunAway, "void PreventOpponentRunAway(FleeTurnChoice@ choice, bool& result)");
|
2021-03-28 16:53:08 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(PreventOpponentSwitch, "void PreventOpponentSwitch(SwitchTurnChoice@ choice, bool& result)");
|
|
|
|
|
2021-10-29 17:35:31 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnEndTurn, "void OnEndTurn()");
|
2021-11-21 13:16:57 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnDamage,
|
|
|
|
"void OnDamage(Pokemon@ pokemon, DamageSource damageSource, uint oldHealth, uint newHealth)");
|
2021-11-19 11:40:31 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnFaint, "void OnFaint(Pokemon@ pokemon, DamageSource damageSource)");
|
2021-11-19 14:06:13 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(BlockWeather, "void BlockWeather(Battle@ battle, bool& result)");
|
2021-11-19 14:55:48 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(OnSwitchIn, "void OnSwitchIn(Pokemon@ pokemon)");
|
2022-02-12 16:00:37 +00:00
|
|
|
|
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
ModifyOffensiveStatValue,
|
|
|
|
"void ModifyOffensiveStatValue(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& offensiveStatValue)");
|
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
ModifyDefensiveStatValue,
|
|
|
|
"void ModifyDefensiveStatValue(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& defensiveStatValue)");
|
2022-02-19 13:04:43 +00:00
|
|
|
SCRIPT_HOOK_FUNCTION(
|
|
|
|
OnAfterHeldItemConsume,
|
|
|
|
"void OnAfterHeldItemConsume(Pokemon@ target, const Item@ item)");
|
2020-01-11 21:30:23 +00:00
|
|
|
};
|
|
|
|
|
2020-02-04 18:34:30 +00:00
|
|
|
#undef SCRIPT_HOOK_FUNCTION
|
2020-01-11 21:30:23 +00:00
|
|
|
#endif // PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|