Module:Items: Difference between revisions

1,747 bytes added ,  30 September 2020
Added the Item Upgrade source table
(Added woodcutting handling to getItemSources)
(Added the Item Upgrade source table)
Line 299: Line 299:
     return ""
     return ""
   else
   else
     return table.concat(tables, '<br/>\r\n')
     return table.concat(tables, '\r\n')
   end
   end
end
end
Line 978: Line 978:
     table.insert(dropRows, {source = fishSource, type = fishType, minqty = 1, qty = 1, chance = thisChance})
     table.insert(dropRows, {source = fishSource, type = fishType, minqty = 1, qty = 1, chance = thisChance})
   end
   end
    
 
   --Make sure to return nothing if there are no drop sources 
  if Shared.tableCount(dropRows) == 0 then return '' end
 
   table.sort(dropRows, function(a, b) return a.qty * a.chance > b.qty * b.chance end)
   table.sort(dropRows, function(a, b) return a.qty * a.chance > b.qty * b.chance end)
   for i, data in pairs(dropRows) do
   for i, data in pairs(dropRows) do
Line 996: Line 999:


   return p._getItemLootSourceTable(item)
   return p._getItemLootSourceTable(item)
end
function p._getItemUpgradeTable(item)
  local result = ''
  if item.itemsRequired ~= nil then
    --First, get details on all the required materials
    local upgradeFrom = {}
    local materials = {}
    for i, row in pairs(item.itemsRequired) do
      local mat = p.getItemByID(row[1])
      --Check to see if the source item can trigger the upgrade
      if mat.canUpgrade or (mat.type == 'Armour' and mat.canUpgrade == nil) then
        table.insert(upgradeFrom, Icons.Icon({mat.name, type='item'}))
      end
      table.insert(materials, Icons.Icon({mat.name, type='item', qty=row[2]}))
    end
    if item.trimmedGPCost ~= nil then
      table.insert(materials, Icons.GP(item.trimmedGPCost))
    end
    result = '{| class="wikitable"\r\n|-\r\n!colspan="2"|Item Upgrade'
    result = result..'\r\n|-\r\n!style="text-align:right;"|Upgrades From\r\n|'
    result = result..table.concat(upgradeFrom, '<br/>')
    result = result..'\r\n|-\r\n|style="text-align:right;"|Materials\r\n|'
    result = result..table.concat(materials, '<br/>')
    result = result..'\r\n|}'
  end
  return result
end
function p.getItemUpgradeTable(frame)
  local itemName = frame.args ~= nil and frame.args[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._getItemUpgradeTable(item)
end
end


Line 1,002: Line 1,042:
   local creationTable = p._getCreationTable(item)
   local creationTable = p._getCreationTable(item)
   if string.len(creationTable) > 0 then result = result..'===Creation===\r\n'..creationTable end
   if string.len(creationTable) > 0 then result = result..'===Creation===\r\n'..creationTable end
  local upgradeTable = p._getItemUpgradeTable(item)
  if string.len(upgradeTable) > 0 then
    if string.len(result) > 0 then
      result = result..'\r\n'
    else
      result = '===Creation===\r\n'
    end
    result = result..upgradeTable
  end
   local lootTable = p._getItemLootSourceTable(item)
   local lootTable = p._getItemLootSourceTable(item)
   if string.len(lootTable) > 0 then
   if string.len(lootTable) > 0 then