Module:Items/SourceTables/Sandbox: Difference between revisions

getItemSourceTables: Format monster combat level
m (Fix level concat in table)
(getItemSourceTables: Format monster combat level)
 
(11 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
Line 799: Line 799:
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
table.insert(rowPart, '\r\n|' ..level)
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 843: 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 860: 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 875: 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 890: 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 919: 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 940: 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 955: 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 973: 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 993: 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
Line 1,001: Line 1,010:
sourceTxt = '[[Mining#Superior Gems|Superior Gem]]'
sourceTxt = '[[Mining#Superior Gems|Superior Gem]]'
-- Superior gems can only be found with Mining 100 or above
-- Superior gems can only be found with Mining 100 or above
lv = Icons._SkillReq("Mining", 100)
lv = 100
else
else
sourceTxt = '[[Mining#Gems|Gem]]'
sourceTxt = '[[Mining#Gems|Gem]]'
-- Gems can only be found with any Mining level
-- Gems can only be found with any Mining level
lv = Icons._SkillReq("Mining", 1)
lv = 1
end
end
table.insert(dropRows, {
table.insert(dropRows, {
source = sourceTxt,  
source = sourceTxt,  
type = mineType,  
level = Icons._SkillReq('Mining', lv),
level = lv,
levelNum = lv,
minqty = thisGem.minQuantity,  
minqty = thisGem.minQuantity,  
qty = thisGem.maxQuantity,  
qty = thisGem.maxQuantity,  
Line 1,018: 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,024: 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,
level = Icons._SkillReq("Magic", spell.level),
levelNum = spell.level,
minqty = thisGem.minQuantity,  
minqty = thisGem.minQuantity,  
qty = thisGem.maxQuantity,
qty = thisGem.maxQuantity,
Line 1,043: 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,052: 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,234: Line 1,242:


function p.getItemSourceTables(frame)
function p.getItemSourceTables(frame)
-- Temp
local itemName = frame.args ~= nil and frame.args[1] or frame
local args = frame:getParent().args
local itemName = args.item or args[1]
--local itemName = frame.args ~= nil and frame.args[1] or frame
local item = Items.getItem(itemName)
local item = Items.getItem(itemName)
if item == nil then
if item == nil then
Line 1,335: 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