From 2bd22cf927b31352366c3d82a171dba3d4994c01 Mon Sep 17 00:00:00 2001 From: 3ster <50641641+3ster@users.noreply.github.com> Date: Sun, 25 Feb 2024 20:45:58 +0100 Subject: [PATCH] feat: Add Spell:GetReagentCost() function (#165) --- src/LuaEngine/LuaFunctions.cpp | 1 + src/LuaEngine/SpellMethods.h | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index 1dd89ff82d..ae7b23e758 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -1085,6 +1085,7 @@ ElunaRegister SpellMethods[] = { "GetEntry", &LuaSpell::GetEntry }, { "GetDuration", &LuaSpell::GetDuration }, { "GetPowerCost", &LuaSpell::GetPowerCost }, + { "GetReagentCost", &LuaSpell::GetReagentCost }, { "GetTargetDest", &LuaSpell::GetTargetDest }, { "GetTarget", &LuaSpell::GetTarget }, diff --git a/src/LuaEngine/SpellMethods.h b/src/LuaEngine/SpellMethods.h index 2036c0084f..3c5d0252e1 100644 --- a/src/LuaEngine/SpellMethods.h +++ b/src/LuaEngine/SpellMethods.h @@ -69,6 +69,30 @@ namespace LuaSpell return 1; } + /** + * Returns the reagents needed for the [Spell]. + * + * @return table reagents : a table containing the [ItemTemplate]s and amount of reagents needed for the [Spell] + */ + int GetReagentCost(lua_State* L, Spell* spell) + { + auto spellInfo = spell->GetSpellInfo(); + auto reagents = spellInfo->Reagent; + auto reagentCounts = spellInfo->ReagentCount; + lua_newtable(L); + for (auto i = 0; i < MAX_SPELL_REAGENTS; ++i) + { + if (reagents[i] <= 0) + continue; + auto reagent = eObjectMgr->GetItemTemplate(reagents[i]); + auto count = reagentCounts[i]; + Eluna::Push(L, reagent); + Eluna::Push(L, count); + lua_settable(L, -3); + } + return 1; + } + /** * Returns the spell duration of the [Spell]. *