From 021b3a480293b34e9ba721a9dd666b6170d98da4 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 29 Aug 2021 11:42:20 +0200 Subject: [PATCH] Adds function to learn move. --- src/Tester/AngelScript/BattleFunctions.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Tester/AngelScript/BattleFunctions.hpp b/src/Tester/AngelScript/BattleFunctions.hpp index c924799..c9c4ab6 100644 --- a/src/Tester/AngelScript/BattleFunctions.hpp +++ b/src/Tester/AngelScript/BattleFunctions.hpp @@ -136,6 +136,15 @@ class BattleFunctions { return b; } + static void LearnMove(PkmnLib::Battling::Pokemon* user, const ArbUt::StringView& moveName) { + auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName); + if (!move.has_value()) { + THROW("Unknown move: " << moveName); + } + user->AddAttack( + new PkmnLib::Battling::LearnedMove(move.value(), CreatureLib::Battling::AttackLearnMethod::Unknown)); + } + public: static void Register(AngelScriptResolver* scriptResolver) { auto engine = scriptResolver->GetBuilder().GetEngine(); @@ -152,6 +161,8 @@ public: asFUNCTION(UseMove), asCALL_CDECL_OBJFIRST) >= 0); Ensure(engine->RegisterObjectMethod("Pokemon", "bool PassTurn()", asFUNCTION(PassTurn), asCALL_CDECL_OBJFIRST) >= 0); + Ensure(engine->RegisterObjectMethod("Pokemon", "bool LearnMove(const constString&in move)", + asFUNCTION(LearnMove), asCALL_CDECL_OBJFIRST) >= 0); } };