Module:DropsLineRoatz: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 109: | Line 109: | ||
cats = categories{name,quantity,rarity,rarity1} | cats = categories{name,quantity,rarity,rarity1} | ||
return ret..cats | return ret..cats | ||
end | |||
-- main function to generate the row | |||
function p._main(name, | |||
altname,namenotes, | |||
quantity,quantitynotes, | |||
rarity,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value, | |||
raritynotes,image, | |||
rarity1,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value, | |||
raritynotes,image, | |||
rarity2,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value, | |||
raritynotes,image, | |||
rarity3,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value, | |||
raritynotes,image, | |||
valueInfo,gemw,alch,alt, | |||
isCoins, | |||
isNothing, | |||
frameArgs,monVers, | |||
cleanedName,dropVers,smwname, | |||
rdt,useSmw, | |||
approx, rolls) | |||
-- value sorts | |||
if type(vsort) ~= 'number' then | |||
vsort = 0 | |||
end | |||
if type(vasort) ~= 'number' then | |||
vasort = 0 | |||
end | |||
-- quantity notes | |||
if #quantitynotes > 3 then | |||
quantity = quantity..quantitynotes | |||
end | |||
-- rarity cell contents | |||
local rare_class, rare_sort | |||
if rarity_value == undefined then | |||
rare_class, rare_sort = unpack(rarities[rarity:lower()] or rarities._default) | |||
elseif rarity_value == false then | |||
rare_class, rare_sort = unpack(rarities._default) | |||
else | |||
rare_sort = 1/rarity_value | |||
rare_class = get_rarity_class(rarity_value) | |||
end | |||
local rollstext = '' | |||
local tilde = '' | |||
if approx then | |||
tilde = '~' | |||
end | |||
local _r = rarity | |||
-- monster versions | |||
local hasRowwideVersion = false | |||
local tblVers = frameArgs.version | |||
local versionKey = 'DEFAULT' | |||
if params.has_content(tblVers) then | |||
-- versions applied to the entire table | |||
versionKey = tblVers | |||
end | |||
if params.has_content(monVers) then | |||
-- versions applied to this row | |||
versionKey = monVers | |||
hasRowwideVersion = true | |||
end | |||
local quantityClassOverride = isNothing and 'table-na' or nil | |||
-- Table row creation | |||
local ret = mw.html.create('tr') | |||
-- row-wide things | |||
:css('text-align','center') | |||
-- inventory image | |||
:tag('td') | |||
:addClass('inventory-image') | |||
:wikitext(image) | |||
:done() | |||
-- item name | |||
:tag('td') | |||
:css('text-align','left') | |||
:addClass('item-col') | |||
:wikitext(string.format('%s',name,altname,#namenotes > 3 and namenotes or '')) | |||
:done() | |||
-- quantity | |||
:tag('td') | |||
:addClass(quantityClassOverride) | |||
:attr('data-sort-value',_h) | |||
:wikitext(quantity) | |||
:done() | |||
-- rarity | |||
local rarity_cell = ret:tag('td') | |||
local rarity_span = rarity_cell:tag('span') | |||
rarity_span:wikitext(rollstext .. tilde .. rarity) | |||
rarity_cell:attr('data-sort-value',rare_sort) | |||
:addClass(rare_class) | |||
if type(rarity_value) == 'number' then | |||
rarity_cell:attr('title', rollstext .. tilde .. string.format('%.3g%%', 100 * rarity_value)) | |||
rarity_span:attr({ | |||
['data-drop-fraction'] = rollstext .. tilde .. rarity, | |||
['data-drop-oneover'] = rollstext .. tilde .. '1/' .. commas(sigfig(1/rarity_value, 4)), | |||
['data-drop-percent'] = rollstext .. tilde .. sigfig(100 * rarity_value, 3), | |||
['data-drop-permil'] = rollstext .. tilde .. sigfig(1000 * rarity_value, 3), | |||
['data-drop-permyriad'] = rollstext .. tilde .. sigfig(10000 * rarity_value, 3), | |||
}) | |||
end | |||
-- rarity1 | |||
local rarity_cell = ret:tag('td') | |||
local rarity_span = rarity_cell:tag('span') | |||
rarity_span:wikitext(rollstext .. tilde .. rarity) | |||
rarity_cell:attr('data-sort-value',rare_sort) | |||
:addClass(rare_class) | |||
if type(rarity_value) == 'number' then | |||
rarity_cell:attr('title', rollstext .. tilde .. string.format('%.3g%%', 100 * rarity_value)) | |||
rarity_span:attr({ | |||
['data-drop-fraction'] = rollstext .. tilde .. rarity, | |||
['data-drop-oneover'] = rollstext .. tilde .. '1/' .. commas(sigfig(1/rarity_value, 4)), | |||
['data-drop-percent'] = rollstext .. tilde .. sigfig(100 * rarity_value, 3), | |||
['data-drop-permil'] = rollstext .. tilde .. sigfig(1000 * rarity_value, 3), | |||
['data-drop-permyriad'] = rollstext .. tilde .. sigfig(10000 * rarity_value, 3), | |||
}) | |||
end | |||
-- rarity2 | |||
local rarity_cell = ret:tag('td') | |||
local rarity_span = rarity_cell:tag('span') | |||
rarity_span:wikitext(rollstext .. tilde .. rarity) | |||
rarity_cell:attr('data-sort-value',rare_sort) | |||
:addClass(rare_class) | |||
if type(rarity_value) == 'number' then | |||
rarity_cell:attr('title', rollstext .. tilde .. string.format('%.3g%%', 100 * rarity_value)) | |||
rarity_span:attr({ | |||
['data-drop-fraction'] = rollstext .. tilde .. rarity, | |||
['data-drop-oneover'] = rollstext .. tilde .. '1/' .. commas(sigfig(1/rarity_value, 4)), | |||
['data-drop-percent'] = rollstext .. tilde .. sigfig(100 * rarity_value, 3), | |||
['data-drop-permil'] = rollstext .. tilde .. sigfig(1000 * rarity_value, 3), | |||
['data-drop-permyriad'] = rollstext .. tilde .. sigfig(10000 * rarity_value, 3), | |||
}) | |||
end | |||
-- rarity3 | |||
local rarity_cell = ret:tag('td') | |||
local rarity_span = rarity_cell:tag('span') | |||
rarity_span:wikitext(rollstext .. tilde .. rarity) | |||
rarity_cell:attr('data-sort-value',rare_sort) | |||
:addClass(rare_class) | |||
if type(rarity_value) == 'number' then | |||
rarity_cell:attr('title', rollstext .. tilde .. string.format('%.3g%%', 100 * rarity_value)) | |||
rarity_span:attr({ | |||
['data-drop-fraction'] = rollstext .. tilde .. rarity, | |||
['data-drop-oneover'] = rollstext .. tilde .. '1/' .. commas(sigfig(1/rarity_value, 4)), | |||
['data-drop-percent'] = rollstext .. tilde .. sigfig(100 * rarity_value, 3), | |||
['data-drop-permil'] = rollstext .. tilde .. sigfig(1000 * rarity_value, 3), | |||
['data-drop-permyriad'] = rollstext .. tilde .. sigfig(10000 * rarity_value, 3), | |||
}) | |||
end | |||
if alt_rarity ~= '' then | |||
if alt_rarity_endash ~= '' then | |||
rarity_cell:tag('span'):wikitext('–') | |||
else | |||
rarity_cell:tag('span'):wikitext('; ') | |||
end | |||
local alt_rarity_span = rarity_cell:tag('span') | |||
alt_rarity_span:wikitext(alt_rarity) | |||
if type(alt_rarity_value) == 'number' then | |||
alt_rarity_span:attr({ | |||
['data-drop-fraction'] = alt_rarity, | |||
['data-drop-oneover'] = '1/' .. commas(sigfig(1/alt_rarity_value, 3)), | |||
['data-drop-percent'] = sigfig(100 * alt_rarity_value, 3), | |||
['data-drop-permil'] = sigfig(1000 * alt_rarity_value, 3), | |||
['data-drop-permyriad'] = sigfig(10000 * alt_rarity_value, 3), | |||
}) | |||
end | |||
end | |||
if #raritynotes > 3 then | |||
rarity_cell:wikitext(raritynotes) | |||
end | |||
-- setup GE and alch cells | |||
local ge_td = ret:tag('td') | |||
-- common attributes | |||
ge_td :attr('data-sort-value',vsort) | |||
:addClass('ge-column') | |||
:css({ | |||
['text-align'] = 'right', | |||
cursor = 'help' | |||
}) | |||
local ge_td_title, ge_td_content, alch_td_title, alch_td_content | |||
-- SMW | |||
local onMain = ns == '' or ns == 'RuneScape' | |||
local unrecognizedDropVersionCategory = '' | |||
if onMain and useSmw and isNothing ~= true then | |||
local smw_sub = {} | |||
-- check if applies to all or only a version | |||
dropFrom = pgTitle | |||
if versionKey ~= 'DEFAULT' then | |||
dropFrom = pgTitle .. '#' .. versionKey | |||
end | |||
local droppedItemName = 'Dropped item' | |||
if rdt == true then | |||
droppedItemName = 'Dropped item from RDT' | |||
end | |||
local smw_json = { | |||
['Dropped item']=smwname, | |||
['Name Notes']=smwNameNote, | |||
['Drop Quantity']=smwQuantity, | |||
['Quantity High']=_h, | |||
['Quantity Low']=_l, | |||
Rarity=rarity, | |||
['Alt Rarity']=alt_rarity, | |||
['Alt Rarity Dash'] = alt_rarity_endash, | |||
['Rarity Notes']=smwRarityNote, | |||
['Rolls']=smwRolls, | |||
['Dropped from'] = dropFrom, | |||
['Drop level'] = dropLevel, | |||
['Drop type'] = dropType | |||
} | |||
local smw_sub = { | |||
[droppedItemName] = smwname, | |||
['Dropped from'] = dropFrom, | |||
["Drop JSON"] = mw.text.jsonEncode(smw_json) | |||
} | |||
end | |||
return tostring(ret) .. unrecognizedDropVersionCategory | |||
end | |||
function qty(quantity, isNothing) | |||
-- if no quantity is given, return unknown | |||
if string.lower(quantity) == 'varies' then | |||
return 'Varies' | |||
elseif isNothing then | |||
return 'N/A' | |||
elseif not quantity or string.lower(quantity) == 'unknown' then | |||
return 'Unknown' | |||
end | |||
-- en dashes are the proper dash for number ranges | |||
-- replace all hyphens and em dashes with en | |||
-- strip *all* whitespace | |||
-- change '(noted)' to '$n' for parsing | |||
quantity = mw.ustring.gsub(quantity,'[-—]','–') | |||
:gsub('%s','') | |||
:gsub('%(noted%)','$n') | |||
-- split list into table | |||
local vals = mw.text.split(quantity,'[,;]') | |||
local low = 2147483648 | |||
local high = 0 | |||
-- recreate the quantity string to ensure consistent formatting | |||
local numstr = {} | |||
for i, v in ipairs(vals) do | |||
local clean = v:gsub('$n','') | |||
-- if list element contains an en dash (indicating range) | |||
-- Find the smaller/larger number (just in case) | |||
-- Compare them to the current min/max | |||
-- put them in order with desired format | |||
if mw.ustring.find(v,'–') then | |||
local splitvals = mw.text.split(clean,'–') | |||
-- assume a is smaller, b is larger | |||
local a = tonumber(splitvals[1]) | |||
local b = tonumber(splitvals[2]) | |||
-- Just in case | |||
if a > b then | |||
a,b = b,a | |||
end | |||
if a < low then | |||
low = a | |||
end | |||
if b > high then | |||
high = b | |||
end | |||
local addx = commas(a)..'–'..commas(b) | |||
if v:find('$n') then | |||
addx = addx.._noted | |||
end | |||
table.insert(numstr,addx) | |||
else | |||
local a = tonumber(clean) | |||
if a < low then | |||
low = a | |||
end | |||
if a > high then | |||
high = a | |||
end | |||
local addx = commas(a) | |||
if v:find('$n') then | |||
addx = addx.._noted | |||
end | |||
table.insert(numstr,addx) | |||
end | |||
end | |||
-- Add a line break if there are too many elements | |||
-- To keep the tables thin | |||
if #numstr > 11 then | |||
local mid = math.floor(#numstr/2) | |||
numstr[mid] = '<br/>'..numstr[mid] | |||
end | |||
-- To prevent any possible confusion with formatted numbers | |||
-- elements should be separated with semicolons followed by a space | |||
numstr = table.concat(numstr,'; ') | |||
-- If no numbers are found in the string, return unknown | |||
if not numstr:find('%d') then | |||
return 'Unknown', price | |||
end | |||
return numstr, high, low | |||
end | |||
function get_total(value,qhigh,qlow) | |||
-- if no alch value is given, return unknown | |||
if not value or string.lower(value) == 'unknown' then | |||
return value | |||
end | |||
-- if value is negative (from smw/ge) it cannot be alched | |||
if tonumber(value) and tonumber(value) < 0 then | |||
return false | |||
end | |||
-- if no numbers return not alchemisable | |||
if not tonumber(value) and not value:find('%d') then | |||
return false | |||
end | |||
-- en dashes are the proper dash for number ranges | |||
-- replace all hyphens and em dashes with en | |||
-- strip *all* whitespace | |||
value = mw.ustring.gsub(value,'[-—]','–') | |||
:gsub('%s','') | |||
-- split list into table | |||
local vals = mw.text.split(value,'[,;]') | |||
-- All value ranges will be a range | |||
-- e.g. if items valued at 100 coins are dropped in quantities of 1, 3, 5 | |||
-- the value returned will be 100–500 rather than 100; 300; 500 | |||
-- If low and high vars are the same in the end, only 1 value is displayed | |||
local low = 2147483648 | |||
local high = 0 | |||
-- recreate the alchval string to ensure consistent formatting | |||
for i, v in ipairs(vals) do | |||
local clean = v:gsub('$n','') | |||
-- if list element contains an en dash (indicating range) | |||
-- Find the smaller/larger number (just in case) | |||
-- Compare them to the current min/max | |||
-- put them in order with desired format | |||
if mw.ustring.find(v,'–') then | |||
local splitvals = mw.text.split(clean,'–') | |||
-- assume a is smaller, b is larger | |||
local a = tonumber(splitvals[1]) | |||
local b = tonumber(splitvals[2]) | |||
-- Just in case | |||
if a > b then | |||
a,b = b,a | |||
end | |||
if a < low then | |||
low = a | |||
end | |||
if b > high then | |||
high = b | |||
end | |||
else | |||
local a = tonumber(clean) | |||
if a < low then | |||
low = a | |||
end | |||
if a > high then | |||
high = a | |||
end | |||
end | |||
end | |||
local valret, sort, avg | |||
if not qhigh or not qlow then | |||
sort = high | |||
avg = high | |||
valret = commas(high) | |||
else | |||
local lower = qlow * low | |||
local higher = qhigh * high | |||
if higher == lower then | |||
valret = commas(higher) | |||
avg = higher | |||
else | |||
valret = commas(lower)..'–'..commas(higher) | |||
avg = (lower+higher)/2 | |||
end | |||
sort = higher | |||
end | |||
return valret, sort, avg | |||
end | end |
Revision as of 16:10, 2 April 2024
Documentation for this module may be created at Module:DropsLineRoatz/doc
local p = {}
local params = require('Module:Paramtest')
local lang = mw.language.getContentLanguage()
local coins_image = require('Module:Coins image')
local curr_image = require('Module:Currency Image')
local exchange = require('Module:Exchange')
local yesno = require('Module:Yesno')
local var = mw.ext.VariablesLua
-- precalculated cached data
local geprices_data = mw.loadJsonData('Module:GEPrices/data.json')
local geprice = exchange._price
local f_gealch = exchange._highalch
local ptitle = mw.title.getCurrentTitle()
local ns = ptitle.nsText
local title = ptitle.fullText
local pgTitle = ptitle.text
local _noted = ' <span class="dropsline-noted">(noted)</span>'
local coins_priceString = "%s Pkp"
local other_priceString = "%s Pkp"
--bg, txt, sort; acceptable non-quantity rarity names
local rarities = {
always = { 'table-bg-blue', 1 },
common = { 'table-bg-green', 16 },
uncommon = { 'table-bg-yellow', 64 },
rare = { 'table-bg-orange', 128 },
['very rare'] = { 'table-bg-red', 1024 },
random = { 'table-bg-pink', 4096 },
varies = { 'table-bg-pink', 4096 },
once = { 'table-bg-pink', 65536 },
conditional = { 'table-bg-pink', 65536 },
_default = { 'table-bg-grey', 65536 }
}
-- colour-code
local rarities_class = {
{ 1, 'table-bg-blue' },
{ 1/25, 'table-bg-green' },
{ 1/99.99, 'table-bg-yellow' },
{ 1/999.99, 'table-bg-orange' },
{ 1/9999999, 'table-bg-red' }
}
-- Params and defaults
local name,namenotes,
quantity,quantitynotes,
rarity,alt_rarity,alt_rarity_endash,
raritynotes,citation,monVers = params.defaults{
{args.name or args.Name,'Item'},
{args.namenotes or args.Namenotes,''},
{args.quantity or args.Quantity,'Unknown'},
{args.quantitynotes or args.Quantitynotes,''},
{args.rarity or args.Rarity,'Unknown'},
{args.rarity1 or args.Rarity1,'Unknown'},
{args.rarity2 or args.Rarity2,'Unknown'},
{args.rarity3 or args.Rarity3,'Unknown'},
{args.altrarity or args.AltRarity,''},
{args.altraritydash or args.AltRarityDash,''},
{args.raritynotes or args.Raritynotes,''},
{args.citation,''},
{args.version or args.Version,''},
}
raritynotes = raritynotes .. citation
local rolls = tonumber(args.rolls or args.Rolls) or false
local rollstext = ''
if rolls then
rollstext = rolls .. ' × '
end
local approx = yesno(args.approx or args.Approx or 'no', false)
local isCoins = name:lower() == 'coins'
local isNothing = name:lower() == 'nothing'
local altname = params.default_to(args.alt or args.Alt,name)
local gemwname = params.default_to(args.gemwname,name)
local _smwname = params.default_to(args.smwname,gemwname)
-- Table row
local ret = p._main(name,
altname,namenotes,
quantity,quantitynotes,
rarity,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value,
raritynotes,image,
rarity1,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value,
raritynotes,image,
rarity2,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value,
raritynotes,image,
rarity3,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value,
raritynotes,image,
valueInfo,gemw,alch,alt,
isCoins,
isNothing,
frameArgs,monVers,
cleanedName,dropVers,smwname,
rdt,useSmw,
approx,rolls)
-- categories for mainspace
local cats = ''
local onMain = ns == '' or ns == 'RuneScape'
if onMain and useSmw then
cats = categories{name,quantity,rarity,rarity1}
return ret..cats
end
-- main function to generate the row
function p._main(name,
altname,namenotes,
quantity,quantitynotes,
rarity,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value,
raritynotes,image,
rarity1,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value,
raritynotes,image,
rarity2,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value,
raritynotes,image,
rarity3,rarity_value,alt_rarity,alt_rarity_endash,alt_rarity_value,
raritynotes,image,
valueInfo,gemw,alch,alt,
isCoins,
isNothing,
frameArgs,monVers,
cleanedName,dropVers,smwname,
rdt,useSmw,
approx, rolls)
-- value sorts
if type(vsort) ~= 'number' then
vsort = 0
end
if type(vasort) ~= 'number' then
vasort = 0
end
-- quantity notes
if #quantitynotes > 3 then
quantity = quantity..quantitynotes
end
-- rarity cell contents
local rare_class, rare_sort
if rarity_value == undefined then
rare_class, rare_sort = unpack(rarities[rarity:lower()] or rarities._default)
elseif rarity_value == false then
rare_class, rare_sort = unpack(rarities._default)
else
rare_sort = 1/rarity_value
rare_class = get_rarity_class(rarity_value)
end
local rollstext = ''
local tilde = ''
if approx then
tilde = '~'
end
local _r = rarity
-- monster versions
local hasRowwideVersion = false
local tblVers = frameArgs.version
local versionKey = 'DEFAULT'
if params.has_content(tblVers) then
-- versions applied to the entire table
versionKey = tblVers
end
if params.has_content(monVers) then
-- versions applied to this row
versionKey = monVers
hasRowwideVersion = true
end
local quantityClassOverride = isNothing and 'table-na' or nil
-- Table row creation
local ret = mw.html.create('tr')
-- row-wide things
:css('text-align','center')
-- inventory image
:tag('td')
:addClass('inventory-image')
:wikitext(image)
:done()
-- item name
:tag('td')
:css('text-align','left')
:addClass('item-col')
:wikitext(string.format('%s',name,altname,#namenotes > 3 and namenotes or ''))
:done()
-- quantity
:tag('td')
:addClass(quantityClassOverride)
:attr('data-sort-value',_h)
:wikitext(quantity)
:done()
-- rarity
local rarity_cell = ret:tag('td')
local rarity_span = rarity_cell:tag('span')
rarity_span:wikitext(rollstext .. tilde .. rarity)
rarity_cell:attr('data-sort-value',rare_sort)
:addClass(rare_class)
if type(rarity_value) == 'number' then
rarity_cell:attr('title', rollstext .. tilde .. string.format('%.3g%%', 100 * rarity_value))
rarity_span:attr({
['data-drop-fraction'] = rollstext .. tilde .. rarity,
['data-drop-oneover'] = rollstext .. tilde .. '1/' .. commas(sigfig(1/rarity_value, 4)),
['data-drop-percent'] = rollstext .. tilde .. sigfig(100 * rarity_value, 3),
['data-drop-permil'] = rollstext .. tilde .. sigfig(1000 * rarity_value, 3),
['data-drop-permyriad'] = rollstext .. tilde .. sigfig(10000 * rarity_value, 3),
})
end
-- rarity1
local rarity_cell = ret:tag('td')
local rarity_span = rarity_cell:tag('span')
rarity_span:wikitext(rollstext .. tilde .. rarity)
rarity_cell:attr('data-sort-value',rare_sort)
:addClass(rare_class)
if type(rarity_value) == 'number' then
rarity_cell:attr('title', rollstext .. tilde .. string.format('%.3g%%', 100 * rarity_value))
rarity_span:attr({
['data-drop-fraction'] = rollstext .. tilde .. rarity,
['data-drop-oneover'] = rollstext .. tilde .. '1/' .. commas(sigfig(1/rarity_value, 4)),
['data-drop-percent'] = rollstext .. tilde .. sigfig(100 * rarity_value, 3),
['data-drop-permil'] = rollstext .. tilde .. sigfig(1000 * rarity_value, 3),
['data-drop-permyriad'] = rollstext .. tilde .. sigfig(10000 * rarity_value, 3),
})
end
-- rarity2
local rarity_cell = ret:tag('td')
local rarity_span = rarity_cell:tag('span')
rarity_span:wikitext(rollstext .. tilde .. rarity)
rarity_cell:attr('data-sort-value',rare_sort)
:addClass(rare_class)
if type(rarity_value) == 'number' then
rarity_cell:attr('title', rollstext .. tilde .. string.format('%.3g%%', 100 * rarity_value))
rarity_span:attr({
['data-drop-fraction'] = rollstext .. tilde .. rarity,
['data-drop-oneover'] = rollstext .. tilde .. '1/' .. commas(sigfig(1/rarity_value, 4)),
['data-drop-percent'] = rollstext .. tilde .. sigfig(100 * rarity_value, 3),
['data-drop-permil'] = rollstext .. tilde .. sigfig(1000 * rarity_value, 3),
['data-drop-permyriad'] = rollstext .. tilde .. sigfig(10000 * rarity_value, 3),
})
end
-- rarity3
local rarity_cell = ret:tag('td')
local rarity_span = rarity_cell:tag('span')
rarity_span:wikitext(rollstext .. tilde .. rarity)
rarity_cell:attr('data-sort-value',rare_sort)
:addClass(rare_class)
if type(rarity_value) == 'number' then
rarity_cell:attr('title', rollstext .. tilde .. string.format('%.3g%%', 100 * rarity_value))
rarity_span:attr({
['data-drop-fraction'] = rollstext .. tilde .. rarity,
['data-drop-oneover'] = rollstext .. tilde .. '1/' .. commas(sigfig(1/rarity_value, 4)),
['data-drop-percent'] = rollstext .. tilde .. sigfig(100 * rarity_value, 3),
['data-drop-permil'] = rollstext .. tilde .. sigfig(1000 * rarity_value, 3),
['data-drop-permyriad'] = rollstext .. tilde .. sigfig(10000 * rarity_value, 3),
})
end
if alt_rarity ~= '' then
if alt_rarity_endash ~= '' then
rarity_cell:tag('span'):wikitext('–')
else
rarity_cell:tag('span'):wikitext('; ')
end
local alt_rarity_span = rarity_cell:tag('span')
alt_rarity_span:wikitext(alt_rarity)
if type(alt_rarity_value) == 'number' then
alt_rarity_span:attr({
['data-drop-fraction'] = alt_rarity,
['data-drop-oneover'] = '1/' .. commas(sigfig(1/alt_rarity_value, 3)),
['data-drop-percent'] = sigfig(100 * alt_rarity_value, 3),
['data-drop-permil'] = sigfig(1000 * alt_rarity_value, 3),
['data-drop-permyriad'] = sigfig(10000 * alt_rarity_value, 3),
})
end
end
if #raritynotes > 3 then
rarity_cell:wikitext(raritynotes)
end
-- setup GE and alch cells
local ge_td = ret:tag('td')
-- common attributes
ge_td :attr('data-sort-value',vsort)
:addClass('ge-column')
:css({
['text-align'] = 'right',
cursor = 'help'
})
local ge_td_title, ge_td_content, alch_td_title, alch_td_content
-- SMW
local onMain = ns == '' or ns == 'RuneScape'
local unrecognizedDropVersionCategory = ''
if onMain and useSmw and isNothing ~= true then
local smw_sub = {}
-- check if applies to all or only a version
dropFrom = pgTitle
if versionKey ~= 'DEFAULT' then
dropFrom = pgTitle .. '#' .. versionKey
end
local droppedItemName = 'Dropped item'
if rdt == true then
droppedItemName = 'Dropped item from RDT'
end
local smw_json = {
['Dropped item']=smwname,
['Name Notes']=smwNameNote,
['Drop Quantity']=smwQuantity,
['Quantity High']=_h,
['Quantity Low']=_l,
Rarity=rarity,
['Alt Rarity']=alt_rarity,
['Alt Rarity Dash'] = alt_rarity_endash,
['Rarity Notes']=smwRarityNote,
['Rolls']=smwRolls,
['Dropped from'] = dropFrom,
['Drop level'] = dropLevel,
['Drop type'] = dropType
}
local smw_sub = {
[droppedItemName] = smwname,
['Dropped from'] = dropFrom,
["Drop JSON"] = mw.text.jsonEncode(smw_json)
}
end
return tostring(ret) .. unrecognizedDropVersionCategory
end
function qty(quantity, isNothing)
-- if no quantity is given, return unknown
if string.lower(quantity) == 'varies' then
return 'Varies'
elseif isNothing then
return 'N/A'
elseif not quantity or string.lower(quantity) == 'unknown' then
return 'Unknown'
end
-- en dashes are the proper dash for number ranges
-- replace all hyphens and em dashes with en
-- strip *all* whitespace
-- change '(noted)' to '$n' for parsing
quantity = mw.ustring.gsub(quantity,'[-—]','–')
:gsub('%s','')
:gsub('%(noted%)','$n')
-- split list into table
local vals = mw.text.split(quantity,'[,;]')
local low = 2147483648
local high = 0
-- recreate the quantity string to ensure consistent formatting
local numstr = {}
for i, v in ipairs(vals) do
local clean = v:gsub('$n','')
-- if list element contains an en dash (indicating range)
-- Find the smaller/larger number (just in case)
-- Compare them to the current min/max
-- put them in order with desired format
if mw.ustring.find(v,'–') then
local splitvals = mw.text.split(clean,'–')
-- assume a is smaller, b is larger
local a = tonumber(splitvals[1])
local b = tonumber(splitvals[2])
-- Just in case
if a > b then
a,b = b,a
end
if a < low then
low = a
end
if b > high then
high = b
end
local addx = commas(a)..'–'..commas(b)
if v:find('$n') then
addx = addx.._noted
end
table.insert(numstr,addx)
else
local a = tonumber(clean)
if a < low then
low = a
end
if a > high then
high = a
end
local addx = commas(a)
if v:find('$n') then
addx = addx.._noted
end
table.insert(numstr,addx)
end
end
-- Add a line break if there are too many elements
-- To keep the tables thin
if #numstr > 11 then
local mid = math.floor(#numstr/2)
numstr[mid] = '<br/>'..numstr[mid]
end
-- To prevent any possible confusion with formatted numbers
-- elements should be separated with semicolons followed by a space
numstr = table.concat(numstr,'; ')
-- If no numbers are found in the string, return unknown
if not numstr:find('%d') then
return 'Unknown', price
end
return numstr, high, low
end
function get_total(value,qhigh,qlow)
-- if no alch value is given, return unknown
if not value or string.lower(value) == 'unknown' then
return value
end
-- if value is negative (from smw/ge) it cannot be alched
if tonumber(value) and tonumber(value) < 0 then
return false
end
-- if no numbers return not alchemisable
if not tonumber(value) and not value:find('%d') then
return false
end
-- en dashes are the proper dash for number ranges
-- replace all hyphens and em dashes with en
-- strip *all* whitespace
value = mw.ustring.gsub(value,'[-—]','–')
:gsub('%s','')
-- split list into table
local vals = mw.text.split(value,'[,;]')
-- All value ranges will be a range
-- e.g. if items valued at 100 coins are dropped in quantities of 1, 3, 5
-- the value returned will be 100–500 rather than 100; 300; 500
-- If low and high vars are the same in the end, only 1 value is displayed
local low = 2147483648
local high = 0
-- recreate the alchval string to ensure consistent formatting
for i, v in ipairs(vals) do
local clean = v:gsub('$n','')
-- if list element contains an en dash (indicating range)
-- Find the smaller/larger number (just in case)
-- Compare them to the current min/max
-- put them in order with desired format
if mw.ustring.find(v,'–') then
local splitvals = mw.text.split(clean,'–')
-- assume a is smaller, b is larger
local a = tonumber(splitvals[1])
local b = tonumber(splitvals[2])
-- Just in case
if a > b then
a,b = b,a
end
if a < low then
low = a
end
if b > high then
high = b
end
else
local a = tonumber(clean)
if a < low then
low = a
end
if a > high then
high = a
end
end
end
local valret, sort, avg
if not qhigh or not qlow then
sort = high
avg = high
valret = commas(high)
else
local lower = qlow * low
local higher = qhigh * high
if higher == lower then
valret = commas(higher)
avg = higher
else
valret = commas(lower)..'–'..commas(higher)
avg = (lower+higher)/2
end
sort = higher
end
return valret, sort, avg
end