Anonymous

Module:Items: Difference between revisions

From Melvor Idle
2,389 bytes added ,  25 September 2020
Added more item creation/production tables
(Fixed issue caused by changing over to ItemData.Items)
(Added more item creation/production tables)
Line 27: Line 27:
       --Make sure every item has an id, and account for Lua being 1-index
       --Make sure every item has an id, and account for Lua being 1-index
       result.id = i -1
       result.id = i -1
      break
     end
     end
   end
   end
Line 127: Line 128:


   local skill = ''
   local skill = ''
  local specialReq = nil
   local time = 0
   local time = 0
  local maxTime = nil
   local lvl = 0
   local lvl = 0
   local xp = 0
   local xp = 0
   local qty = nil
   local qty = nil
   local req = {}
   local req = nil
   --First figure out what skill is used to make this...
   --First figure out what skill is used to make this...
   if item.smithingLevel ~= nil then
   if item.smithingLevel ~= nil then
Line 170: Line 173:
     xp = potionData.herbloreXP
     xp = potionData.herbloreXP
     time = 2
     time = 2
  elseif item.miningLevel ~= nil then
    skill = 'Mining'
    lvl = item.miningLevel
    time = 3
    xp = item.miningXP
    if item.name == 'Dragonite Ore' then
      specialReq = Icons.Icon({"Mastery", notext='true'})..' 271 total [[Mining]] [[Mastery]]'
    end
  elseif item.type == "Logs" then
    --Well this feels like cheating, but for as long as logs are the first items by ID it works
    local treeData = SkillData.Woodcutting[item.id + 1]
    skill = 'Woodcutting'
    lvl = treeData.level
    time = treeData.interval / 1000
    xp = treeData.xp
  elseif item.fishingLevel ~= nil then
    skill = 'Fishing'
    lvl = item.fishingLevel
    xp = item.fishingXP
    time = item.minFishingInterval/1000
    maxTime = item.maxFishingInterval/1000
  elseif item.type == "Havest" or type == "Herb" then
    --Havest/Herb means farming
    --Yes, Havest. The typos are coming from inside the source code
    for i, item2 in pairs(ItemData.Items) do
      if item2.grownItemID == item.id then
        skill = 'Farming'
        lvl = item2.farmingLevel
        xp = item2.farmingXP
        time = item2.timeToGrow
        qty = 5
        req = {{id = i - 1, qty = (item2.seedsRequired ~= nil and item2.seedsRequired or 1)}}
        break
      end
    end
    if skill == '' then
      return "Failed to find source item for herb/fruit/vegetable"
    end
  elseif item.type == "Food" or item.type == "Cooked Fish" then
    --Food/Cooked Fish is Fishing, need to figure out source item
    for i, item2 in pairs(ItemData.Items) do
      if item2.burntItemID == item.id or item2.cookedItemID == item.id then
        skill = 'Cooking'
        lvl = item2.cookingLevel
        if item2.burntItemID == item.id then
          xp = 1
        else
          xp = item2.cookingXP
        end
        time = 3
        req = {{id = i - 1, qty = 1}}
        break
      end
    end
    if skill == '' then
      return "Failed to find source item for cooked/burnt fish"
    end
   else
   else
     return "Failed to find creation requirements for this (Possibly the module isn't properly updated for this skill)"
     return "Failed to find creation requirements for this (Possibly the module isn't properly updated for this skill)"
Line 176: Line 236:


   local result = '{|class="wikitable"'
   local result = '{|class="wikitable"'
   result = result..'\r\n!colspan="2"|Item Creation\r\n|-'
   if req ~= nil then
    result = result..'\r\n!colspan="2"|Item Creation'
  else
    result = result..'\r\n!colspan="2"|Item Production'
  end
   result = result..'\r\n|-\r\n!style="text-align: right;"|Requirements'
   result = result..'\r\n|-\r\n!style="text-align: right;"|Requirements'
   result = result..'\r\n|'..Icons.Icon({skill, type="skill", notext="true"}).." '''"..lvl.."'''"
   result = result..'\r\n|'..Icons.Icon({skill, type="skill", notext="true"}).." '''"..lvl.."''' [["..skill.."]]"
   result = result..'\r\n|-\r\n!style="text-align: right;"|Materials\r\n|'
   if specialReq ~= nil then result = result..'<br/>'..specialReq end
  for i, mat in pairs(req) do
 
    if i > 1 then result = result..'<br/>' end
  if req ~= nil then
    local matItem = p.getItemByID(mat.id)
    result = result..'\r\n|-\r\n!style="text-align: right;"|Materials\r\n|'
    if matItem == nil then
    for i, mat in pairs(req) do
      result = result..mat.qty..'x ?????'
      if i > 1 then result = result..'<br/>' end
    else
      local matItem = p.getItemByID(mat.id)
      result = result..Icons.Icon({matItem.name, type='item', qty=mat.qty})
      if matItem == nil then
        result = result..mat.qty..'x ?????'
      else
        result = result..Icons.Icon({matItem.name, type='item', qty=mat.qty})
      end
     end
     end
   end
   end
Line 194: Line 262:
   result = result..'\r\n|'..xp..' XP'
   result = result..'\r\n|'..xp..' XP'
   result = result..'\r\n|-\r\n!style="text-align:right;"|Base Creation Time'
   result = result..'\r\n|-\r\n!style="text-align:right;"|Base Creation Time'
   result = result..'\r\n|'..time..'.0 s'
   result = result..'\r\n|'..Shared.formatnum(Shared.round(time, 2, 1))..'s'
  if maxTime ~= nil then result = result..' - '..Shared.formatnum(Shared.round(maxTime, 2, 1))..'s' end
   result = result..'\r\n|}'
   result = result..'\r\n|}'