From 4d1b3448ba9c8aba8d44b6f73e39ab1cee48bba3 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 20 Nov 2021 11:06:39 +0100 Subject: [PATCH] Adds angelscript helper function to check if Pokemon has a type by the types string name. --- .../TypeRegistry/Battling/RegisterPokemonClass.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index 206af98..2b92793 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -81,6 +81,11 @@ static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const A return handle; } +static bool HasTypeStringWrapper(PkmnLib::Battling::Pokemon* p, const ArbUt::StringView& sv) { + auto typeId = p->GetLibrary()->GetTypeLibrary()->GetTypeId(sv); + return p->HasType(typeId); +} + static float GetEffectivenessHelper(CreatureLib::Library::TypeLibrary* typeLib, u8 attackingType, PkmnLib::Battling::Pokemon* pokemon) { return typeLib->GetEffectiveness(attackingType, pokemon->GetTypes()); @@ -152,6 +157,9 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const", asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL); Ensure(r >= 0); + r = engine->RegisterObjectMethod("Pokemon", "bool HasType(const constString& type) const", + asFUNCTION(HasTypeStringWrapper), asCALL_CDECL_OBJFIRST); + Ensure(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "void Damage(uint32 type, DamageSource source)", asMETHOD(PkmnLib::Battling::Pokemon, Damage), asCALL_THISCALL); Ensure(r >= 0);