feat: Add Spell:GetReagentCost() function (#165)

This commit is contained in:
3ster
2024-02-25 20:45:58 +01:00
committed by GitHub
parent 05b43dd89b
commit 2bd22cf927
2 changed files with 25 additions and 0 deletions

View File

@@ -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 },

View File

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