2020-01-09 16:03:34 +00:00
|
|
|
#ifndef PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
|
|
|
#define PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
2021-03-07 10:12:18 +00:00
|
|
|
#include <CreatureLib/Battling/ScriptHandling/BattleScript.hpp>
|
2021-10-29 21:54:44 +00:00
|
|
|
#include <CreatureLib/Battling/ScriptHandling/ScriptCategory.hpp>
|
2020-01-12 17:20:59 +00:00
|
|
|
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
2020-02-05 16:06:15 +00:00
|
|
|
#include <angelscript.h>
|
2022-02-11 11:17:27 +00:00
|
|
|
#include <scriptarray/scriptarray.h>
|
|
|
|
#include <scripthandle/scripthandle.h>
|
2020-02-20 12:28:31 +00:00
|
|
|
#include "../../Battling/PkmnScript.hpp"
|
2020-01-11 21:30:23 +00:00
|
|
|
#include "AngelScriptTypeInfo.hpp"
|
2021-09-25 15:56:31 +00:00
|
|
|
#include "TypeRegistry/NativeArray.hpp"
|
2020-01-09 16:03:34 +00:00
|
|
|
|
2020-04-23 22:05:43 +00:00
|
|
|
class AngelScriptResolver;
|
2021-09-22 17:02:01 +00:00
|
|
|
class ContextPool;
|
|
|
|
|
2020-10-15 16:13:00 +00:00
|
|
|
class AngelScriptScript final : public PkmnLib::Battling::PkmnScript {
|
2020-01-11 21:30:23 +00:00
|
|
|
private:
|
2020-04-23 22:05:43 +00:00
|
|
|
AngelScriptResolver* _resolver = nullptr;
|
2020-01-11 21:30:23 +00:00
|
|
|
AngelScriptTypeInfo* _type = nullptr;
|
|
|
|
ContextPool* _ctxPool = nullptr;
|
|
|
|
|
|
|
|
asIScriptObject* _obj = nullptr;
|
2021-09-25 15:56:31 +00:00
|
|
|
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
|
|
|
|
GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
|
2020-04-28 12:48:56 +00:00
|
|
|
|
2020-01-11 21:30:23 +00:00
|
|
|
public:
|
2021-10-29 21:54:44 +00:00
|
|
|
AngelScriptScript(const ArbUt::OptionalBorrowedPtr<void>& owner, asITypeInfo* ownerType,
|
|
|
|
AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,
|
|
|
|
ContextPool* ctxPool);
|
2020-01-11 21:30:23 +00:00
|
|
|
|
|
|
|
~AngelScriptScript() override { _obj->Release(); }
|
|
|
|
|
2021-10-29 21:54:44 +00:00
|
|
|
BattleScript* Clone(const ArbUt::OptionalBorrowedPtr<void>& owner) override;
|
2021-04-11 14:27:21 +00:00
|
|
|
|
2021-03-27 21:19:18 +00:00
|
|
|
inline asIScriptObject* GetRawAngelscriptObject() const noexcept { return _obj; }
|
|
|
|
|
2020-07-04 13:50:30 +00:00
|
|
|
[[nodiscard]] const ArbUt::StringView& GetName() const noexcept override { return _type->GetName(); }
|
2021-01-22 13:11:03 +00:00
|
|
|
const AngelScriptTypeInfo* GetType() const noexcept { return _type; }
|
2020-02-23 15:02:27 +00:00
|
|
|
|
2020-07-04 13:50:30 +00:00
|
|
|
asIScriptFunction* PrepareMethod(const ArbUt::BasicStringView& name, asIScriptContext* ctx) {
|
2020-01-11 21:30:23 +00:00
|
|
|
auto func = _type->GetFunction(name);
|
|
|
|
ctx->Prepare(func);
|
|
|
|
ctx->SetObject(_obj);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2020-01-12 17:20:59 +00:00
|
|
|
ContextPool* GetContextPool() { return _ctxPool; }
|
2020-02-04 18:34:30 +00:00
|
|
|
|
2021-10-29 21:54:44 +00:00
|
|
|
CScriptHandle* GetAngelscriptOwner();
|
2022-02-12 16:27:39 +00:00
|
|
|
void OnInitialize(const CreatureLib::Battling::BattleLibrary*,
|
|
|
|
const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) override;
|
2020-04-23 22:02:10 +00:00
|
|
|
void Stack() override;
|
2020-02-06 15:25:55 +00:00
|
|
|
|
2020-04-23 22:02:10 +00:00
|
|
|
void OnRemove() override;
|
2020-02-04 18:34:30 +00:00
|
|
|
|
2020-04-23 22:02:10 +00:00
|
|
|
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override;
|
2020-02-04 18:34:30 +00:00
|
|
|
|
2020-07-04 13:50:30 +00:00
|
|
|
void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ArbUt::StringView* outAttack) override;
|
2020-02-04 18:34:30 +00:00
|
|
|
|
2021-03-28 17:58:08 +00:00
|
|
|
void ModifyNumberOfHits(CreatureLib::Battling::AttackTurnChoice* choice, u8* numberOfHits) override;
|
2020-04-23 22:02:10 +00:00
|
|
|
void PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override;
|
2020-02-04 18:34:30 +00:00
|
|
|
|
2020-04-23 22:02:10 +00:00
|
|
|
void FailAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outFailed) override;
|
2020-02-04 18:34:30 +00:00
|
|
|
|
2020-04-23 22:02:10 +00:00
|
|
|
void StopBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override;
|
2020-02-04 18:34:30 +00:00
|
|
|
|
2020-04-23 22:02:10 +00:00
|
|
|
void OnBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack) override;
|
2020-02-05 16:06:15 +00:00
|
|
|
|
2020-02-04 18:34:30 +00:00
|
|
|
void FailIncomingAttack(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
bool* outResult) override;
|
2020-02-04 18:34:30 +00:00
|
|
|
void IsInvulnerable(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
bool* outResult) override;
|
|
|
|
void OnAttackMiss(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target) override;
|
2020-02-05 16:06:15 +00:00
|
|
|
|
2020-02-04 18:34:30 +00:00
|
|
|
void ChangeAttackType(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitNumber, uint8_t* outType) override;
|
2020-02-05 16:06:15 +00:00
|
|
|
|
2021-11-21 09:55:54 +00:00
|
|
|
void BlockCritical(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2021-11-21 13:16:57 +00:00
|
|
|
uint8_t hitNumber, bool* blockCritical) override;
|
2020-04-19 11:41:41 +00:00
|
|
|
void ChangeEffectiveness(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitNumber, float* effectiveness) override;
|
2020-04-19 11:41:41 +00:00
|
|
|
|
2022-02-12 14:59:16 +00:00
|
|
|
void PreventStatBoostChange(CreatureLib::Battling::Creature* target, CreatureLib::Library::Statistic stat,
|
|
|
|
int8_t diffAmount, bool* prevent) override;
|
2022-02-12 14:24:50 +00:00
|
|
|
void ModifyStatBoostChange(CreatureLib::Battling::Creature* target, CreatureLib::Library::Statistic stat,
|
|
|
|
int8_t* diffAmount) override;
|
2020-02-04 18:34:30 +00:00
|
|
|
void PreventSecondaryEffects(const CreatureLib::Battling::ExecutingAttack* attack,
|
2020-04-23 22:02:10 +00:00
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber, bool* outResult) override;
|
2020-02-05 16:06:15 +00:00
|
|
|
|
2021-11-21 13:16:57 +00:00
|
|
|
void OnIncomingHit(const CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
|
|
|
uint8_t hitNumber) override;
|
2021-11-21 12:37:26 +00:00
|
|
|
void OnFaintingOpponent(const CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, u8 hitNumber) override;
|
2020-02-04 18:34:30 +00:00
|
|
|
void OnSecondaryEffect(const CreatureLib::Battling::ExecutingAttack* attack,
|
2020-04-23 22:02:10 +00:00
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber) override;
|
2020-02-05 16:06:15 +00:00
|
|
|
|
2020-02-04 18:34:30 +00:00
|
|
|
void OnAfterHits(const CreatureLib::Battling::ExecutingAttack* attack,
|
2020-04-23 22:02:10 +00:00
|
|
|
CreatureLib::Battling::Creature* target) override;
|
2020-02-05 16:06:15 +00:00
|
|
|
|
2020-04-23 22:02:10 +00:00
|
|
|
void PreventSelfSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) override;
|
2020-02-16 14:21:58 +00:00
|
|
|
|
|
|
|
void ModifyEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
2020-04-23 22:02:10 +00:00
|
|
|
CreatureLib::Battling::Creature* target, float* chance) override;
|
2020-02-16 14:21:58 +00:00
|
|
|
void ModifyIncomingEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
2020-04-23 22:02:10 +00:00
|
|
|
CreatureLib::Battling::Creature* target, float* chance) override;
|
2020-02-19 09:25:27 +00:00
|
|
|
|
|
|
|
void OverrideBasePower(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitIndex, uint8_t* basePower) override;
|
2020-02-19 09:25:27 +00:00
|
|
|
void ChangeDamageStatsUser(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitIndex, CreatureLib::Battling::Creature** statsUser) override;
|
2020-02-19 09:25:27 +00:00
|
|
|
void BypassDefensiveStat(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitIndex, bool* bypass) override;
|
2020-02-19 09:25:27 +00:00
|
|
|
void BypassOffensiveStat(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitIndex, bool* bypass) override;
|
2020-02-19 09:25:27 +00:00
|
|
|
void ModifyStatModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitIndex, float* modifier) override;
|
2020-02-19 09:25:27 +00:00
|
|
|
void ModifyDamageModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitIndex, float* modifier) override;
|
2020-02-19 09:25:27 +00:00
|
|
|
void OverrideDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hitIndex, uint32_t* damage) override;
|
2021-10-29 16:29:30 +00:00
|
|
|
void OverrideIncomingDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
|
|
|
uint8_t hitIndex, uint32_t* damage) override;
|
2020-02-20 12:28:31 +00:00
|
|
|
|
2021-03-27 12:33:56 +00:00
|
|
|
void ChangePriority(CreatureLib::Battling::AttackTurnChoice* choice, int8_t* priority) override;
|
|
|
|
void OnFail(CreatureLib::Battling::Creature* target) override;
|
|
|
|
void OnOpponentFail(CreatureLib::Battling::Creature* target) override;
|
|
|
|
|
2021-03-27 14:34:04 +00:00
|
|
|
void PreventRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) override;
|
|
|
|
void PreventOpponentRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) override;
|
2021-03-28 16:53:08 +00:00
|
|
|
void PreventOpponentSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) override;
|
2021-10-29 17:35:31 +00:00
|
|
|
void OnEndTurn() override;
|
2021-11-21 13:16:57 +00:00
|
|
|
void OnDamage(CreatureLib::Battling::Creature* creature, CreatureLib::Battling::DamageSource source,
|
|
|
|
[[maybe_unused]] u32 oldHealth, [[maybe_unused]] u32 newHealth) override;
|
2021-11-19 17:07:21 +00:00
|
|
|
void OnFaint(CreatureLib::Battling::Creature* creature, CreatureLib::Battling::DamageSource source) override;
|
|
|
|
void OnSwitchIn(CreatureLib::Battling::Creature* creature) override;
|
2022-02-19 13:04:43 +00:00
|
|
|
void OnAfterHeldItemConsume(CreatureLib::Battling::Creature* creature,
|
|
|
|
const CreatureLib::Library::Item* item) override;
|
2021-03-27 14:34:04 +00:00
|
|
|
|
2020-02-20 12:28:31 +00:00
|
|
|
////////////////////
|
|
|
|
// PkmnLib methods//
|
|
|
|
////////////////////
|
|
|
|
|
2022-02-12 12:03:40 +00:00
|
|
|
void PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hit, bool* preventCrit) override;
|
2020-02-20 12:28:31 +00:00
|
|
|
void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
2020-04-23 22:02:10 +00:00
|
|
|
uint8_t hit, uint8_t* critStage) override;
|
2020-06-05 11:49:12 +00:00
|
|
|
void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, uint8_t hit, float* critModifier) override;
|
|
|
|
void OverrideSTABModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
|
|
|
uint8_t hit, float* stabModifier) override;
|
2020-05-24 11:36:45 +00:00
|
|
|
|
|
|
|
void ModifyExperienceGain(CreatureLib::Battling::Creature* faintedMon, CreatureLib::Battling::Creature* winningMon,
|
|
|
|
uint32_t* experienceGain) override;
|
|
|
|
void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon, CreatureLib::Battling::Creature* winningMon,
|
|
|
|
bool* shareExperience) override;
|
2021-11-19 11:40:31 +00:00
|
|
|
|
2021-11-19 14:06:13 +00:00
|
|
|
void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather) override;
|
2022-02-12 16:00:37 +00:00
|
|
|
|
|
|
|
void ModifyOffensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier) override;
|
|
|
|
void ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
|
|
|
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier) override;
|
2020-01-11 21:30:23 +00:00
|
|
|
};
|
2020-01-09 16:03:34 +00:00
|
|
|
|
2020-02-08 09:22:18 +00:00
|
|
|
#undef CALL_HOOK
|
2020-01-09 16:03:34 +00:00
|
|
|
#endif // PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|