From 03f1948b2dfa91071b6a4ee41579b19447b4a8dd Mon Sep 17 00:00:00 2001 From: Axel Cocat Date: Thu, 29 Dec 2022 11:51:29 +0100 Subject: [PATCH] feat: add Player:GetAchievementCriteriaProgress() (#78) --- src/LuaEngine/LuaFunctions.cpp | 1 + src/LuaEngine/PlayerMethods.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index 9fef984..1986d1c 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -612,6 +612,7 @@ ElunaRegister PlayerMethods[] = // {"HasPendingBind", &LuaPlayer::HasPendingBind}, // :HasPendingBind() - UNDOCUMENTED - Returns true if the player has a pending instance bind #if (!defined(TBC) && !defined(CLASSIC)) { "HasAchieved", &LuaPlayer::HasAchieved }, + { "GetAchievementCriteriaProgress", &LuaPlayer::GetAchievementCriteriaProgress }, #if defined(TRINITY) || defined(AZEROTHCORE) { "SetAchievement", &LuaPlayer::SetAchievement }, #endif diff --git a/src/LuaEngine/PlayerMethods.h b/src/LuaEngine/PlayerMethods.h index 2f48f99..cf49e8f 100644 --- a/src/LuaEngine/PlayerMethods.h +++ b/src/LuaEngine/PlayerMethods.h @@ -64,6 +64,28 @@ namespace LuaPlayer #endif return 1; } + + /** + * Returns the progress of the [Player] for the specified achievement criteria. + * + * @param uint32 criteriaId + * @return uint32 progress : progress value or nil + */ + int GetAchievementCriteriaProgress(lua_State* L, Player* player) + { + uint32 criteriaId = Eluna::CHECKVAL(L, 2); + const AchievementCriteriaEntry* criteria = sAchievementCriteriaStore.LookupEntry(criteriaId); + CriteriaProgress* progress = player->GetAchievementMgr()->GetCriteriaProgress(criteria); + if (progress) + { + Eluna::Push(L, progress->counter); + } + else + { + Eluna::Push(L, (void*)nullptr); + } + return 1; + } #endif /**