Reworks setting script owner to something a lot more clean
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -19,15 +19,26 @@ AngelScriptScript::AngelScriptScript(const ArbUt::OptionalBorrowedPtr<void>& own
|
||||
AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,
|
||||
ContextPool* ctxPool)
|
||||
: PkmnLib::Battling::PkmnScript(owner), _resolver(resolver), _type(type), _ctxPool(ctxPool), _obj(obj) {
|
||||
if (_type->GetGetOwner().Exists && owner.HasValue()) {
|
||||
if (_type->GetSetOwner().Exists && owner.HasValue()) {
|
||||
if (ownerType == nullptr) {
|
||||
THROW("Script was created with owner value, but with unknown owner type.")
|
||||
}
|
||||
auto* handle = GetAngelscriptOwner();
|
||||
handle->Set(owner.GetValue(), ownerType);
|
||||
_ownerHandle = new CScriptHandle(owner.GetValue(), ownerType);
|
||||
SetAngelscriptOwner(_ownerHandle);
|
||||
}
|
||||
}
|
||||
|
||||
CreatureLib::Battling::BattleScript* AngelScriptScript::Clone(const ArbUt::OptionalBorrowedPtr<void>& owner) {
|
||||
auto* ctx = _ctxPool->RequestContext();
|
||||
auto* obj = _type->Instantiate(ctx);
|
||||
if (_obj != nullptr) {
|
||||
obj->CopyFrom(_obj);
|
||||
}
|
||||
_ctxPool->ReturnContextToPool(ctx);
|
||||
|
||||
return new AngelScriptScript(owner, GetAngelscriptOwner()->GetType(), _resolver, _type, obj, _ctxPool);
|
||||
}
|
||||
|
||||
CScriptHandle* AngelScriptScript::GetAngelscriptOwner() {
|
||||
CScriptHandle* handle = nullptr;
|
||||
AngelScriptUtils::AngelscriptFunctionCall(
|
||||
@@ -36,6 +47,20 @@ CScriptHandle* AngelScriptScript::GetAngelscriptOwner() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
void AngelScriptScript::SetAngelscriptOwner(CScriptHandle* owner) {
|
||||
AngelScriptUtils::AngelscriptFunctionCall(
|
||||
_type->GetSetOwner().Function, _ctxPool, _obj, _resolver, GetName(),
|
||||
[&](asIScriptContext* ctx) { ctx->SetArgObject(0, owner); }, [&](asIScriptContext*) {});
|
||||
}
|
||||
|
||||
AngelScriptScript::~AngelScriptScript() {
|
||||
if (_ownerHandle != nullptr){
|
||||
delete _ownerHandle;
|
||||
}
|
||||
_obj->Release();
|
||||
}
|
||||
|
||||
|
||||
void AngelScriptScript::OnInitialize(const CreatureLib::Battling::BattleLibrary* library,
|
||||
const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
|
||||
CALL_HOOK(OnInitialize, {
|
||||
@@ -356,23 +381,13 @@ void AngelScriptScript::PreventOpponentSwitch(const CreatureLib::Battling::Switc
|
||||
})
|
||||
}
|
||||
void AngelScriptScript::OnEndTurn() { CALL_HOOK(OnEndTurn, {}) }
|
||||
void AngelScriptScript::ModifyNumberOfHits(CreatureLib::Battling::AttackTurnChoice* choice,
|
||||
u8* numberOfHits){CALL_HOOK(ModifyNumberOfHits,
|
||||
{
|
||||
ctx->SetArgObject(0, (void*)choice);
|
||||
ctx->SetArgAddress(1, numberOfHits);
|
||||
})}
|
||||
|
||||
CreatureLib::Battling::BattleScript* AngelScriptScript::Clone(const ArbUt::OptionalBorrowedPtr<void>& owner) {
|
||||
auto* ctx = _ctxPool->RequestContext();
|
||||
auto* obj = _type->Instantiate(ctx);
|
||||
if (_obj != nullptr) {
|
||||
obj->CopyFrom(_obj);
|
||||
}
|
||||
_ctxPool->ReturnContextToPool(ctx);
|
||||
|
||||
return new AngelScriptScript(owner, GetAngelscriptOwner()->GetType(), _resolver, _type, obj, _ctxPool);
|
||||
void AngelScriptScript::ModifyNumberOfHits(CreatureLib::Battling::AttackTurnChoice* choice, u8* numberOfHits) {
|
||||
CALL_HOOK(ModifyNumberOfHits, {
|
||||
ctx->SetArgObject(0, (void*)choice);
|
||||
ctx->SetArgAddress(1, numberOfHits);
|
||||
})
|
||||
}
|
||||
|
||||
void AngelScriptScript::OnDamage(CreatureLib::Battling::Creature* creature, CreatureLib::Battling::DamageSource source,
|
||||
[[maybe_unused]] u32 oldHealth, [[maybe_unused]] u32 newHealth) {
|
||||
CALL_HOOK(OnDamage, {
|
||||
|
||||
Reference in New Issue
Block a user