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]. *