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( \
|
2021-09-22 17:02:01 +00:00
|
|
|
s.Function, _ctxPool, _obj, _resolver, GetName(), [&]([[maybe_unused]] asIScriptContext* ctx) { setup }, \
|
2021-03-07 16:09:30 +00:00
|
|
|
[&]([[maybe_unused]] asIScriptContext* ctx) {});
|
2020-04-23 22:02:10 +00:00
|
|
|
|
2021-09-25 15:56:31 +00:00
|
|
|
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
|
|
|
|
AngelScriptScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
|
|
|
|
return new NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>(&ls);
|
2020-04-23 22:02:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 21:54:44 +00:00
|
|
|
AngelScriptScript::AngelScriptScript(const ArbUt::OptionalBorrowedPtr<void>& owner, asITypeInfo* ownerType,
|
|
|
|
AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,
|
|
|
|
ContextPool* ctxPool)
|
|
|
|
: PkmnLib::Battling::PkmnScript(owner), _resolver(resolver), _type(type), _ctxPool(ctxPool), _obj(obj) {
|
|
|
|
if (_type->GetGetOwner().Exists) {
|
|
|
|
CScriptHandle* handle = nullptr;
|
|
|
|
AngelScriptUtils::AngelscriptFunctionCall(
|
|
|
|
_type->GetGetOwner().Function, _ctxPool, _obj, _resolver, GetName(), [&](asIScriptContext*) {},
|
|
|
|
[&](asIScriptContext* ctx) { handle = (CScriptHandle*)ctx->GetReturnObject(); });
|
|
|
|
handle->Set(owner.GetValue(), ownerType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CScriptHandle* AngelScriptScript::GetAngelscriptOwner() {
|
|
|
|
CScriptHandle* handle = nullptr;
|
|
|
|
AngelScriptUtils::AngelscriptFunctionCall(
|
|
|
|
_type->GetGetOwner().Function, _ctxPool, _obj, _resolver, GetName(), [&](asIScriptContext*) {},
|
|
|
|
[&](asIScriptContext* ctx) { handle = (CScriptHandle*)ctx->GetReturnObject(); });
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
CALL_HOOK(OnInitialize, {
|
2021-09-25 15:56:31 +00:00
|
|
|
auto arr = GetEffectParameters(parameters);
|
2020-04-23 22:02:10 +00:00
|
|
|
ctx->SetArgAddress(0, arr);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
})
|
|
|
|
}
|
2021-10-29 16:29:30 +00:00
|
|
|
void AngelScriptScript::OverrideIncomingDamage(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
|
|
|
uint32_t* damage) {
|
|
|
|
CALL_HOOK(OverrideIncomingDamage, {
|
|
|
|
ctx->SetArgObject(0, (void*)attack);
|
|
|
|
ctx->SetArgObject(1, (void*)target);
|
|
|
|
ctx->SetArgByte(2, hitIndex);
|
|
|
|
ctx->SetArgAddress(3, damage);
|
|
|
|
})
|
|
|
|
}
|
2020-04-23 22:02:10 +00:00
|
|
|
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);
|
|
|
|
})
|
|
|
|
}
|
2021-10-29 17:35:31 +00:00
|
|
|
void AngelScriptScript::OnEndTurn() { CALL_HOOK(OnEndTurn, {}) }
|
2021-04-11 14:27:21 +00:00
|
|
|
void AngelScriptScript::ModifyNumberOfHits(CreatureLib::Battling::AttackTurnChoice* choice,
|
|
|
|
u8* numberOfHits){CALL_HOOK(ModifyNumberOfHits,
|
|
|
|
{
|
|
|
|
ctx->SetArgObject(0, (void*)choice);
|
|
|
|
ctx->SetArgAddress(1, numberOfHits);
|
|
|
|
})}
|
|
|
|
|
2021-10-29 21:54:44 +00:00
|
|
|
CreatureLib::Battling::BattleScript* AngelScriptScript::Clone(const ArbUt::OptionalBorrowedPtr<void>& owner) {
|
2021-04-11 14:27:21 +00:00
|
|
|
auto* ctx = _ctxPool->RequestContext();
|
|
|
|
auto* obj = _type->Instantiate(ctx);
|
2021-04-11 15:50:47 +00:00
|
|
|
if (_obj != nullptr) {
|
2021-04-11 14:27:21 +00:00
|
|
|
obj->CopyFrom(_obj);
|
|
|
|
}
|
|
|
|
_ctxPool->ReturnContextToPool(ctx);
|
2021-10-29 21:54:44 +00:00
|
|
|
|
|
|
|
return new AngelScriptScript(owner, GetAngelscriptOwner()->GetType(), _resolver, _type, obj, _ctxPool);
|
2021-03-28 17:58:08 +00:00
|
|
|
}
|