Module:Items/SourceTables/Sandbox: Difference between revisions

getItemSourceTables: Format monster combat level
m (WIP (partially add level to output table))
(getItemSourceTables: Format monster combat level)
 
(16 intermediate revisions by 2 users not shown)
Line 789: Line 789:
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n!Source!!Source Type!!Level!!Quantity!!colspan="2"|Chance')
table.insert(resultPart, '\r\n!Source!!Level!!Quantity!!colspan="2"|Chance')


--Set up function for adding rows
--Set up function for adding rows
local buildRow = function(source, type, level, minqty, qty, weight, totalWeight, expIcon)
local buildRow = function(source, level, levelNum, minqty, qty, weight, totalWeight, expIcon)
if minqty == nil then minqty = 1 end
if minqty == nil then minqty = 1 end
if expIcon == nil then expIcon = '' end
if expIcon == nil then expIcon = '' end
if level == nil then level = 'N/A' end
local rowPart = {}
local rowPart = {}
table.insert(rowPart, '\r\n|-')
table.insert(rowPart, '\r\n|-')
table.insert(rowPart, '\r\n|style="text-align: left;"|'..source)
table.insert(rowPart, '\r\n|style="text-align: left;"|'..source)
--Weeding out brackets since they don't play nice with data-sort-value
-- Retrieve numeric level value for sorting, or remove anything between [[]]
local _, _, typeText = string.find(type, "%|([%a%s]+)%]")
local levelValue = ''
if typeText == nil then _, _, typeText = string.find(type, "%[%[([%a%s]+)%]") end
if levelNum ~= nil then
if typeText == nil then typeText = type end
levelValue = tostring(levelNum)
table.insert(rowPart, '\r\n|style="text-align: left;" data-sort-value="'..typeText..'"|'..expIcon..type)
else
 
levelValue = level:match('%[%[.-%]%]%s*(%w+)$') or ''
end
table.insert(rowPart, '\r\n|style="text-align: left;" data-sort-value="'..levelValue..'"|'..expIcon.. level)
table.insert(rowPart, '\r\n|style="text-align: right;" data-sort-value="'..qty..'"|'..Shared.formatnum(minqty))
table.insert(rowPart, '\r\n|style="text-align: right;" data-sort-value="'..qty..'"|'..Shared.formatnum(minqty))
if qty ~= minqty then table.insert(rowPart, ' - '..Shared.formatnum(qty)) end
if qty ~= minqty then table.insert(rowPart, ' - '..Shared.formatnum(qty)) end
Line 842: Line 845:
iconName = SourceOverrides[drop.id]
iconName = SourceOverrides[drop.id]
end
end
if monster ~= nil then
if monster ~= nil then
local monsterLevel = Monsters._getMonsterCombatLevel(monster)
table.insert(dropRows, {
table.insert(dropRows, {
source = Icons.Icon({iconName, type='monster'}),  
source = Icons.Icon({iconName, type='monster'}),  
type = '[[Monster]]', minqty = drop.minQty,  
level = Icons.Icon({'Monsters', img='Combat', notext=true}) .. ' Level ' .. Shared.formatnum(monsterLevel),
levelNum = monsterLevel,
minqty = drop.minQty,  
qty = drop.maxQty,  
qty = drop.maxQty,  
weight = drop.dropWt,  
weight = drop.dropWt,  
Line 859: Line 866:
table.insert(dropRows, {
table.insert(dropRows, {
source = Icons.Icon({drop.name, type='poi'}),  
source = Icons.Icon({drop.name, type='poi'}),  
type = '[[Archaeology|Dig Site]] ('..drop.size..')',  
level = Icons._SkillReq('Archaeology', drop.level) .. ' ('..drop.size..')',
levelNum = drop.level,
minqty = drop.minQty,  
minqty = drop.minQty,  
qty = drop.maxQty,  
qty = drop.maxQty,  
Line 874: Line 882:
table.insert(dropRows, {
table.insert(dropRows, {
source = Icons.Icon({dungeon.name, type='dungeon'}),  
source = Icons.Icon({dungeon.name, type='dungeon'}),  
type = '[[Dungeon]]',  
level = '[[Dungeon]]',
minqty = 1,  
minqty = 1,  
qty = 1,  
qty = 1,  
Line 889: Line 897:
table.insert(dropRows, {
table.insert(dropRows, {
source = sourceTxt,  
source = sourceTxt,  
type = '[[Dungeon]]',  
level = '[[Dungeon]]',
minqty = 1,  
minqty = 1,  
qty = 1,  
qty = 1,  
Line 918: Line 926:
table.insert(dropRows, {
table.insert(dropRows, {
source = sourceTxt,  
source = sourceTxt,  
type = '[[Chest]]',  
level = '[[Chest]]',
minqty = minQty,  
minqty = minQty,  
qty = maxQty,  
qty = maxQty,  
Line 939: Line 947:
table.insert(dropRows, {
table.insert(dropRows, {
source = sourceTxt,  
source = sourceTxt,  
type = Icons.Icon({SkillData.Thieving.name, type='skill'}),  
level = Icons._SkillReq("Thieving", thiefRow.level),
levelNum = thiefRow.level,
minqty = thiefRow.minQty,  
minqty = thiefRow.minQty,  
qty = thiefRow.maxQty,  
qty = thiefRow.maxQty,  
Line 954: Line 963:
table.insert(dropRows, {
table.insert(dropRows, {
source = fishSource,  
source = fishSource,  
type = fishType,  
level = Icons._SkillReq("Fishing", 1),
levelNum = 1,
minqty = 1,  
minqty = 1,  
qty = 1,  
qty = 1,  
Line 972: Line 982:
table.insert(dropRows, {
table.insert(dropRows, {
source = fishSource,  
source = fishSource,  
type = fishType,  
level = Icons._SkillReq("Fishing", 1),
levelNum = 1,
minqty = fishItem.minQuantity,  
minqty = fishItem.minQuantity,  
qty = fishItem.maxQuantity,  
qty = fishItem.maxQuantity,  
Line 992: Line 1,003:
end
end
if thisGem ~= nil then
if thisGem ~= nil then
local mineType = Icons.Icon({SkillData.Mining.name, type='skill'})
local expIcon = ''
local expIcon = ''
local sourceTxt
local sourceTxt
local lv = nil
if item.type == 'Superior Gem' then
if item.type == 'Superior Gem' then
expIcon = Icons.TotH()
expIcon = Icons.TotH()
sourceTxt = '[[Mining#Superior Gems|Superior Gem]]'
sourceTxt = '[[Mining#Superior Gems|Superior Gem]]'
-- Superior gems can only be found with Mining 100 or above
lv = 100
else
else
sourceTxt = '[[Mining#Gems|Gem]]'
sourceTxt = '[[Mining#Gems|Gem]]'
-- Gems can only be found with any Mining level
lv = 1
end
end
table.insert(dropRows, {
table.insert(dropRows, {
source = sourceTxt,  
source = sourceTxt,  
type = mineType,  
level = Icons._SkillReq('Mining', lv),
levelNum = lv,
minqty = thisGem.minQuantity,  
minqty = thisGem.minQuantity,  
qty = thisGem.maxQuantity,  
qty = thisGem.maxQuantity,  
Line 1,011: Line 1,027:
-- Check for Alt. Magic spells also
-- Check for Alt. Magic spells also
local magicType = Icons.Icon({SkillData.Magic.name, type = 'skill'})
local producesKey = (gemKey == 'randomGems' and 'RandomGem') or 'RandomSuperiorGem'
local producesKey = (gemKey == 'randomGems' and 'RandomGem') or 'RandomSuperiorGem'
for j, spell in ipairs(Magic.getSpellsBySpellBook('altMagic')) do
for j, spell in ipairs(Magic.getSpellsBySpellBook('altMagic')) do
Line 1,017: Line 1,032:
table.insert(dropRows, {
table.insert(dropRows, {
source = Icons.Icon({spell.name, type=Magic._getSpellIconType(spell)}),  
source = Icons.Icon({spell.name, type=Magic._getSpellIconType(spell)}),  
type = magicType,  
level = Icons.Icon({'Alternative Magic', type='skill', img='Magic', notext=true}) .. ' Level ' .. spell.level,
levelNum = spell.level,
minqty = thisGem.minQuantity,  
minqty = thisGem.minQuantity,  
qty = thisGem.maxQuantity,
qty = thisGem.maxQuantity,
Line 1,035: Line 1,051:
if a.weight / a.totalWeight == b.weight / b.totalWeight then
if a.weight / a.totalWeight == b.weight / b.totalWeight then
if a.minqty + a.qty == b.minqty + b.qty then
if a.minqty + a.qty == b.minqty + b.qty then
return (a.type == b.type and a.source < b.source) or a.type < b.type
return (a.level == b.level and a.source < b.source) or a.level < b.level
else
else
return a.minqty + a.qty > b.minqty + b.qty
return a.minqty + a.qty > b.minqty + b.qty
Line 1,044: Line 1,060:
end)
end)
for i, data in ipairs(dropRows) do
for i, data in ipairs(dropRows) do
table.insert(resultPart, buildRow(data.source, data.type, data.level, data.minqty, data.qty, data.weight, data.totalWeight, data.expIcon))
table.insert(resultPart, buildRow(data.source, data.level, data.levelNum, data.minqty, data.qty, data.weight, data.totalWeight, data.expIcon))
end
end


Line 1,324: Line 1,340:
local min = found.minQuantity
local min = found.minQuantity
local max = found.maxQuantity
local max = found.maxQuantity
table.insert(resultArray, {id = digSite.id, name = digSite.name, size = sizeName, minQty = min, maxQty = max, dropWt = found.weight, totalWt = sizeWeight})
table.insert(resultArray, {
id = digSite.id,  
name = digSite.name,  
level = digSite.level,
size = sizeName,  
minQty = min,  
maxQty = max,  
dropWt = found.weight,  
totalWt = sizeWeight})
end
end
end
end