Anonymous

Module:Items/ComparisonTables: Difference between revisions

From Melvor Idle
Re-implement getDoubleLootTable()
(Swapping over to Auron's v0.21 test version)
(Re-implement getDoubleLootTable())
Line 379: Line 379:
     return p._getEquipmentTable(itemList, includeModifiers)
     return p._getEquipmentTable(itemList, includeModifiers)
   end
   end
end
function p.getDoubleLootTable(frame)
  local modsDL = {
    'increasedChanceToDoubleLootCombat',
    'decreasedChanceToDoubleLootCombat',
    'increasedChanceToDoubleLootThieving',
    'decreasedChanceToDoubleLootThieving',
    'increasedChanceToDoubleItemsGlobal',
    'decreasedChanceToDoubleItemsGlobal'
  }
  local modDetail = {}
  for i, modName in pairs(modsDL) do
    local mName, mText, mSign, mIsNeg, mValUnsigned = Constants.getModifierDetails(modName)
    modDetail[modName] = { mult = (mSign == "+" and 1 or -1) }
  end
  local itemList = Items.getItems(function(item)
      if item.modifiers ~= nil then
        for modName, val in pairs(item.modifiers) do
          if Shared.contains(modsDL, modName) then return true end
        end
        return false
      end
    end)
  table.sort(itemList, function(a, b) return a.id < b.id end)
  local resultPart = {}
  table.insert(resultPart, '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"')
  table.insert(resultPart, '\r\n!colspan="2"|Name!!Bonus!!Description')
  for i, item in Shared.skpairs(itemList) do
    local lootValue = 0
    for modName, modDet in pairs(modDetail) do
      lootValue = lootValue + (item.modifiers[modName] or 0) * modDet.mult
    end
    table.insert(resultPart, '\r\n|-')
    table.insert(resultPart, '\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
    table.insert(resultPart, '||[['..item.name..']]')
    table.insert(resultPart, '||style ="text-align: right;" data-sort-value="'..lootValue..'"|'..lootValue..'%')
    table.insert(resultPart, '||'..item.description)
  end
  table.insert(resultPart, '\r\n|}')
  return table.concat(resultPart)
end
end