Adds Angelscript registration for AttemptCapture
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-03-27 13:18:39 +02:00
parent c0e7f905a9
commit da5fe90601
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 9 additions and 4 deletions

View File

@ -80,10 +80,10 @@ shared abstract class PkmnScript {
Ensure(r >= 0);
r = engine->GetModuleByIndex(0)->AddScriptSection("ItemUseScript", R"(
shared abstract class ItemUseScript {
private Item@ __owner;
private const Item@ __owner;
protected const Item@ GetOwner() { return __owner; };
protected void SetOwner(Item@ o) { @__owner = @o; };
protected void SetOwner(const Item@ o) { @__owner = @o; };
void OnInitialize(const narray<EffectParameter@>@ parameters){};
bool IsItemUsable() { return false; };

View File

@ -74,10 +74,12 @@ static size_t GetTypesLengthWrapper(PkmnLib::Battling::Pokemon* p) { return p->G
static uint8_t GetTypeWrapper(PkmnLib::Battling::Pokemon* p, size_t index) { return p->GetTypes()[index]; }
#if defined(__clang__)
// Angelscript aligns this wrong (aligned on 4 bytes, wants 8). While this is a slight performance hit, we can ignore it for now.
// Angelscript aligns this wrong (aligned on 4 bytes, wants 8). While this is a slight performance hit, we can ignore it
// for now.
[[clang::no_sanitize("alignment")]]
#endif
static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& name) {
static CScriptHandle
AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& name) {
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
auto* script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
@ -213,6 +215,9 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
"Pokemon", "void ChangeForme(const constString &in name)",
asMETHODPR(PkmnLib::Battling::Pokemon, ChangeVariant, (const ArbUt::StringView&), void), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void AttemptCapture(const Item@ item)",
asMETHOD(PkmnLib::Battling::Pokemon, AttemptCapture), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("TypeLibrary",
"float GetEffectiveness(uint8 attackingType, Pokemon@ defender) const",