Anonymous

Module:Magic: Difference between revisions

From Melvor Idle
1,880 bytes added ,  6 October 2020
Added ability to get all spells for a given rune.
(Fixed some mistakes with new getting spells)
(Added ability to get all spells for a given rune.)
Line 55: Line 55:
     return nil
     return nil
   end
   end
end
function p.getSpellsForRune(runeID)
  local spellList = {}
  for secName, secArray in Shared.skpairs(MagicData) do
    for i, spell in pairs(secArray) do
      local foundSpell = false
      for j, req in pairs(spell.runesRequired) do
        if req.id == runeID then
          table.insert(spellList, processSpell(secName, i))
          foundSpell = true
          break
        end
      end
      if spell.runesRequiredAlt ~= nil and not foundSpell then
        for j, req in pairs(spell.runesRequiredAlt) do
          if req.id == runeID then
            table.insert(spellList, processSpell(secName, i))
            break
          end
        end
      end
    end
  end
  table.sort(spellList, function(a, b)
              if a.type ~= b.type then
                return p.getSpellTypeIndex(a.type) < p.getSpellTypeIndex(b.type)
              else
                return a.magicLevelRequired < b.magicLevelRequired
              end
            end)
  return spellList
end
function p.getSpellTypeIndex(type)
  if type == 'Spells' then
    return 0
  elseif type == 'Curses' then
    return 1
  elseif type == 'Auroras' then
    return 2
  elseif type == 'Ancient' then
    return 3
  elseif type == 'AltMagic' then
    return 4
  end
  return -1
end
function p.getSpellTypeLink(type)
  if type == 'Spells' then
    return Icons.Icon({'Magic#Standard Magic', 'Standard', img='Standard', type='spellType'})
  elseif type == 'Curses' then
    return Icons.Icon({'Magic#Curses', 'Curse', img='Curse', type='spellType'})
  elseif type == 'Auroras' then
    return Icons.Icon({'Magic#Auroras', 'Aurora', img='Aurora', type='spellType'})
  elseif type == 'Ancient' then
    return Icons.Icon({'Magic#Ancient Magicks', 'Ancient', img='Ancient', type='spellType'})
  elseif type == 'AltMagic' then
    return Icons.Icon({'Alt. Magic', type='skill'})
  end
  return ''
end
end


return p
return p