Module:Items: Difference between revisions

Did some stuff to make sure potions sort properly
(Made Arrow Shaft exception)
(Did some stuff to make sure potions sort properly)
Line 912: Line 912:
function p._getItemUseTable(item)
function p._getItemUseTable(item)
   local useArray = {}
   local useArray = {}
  local potTierMastery = {[0] = 0, [1] = 15, [2] = 40, [3] = 65}


   --First, loop through all items to find anything that can be made or upgraded into using our source
   --First, loop through all items to find anything that can be made or upgraded into using our source
Line 923: Line 924:
           --Potions do have upgrade requirements though
           --Potions do have upgrade requirements though
           if item2.potionTier ~= nil then
           if item2.potionTier ~= nil then
            local potTierMastery = {[1] = 15, [2] = 40, [3] = 65}
             rowReq = Icons._MasteryReq(item2.name, potTierMastery[item2.potionTier])
             rowReq = Icons._MasteryReq(item2.name, potTierMastery[item2.potionTier])
           end
           end
Line 990: Line 990:
           local mat = item2.herbloreReq
           local mat = item2.herbloreReq
           local xp = potionData.herbloreXP
           local xp = potionData.herbloreXP
           local rowReq = potionData.herbloreLevel
          --Potions do have upgrade requirements though
           table.insert(useArray, {item = item2, qty = 1, mats = mat, skill = 'Herblore', req = rowReq, xp = xp})
           local rowReq = Icons._SkillReq('Herblore', potionData.herbloreLevel)
          local masteryLvl = 0
          if item2.potionTier ~= nil then
            masteryLvl = potTierMastery[item2.potionTier]
            rowReq = rowReq..'<br/>'..Icons._MasteryReq(item2.name, masteryLvl)
          end
          local reqVal = potionData.herbloreLevel + (masteryLvl * 0.01)
           table.insert(useArray, {item = item2, qty = 1, mats = mat, skill = 'Herblore', reqVal = reqVal, req = rowReq, xp = xp})
           break
           break
         end
         end
Line 1,000: Line 1,007:
   --Finally build the table using what we've learned
   --Finally build the table using what we've learned
   table.sort(useArray, function(a, b)
   table.sort(useArray, function(a, b)
                        local aReqVal = a.reqVal ~= nil and a.reqVal or a.req
                        local bReqVal = b.reqVal ~= nil and b.reqVal or b.req
                         if a.skill ~= b.skill then
                         if a.skill ~= b.skill then
                           return a.skill < b.skill
                           return a.skill < b.skill
                         elseif type(a.req) ~= type(b.req) then
                         elseif type(aReqVal) ~= type(bReqVal) then
                           return tostring(a.req) < tostring(b.req)
                           return tostring(aReqVal) < tostring(bReqVal)
                         elseif a.req ~= b.req then
                         elseif aReqVal ~= bReqVal then
                           return a.req < b.req
                           return aReqVal < bReqVal
                         else
                         else
                           return a.item.name < b.item.name
                           return a.item.name < b.item.name
Line 1,029: Line 1,038:
     if type(row.req) == 'number' then
     if type(row.req) == 'number' then
       result = result..'|| data-sort-value="'..row.req..'"|'..Icons._SkillReq(row.skill, row.req)
       result = result..'|| data-sort-value="'..row.req..'"|'..Icons._SkillReq(row.skill, row.req)
    elseif row.reqVal ~= nil then
      result = result..'|| data-sort-value="'..row.reqVal..'"|'..row.req
     else
     else
       result = result..'||'..row.req
       result = result..'||'..row.req