Skip to content

Commit

Permalink
feat: Add Spell:GetReagentCost() function (azerothcore#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
3ster committed Feb 25, 2024
1 parent 05b43dd commit 2bd22cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/LuaEngine/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ ElunaRegister<Spell> SpellMethods[] =
{ "GetEntry", &LuaSpell::GetEntry },
{ "GetDuration", &LuaSpell::GetDuration },
{ "GetPowerCost", &LuaSpell::GetPowerCost },
{ "GetReagentCost", &LuaSpell::GetReagentCost },
{ "GetTargetDest", &LuaSpell::GetTargetDest },
{ "GetTarget", &LuaSpell::GetTarget },

Expand Down
24 changes: 24 additions & 0 deletions src/LuaEngine/SpellMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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].
*
Expand Down

0 comments on commit 2bd22cf

Please sign in to comment.