2020-01-09 16:03:34 +00:00
|
|
|
#include "AngelScriptScript.hpp"
|
2021-03-07 16:09:30 +00:00
|
|
|
#include "AngelScriptFunctionCall.hpp"
|
2020-04-23 22:05:43 +00:00
|
|
|
#include "AngelScriptResolver.hpp"
|
2020-04-23 22:02:10 +00:00
|
|
|
|
|
|
|
#define CALL_HOOK(name, setup) \
|
|
|
|
auto s = _type->Get##name(); \
|
|
|
|
if (!s.Exists) \
|
|
|
|
return; \
|
2021-03-07 16:09:30 +00:00
|
|
|
AngelScriptUtils::AngelscriptFunctionCall( \
|
|
|
|
s.Function, _ctxPool, _obj, GetName(), [&]([[maybe_unused]] asIScriptContext* ctx) { setup }, \
|
|
|
|
[&]([[maybe_unused]] asIScriptContext* ctx) {});
|
2020-04-23 22:02:10 +00:00
|
|
|
|
2020-05-27 15:26:25 +00:00
|
|
|
CScriptArray* AngelScriptScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
|
2020-04-23 22:02:10 +00:00
|
|
|
asITypeInfo* t = _resolver->GetBaseType("array<EffectParameter@>"_cnc);
|
|
|
|
CScriptArray* arr = CScriptArray::Create(t, ls.Count());
|
|
|
|
for (size_t i = 0; i < ls.Count(); i++) {
|
|
|
|
arr->SetValue(i, (void**)&ls[i]);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2020-05-27 15:26:25 +00:00
|
|
|
void AngelScriptScript::OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
|
2020-04-23 22:02:10 +00:00
|
|
|
CScriptArray* arr = nullptr;
|
|
|
|
CALL_HOOK(OnInitialize, {
|
|
|
|
arr = GetEffectParameters(parameters);
|
|
|
|
ctx->SetArgAddress(0, arr);
|
|
|
|
})
|
|
|
|
if (arr != nullptr) {
|
|
|
|
arr->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void AngelScriptScript::Stack() { CALL_HOOK(Stack, ); }
|
|
|
|
void AngelScriptScript::OnRemove() { CALL_HOOK(OnRemove, ); }
|
|
|
|
void AngelScriptScript::OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) {
|
|
|
|
CALL_HOOK(OnBeforeTurn, { ctx->SetArgObject(0, (void*)choice); })
|
|
|
|
}
|
2020-07-04 13:50:30 +00:00
|
|
|
void AngelScriptScript::ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ArbUt::StringView* outAttack) {
|
2020-04-23 22:02:10 +00:00
|
|
|
CALL_HOOK(ChangeAttack, {
|
|
|
|
ctx->SetArgObject(0, (void*)choice);
|
|
|
|
ctx->SetArgAddress(0, outAttack);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) {
|
|
|
|
CALL_HOOK(PreventAttack, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgAddress(1, outResult);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::FailAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outFailed) {
|
|
|
|
CALL_HOOK(FailAttack, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgAddress(1, outFailed);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::StopBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) {
|
|
|
|
CALL_HOOK(StopBeforeAttack, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgAddress(1, outResult);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OnBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack) {
|
|
|
|
CALL_HOOK(OnBeforeAttack, { ctx->SetArgObject(0, (void*)attack); })
|
|
|
|
}
|
|
|
|
void AngelScriptScript::FailIncomingAttack(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, bool* outResult) {
|
|
|
|
CALL_HOOK(FailIncomingAttack, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgAddress(2, outResult);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::IsInvulnerable(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, bool* outResult) {
|
|
|
|
CALL_HOOK(IsInvulnerable, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgAddress(2, outResult);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OnAttackMiss(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target) {
|
|
|
|
CALL_HOOK(OnAttackMiss, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::ChangeAttackType(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber, uint8_t* outType) {
|
|
|
|
CALL_HOOK(ChangeAttackType, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitNumber);
|
|
|
|
ctx->SetArgAddress(3, outType);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::ChangeEffectiveness(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber,
|
|
|
|
float* effectiveness) {
|
|
|
|
CALL_HOOK(ChangeEffectiveness, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitNumber);
|
|
|
|
ctx->SetArgAddress(3, effectiveness);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::PreventSecondaryEffects(const CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber,
|
|
|
|
bool* outResult) {
|
|
|
|
CALL_HOOK(PreventSecondaryEffects, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitNumber);
|
|
|
|
ctx->SetArgAddress(3, outResult);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OnSecondaryEffect(const CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber) {
|
|
|
|
CALL_HOOK(OnSecondaryEffect, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitNumber);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OnAfterHits(const CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target) {
|
|
|
|
CALL_HOOK(OnAfterHits, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::PreventSelfSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) {
|
|
|
|
CALL_HOOK(PreventSelfSwitch, {
|
|
|
|
ctx->SetArgObject(0, (void*)choice);
|
|
|
|
ctx->SetArgAddress(1, outResult);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::ModifyEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, float* chance) {
|
|
|
|
CALL_HOOK(ModifyEffectChance, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgAddress(2, chance);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::ModifyIncomingEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, float* chance) {
|
|
|
|
CALL_HOOK(ModifyIncomingEffectChance, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgAddress(2, chance);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OverrideBasePower(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
|
|
|
uint8_t* basePower) {
|
|
|
|
CALL_HOOK(OverrideBasePower, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitIndex);
|
|
|
|
ctx->SetArgAddress(3, basePower);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::ChangeDamageStatsUser(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
|
|
|
CreatureLib::Battling::Creature** statsUser) {
|
|
|
|
CALL_HOOK(ChangeDamageStatsUser, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitIndex);
|
|
|
|
ctx->SetArgAddress(3, statsUser);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::BypassDefensiveStat(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex, bool* bypass) {
|
|
|
|
CALL_HOOK(BypassDefensiveStat, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitIndex);
|
|
|
|
ctx->SetArgAddress(3, bypass);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::BypassOffensiveStat(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex, bool* bypass) {
|
|
|
|
CALL_HOOK(BypassOffensiveStat, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitIndex);
|
|
|
|
ctx->SetArgAddress(3, bypass);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::ModifyStatModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex, float* modifier) {
|
|
|
|
CALL_HOOK(ModifyStatModifier, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitIndex);
|
|
|
|
ctx->SetArgAddress(3, modifier);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::ModifyDamageModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
|
|
|
float* modifier) {
|
|
|
|
CALL_HOOK(ModifyDamageModifier, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitIndex);
|
|
|
|
ctx->SetArgAddress(3, modifier);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OverrideDamage(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex, uint32_t* damage) {
|
|
|
|
CALL_HOOK(OverrideDamage, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitIndex);
|
|
|
|
ctx->SetArgAddress(3, damage);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage) {
|
|
|
|
CALL_HOOK(ModifyCriticalStage, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hit);
|
|
|
|
ctx->SetArgAddress(3, critStage);
|
|
|
|
})
|
|
|
|
}
|
2020-05-24 11:36:45 +00:00
|
|
|
void AngelScriptScript::ModifyExperienceGain(CreatureLib::Battling::Creature* faintedMon,
|
|
|
|
CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain) {
|
|
|
|
CALL_HOOK(ModifyExperienceGain, {
|
|
|
|
ctx->SetArgObject(0, (void*)faintedMon);
|
|
|
|
ctx->SetArgObject(1, (void*)winningMon);
|
|
|
|
ctx->SetArgAddress(2, experienceGain);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::DoesShareExperience(CreatureLib::Battling::Creature* faintedMon,
|
|
|
|
CreatureLib::Battling::Creature* winningMon, bool* shareExperience) {
|
|
|
|
CALL_HOOK(DoesShareExperience, {
|
|
|
|
ctx->SetArgObject(0, (void*)faintedMon);
|
|
|
|
ctx->SetArgObject(1, (void*)winningMon);
|
|
|
|
ctx->SetArgAddress(2, shareExperience);
|
|
|
|
})
|
|
|
|
}
|
2020-06-05 11:49:12 +00:00
|
|
|
void AngelScriptScript::OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hit,
|
|
|
|
float* critModifier) {
|
|
|
|
CALL_HOOK(OverrideCriticalModifier, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hit);
|
|
|
|
ctx->SetArgAddress(3, critModifier);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OverrideSTABModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hit,
|
|
|
|
float* stabModifier) {
|
|
|
|
CALL_HOOK(OverrideSTABModifier, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hit);
|
|
|
|
ctx->SetArgAddress(3, stabModifier);
|
|
|
|
})
|
|
|
|
}
|
2021-03-27 12:33:56 +00:00
|
|
|
void AngelScriptScript::ChangePriority(CreatureLib::Battling::AttackTurnChoice* choice, int8_t* priority) {
|
|
|
|
CALL_HOOK(ChangePriority, {
|
|
|
|
ctx->SetArgObject(0, (void*)choice);
|
|
|
|
ctx->SetArgAddress(1, priority);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OnFail(CreatureLib::Battling::Creature* target) {
|
2021-03-27 12:46:34 +00:00
|
|
|
CALL_HOOK(OnFail, { ctx->SetArgObject(0, (void*)target); })
|
2021-03-27 12:33:56 +00:00
|
|
|
}
|
|
|
|
void AngelScriptScript::OnOpponentFail(CreatureLib::Battling::Creature* target) {
|
2021-03-27 12:46:34 +00:00
|
|
|
CALL_HOOK(OnOpponentFail, { ctx->SetArgObject(0, (void*)target); })
|
2021-03-27 12:33:56 +00:00
|
|
|
}
|
2021-03-27 14:34:04 +00:00
|
|
|
void AngelScriptScript::PreventRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) {
|
|
|
|
CALL_HOOK(PreventRunAway, {
|
|
|
|
ctx->SetArgObject(0, (void*)choice);
|
|
|
|
ctx->SetArgAddress(1, result);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::PreventOpponentRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) {
|
|
|
|
CALL_HOOK(PreventOpponentRunAway, {
|
|
|
|
ctx->SetArgObject(0, (void*)choice);
|
|
|
|
ctx->SetArgAddress(1, result);
|
|
|
|
})
|
|
|
|
}
|
2021-03-28 16:53:08 +00:00
|
|
|
void AngelScriptScript::PreventOpponentSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) {
|
|
|
|
CALL_HOOK(PreventOpponentSwitch, {
|
|
|
|
ctx->SetArgObject(0, (void*)choice);
|
|
|
|
ctx->SetArgAddress(1, outResult);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
void AngelScriptScript::OnEndTurn(CreatureLib::Battling::Creature* creature) {
|
|
|
|
CALL_HOOK(OnEndTurn, { ctx->SetArgObject(0, (void*)creature); })
|
|
|
|
}
|