Anonymous

Module:Items: Difference between revisions

From Melvor Idle
4,473 bytes added ,  23 September 2020
Added function for compiling item sources. (Somewhat incomplete right now)
(Added nolink qualifier to getWeaponAttackType)
(Added function for compiling item sources. (Somewhat incomplete right now))
Line 1: Line 1:
local p = {}
local p = {}


local MonsterData = mw.loadData('Module:Monsters/data')
local ItemData = mw.loadData('Module:Items/data')
local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:Skills/data')
local SkillData = mw.loadData('Module:Skills/data')
Line 6: Line 7:
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon'}


function p.getItemByID(ID)
function p.getItemByID(ID)
Line 193: Line 196:


   return result
   return result
end
function p._getItemSources(item)
  local result = ''
  --Alright, time to go through all the ways you can get an item...
  --First up: Can we kill somebody and take theirs?
  local killFound = false
  for i, monster in pairs(MonsterData.Monsters) do
    if monster.lootTable ~= nil then
      for j, loot in pairs(monster.lootTable) do
        if loot[1] == item.id then
          if killFound then
            result = result..','..Icons.Icon({monster.name, type="monster", notext="true"})
          else
            result = result..'Killing: '..Icons.Icon({monster.name, type="monster", notext="true"})
            killFound = true
          end
        end
      end
    end
  end
  --Next: Can we find it in a box?
  local boxFound = false
  for i, chest in pairs(ItemData) do
    if chest.dropTable ~= nil then
      for j, loot in pairs(chest.dropTable) do
        if loot[1] == item.id then
          if boxFound then
            result = result..','..Icons.Icon({chest.name, type="item", notext="true"})
          else
            if string.len(result) > 0 then result = result..'\r\n<br/>' end
            result = result..'Opening: '..Icons.Icon({chest.name, type="item", notext="true"})
            boxFound = true
          end
        end
      end
    end
  end
  --Next: Can we take it from somebody else -without- killing them?
  for i, npc in pairs(SkillData.Thieving) do
    if npc.lootTable ~= nil then
      for j, loot in pairs(npc.lootTable) do
        if loot[1] == item.id then
          if string.len(result) > 0 then result = result..'\r\n<br/>' end
          result = result..'Pickpocketing: '..Icons.Icon({npc.name, type="thieving", notext="true"})
          boxFound = true
        end
      end
    end
  end
  --Next: Can we get to it via upgrading?
  local upgradeFound = false
  if item.itemsRequired ~= nil then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..'Upgrading: '
    for i, req in pairs(item.itemsRequired) do
      local reqItem = p.getItemByID(req[1])
      if reqItem.canUpgrade then
        if upgradeFound then result = result..', ' else upgradeFound = true end
        result = result..Icons.Icon({reqItem.name, type='item', notext='true'})
      end
    end
  end
  --If all else fails, I guess we should check if we can make it ourselves
  --SmithCheck:
  if item.smithingLevel ~= nil then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..Icons._SkillReq("Smithing", item.smithingLevel)
  end
  --CraftCheck:
  if item.craftingLevel ~= nil then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..Icons._SkillReq("Crafting", item.craftingLevel)
  end
  --FletchCheck:
  if item.fletchingLevel ~= nil then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..Icons._SkillReq("Fletching", item.fletchingLevel)
  end
  --RunecraftCheck:
  if item.runecraftingLevel ~= nil then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..Icons._SkillReq("Runecrafting", item.runecraftingLevel)
  end
  --FishCheck:
  if (item.category == "Fishing" and (item.type == "Junk" or item.type == "Special")) or item.category == "Gem" then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..Icons._SkillReq("Fishing", 1)
  elseif item.category == 'Fishing' then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..Icons._SkillReq("Fishing", item.fishingLevel)
  end
  --Finally there are some weird exceptions:
  --Shop items
  if item.slayerCost ~= nil or item.buysFor ~= nil then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..'[[Shop]]'
  end
  --Easter Eggs (manual list 'cause don't have a better way to do that)
  if Shared.contains(EasterEggs, item.name) then
    if string.len(result) > 0 then result = result..'\r\n<br/>' end
    result = result..'[[Easter Eggs]]'
  end
  return result
end
function p.getItemSources(frame)
  local itemName = frame.args ~= nil and frame[1] or frame
  local item = p.getItem(itemName)
  if item == nil then
    return "ERROR: No item named "..itemName.." exists in the data module"
  end
  return p._getItemSources(item)
end
end


return p
return p