Module:DropsLine: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary Tag: Manual revert |
||
(15 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
local coins_image = require('Module:Coins image') | local coins_image = require('Module:Coins image') | ||
local curr_image = require('Module:Currency Image') | local curr_image = require('Module:Currency Image') | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
Line 15: | Line 14: | ||
local highalch_data = mw.loadJsonData('Module:GEHighAlchs/data.json') | local highalch_data = mw.loadJsonData('Module:GEHighAlchs/data.json') | ||
local ptitle = mw.title.getCurrentTitle() | local ptitle = mw.title.getCurrentTitle() | ||
local ns = ptitle.nsText | local ns = ptitle.nsText | ||
Line 24: | Line 21: | ||
local _noted = ' <span class="dropsline-noted">(noted)</span>' | local _noted = ' <span class="dropsline-noted">(noted)</span>' | ||
local coins_priceString = "%s | local coins_priceString = "%s Pkp" | ||
local other_priceString = "%s | local other_priceString = "%s Pkp" | ||
--bg, txt, sort; acceptable non-quantity rarity names | --bg, txt, sort; acceptable non-quantity rarity names | ||
Line 78: | Line 73: | ||
end | end | ||
end | end | ||
function sigfig(n, f) | function sigfig(n, f) | ||
f = math.floor(f-1) | f = math.floor(f-1) | ||
Line 85: | Line 81: | ||
local v = n / (10^(m-f)) | local v = n / (10^(m-f)) | ||
v = math.floor(v + 0.5) * 10^(m-f) | v = math.floor(v + 0.5) * 10^(m-f) | ||
return v | return v | ||
end | end | ||
p.sigfig = sigfig | p.sigfig = sigfig | ||
p.commas = commas | p.commas = commas | ||
-- Function to adjust rarity based on donator rank | |||
function adjust_rarity(rarity_value, adjustment) | |||
if not rarity_value or not tonumber(rarity_value) then return nil end | |||
local adjusted_value = 1 / ((1 / rarity_value) * (1 - adjustment)) | |||
return adjusted_value | |||
end | |||
-- Function to generate adjusted rarity cells | |||
function generate_donator_rarity_cells(rarity_value) | |||
local adjustments = { | |||
['Normal Donator'] = 0.15, | |||
['Super Donator'] = 0.25, | |||
['Extreme Donator'] = 0.30, | |||
['Legendary Donator'] = 0.35, | |||
['Royal Donator'] = 0.40 | |||
} | |||
local cells = {} | |||
for rank, adjustment in pairs(adjustments) do | |||
local adjusted_rarity = adjust_rarity(rarity_value, adjustment) | |||
if adjusted_rarity then | |||
local rarity_text = string.format('1/%d', math.floor(adjusted_rarity)) | |||
table.insert(cells, rarity_text) | |||
else | |||
table.insert(cells, 'N/A') | |||
end | |||
end | |||
return cells | |||
end | |||
function p.main(frame) | function p.main(frame) | ||
Line 95: | Line 119: | ||
local frameArgs = frame.args | local frameArgs = frame.args | ||
local name,namenotes, | local name,namenotes, | ||
quantity,quantitynotes, | quantity,quantitynotes, | ||
Line 124: | Line 147: | ||
local _smwname = params.default_to(args.smwname,gemwname) | local _smwname = params.default_to(args.smwname,gemwname) | ||
local cleanedName | local cleanedName | ||
local dropVers = '' | local dropVers = '' | ||
Line 141: | Line 163: | ||
local smwname = cleanedName | local smwname = cleanedName | ||
if dropVers ~= '' then | if dropVers ~= '' then | ||
smwname = cleanedName..'#'..dropVers | smwname = cleanedName..'#'..dropVers | ||
end | end | ||
Line 157: | Line 178: | ||
rarity = params.ucflc(rarity) | rarity = params.ucflc(rarity) | ||
else | else | ||
rarity_value = rarity:gsub(',','') | rarity_value = rarity:gsub(',','') | ||
local rv1, rv2 = string.match(rarity_value, '([%d%.]+)/([%d%.]+)') | local rv1, rv2 = string.match(rarity_value, '([%d%.]+)/([%d%.]+)') | ||
if rv1 and rv2 then | if rv1 and rv2 then | ||
Line 171: | Line 192: | ||
alt_rarity = params.ucflc(alt_rarity) | alt_rarity = params.ucflc(alt_rarity) | ||
else | else | ||
alt_rarity_value = alt_rarity:gsub(',','') | alt_rarity_value = alt_rarity:gsub(',','') | ||
local rv1, rv2 = string.match(alt_rarity_value, '([%d%.]+)/([%d%.]+)') | local rv1, rv2 = string.match(alt_rarity_value, '([%d%.]+)/([%d%.]+)') | ||
if rv1 and rv2 then | if rv1 and rv2 then | ||
Line 185: | Line 206: | ||
local alch = yesno(args.alch or 'yes', false) | local alch = yesno(args.alch or 'yes', false) | ||
local cached_dropdata = droppeditem_data[smwname] | local cached_dropdata = droppeditem_data[smwname] | ||
local cached_alch = nil | local cached_alch = nil | ||
Line 227: | Line 235: | ||
gemw = false | gemw = false | ||
elseif isCoins then | elseif isCoins then | ||
valueInfo = { | valueInfo = { | ||
alch = { | alch = { | ||
Line 239: | Line 246: | ||
} | } | ||
else | else | ||
if alch then | if alch then | ||
if cached_alch ~= nil then | if cached_alch ~= nil then | ||
valueInfo.alch = { | valueInfo.alch = { | ||
Line 248: | Line 253: | ||
} | } | ||
elseif gemw then | elseif gemw then | ||
local hasgealch, gealchval = pcall(f_gealch,gemwname) | local hasgealch, gealchval = pcall(f_gealch,gemwname) | ||
if hasgealch then | if hasgealch then | ||
Line 260: | Line 264: | ||
end | end | ||
if not valueInfo.alch.has then | if not valueInfo.alch.has then | ||
alch = false | |||
end | end | ||
end | end | ||
if gemw then | if gemw then | ||
if geprice_frombulk ~= nil then | if geprice_frombulk ~= nil then | ||
Line 287: | Line 279: | ||
end | end | ||
local image,image_n | local image,image_n | ||
if isCoins then | if isCoins then | ||
Line 302: | Line 291: | ||
image = '[[File:Bank filler.png|link=Nothing|alt=This does not exist.]]' | image = '[[File:Bank filler.png|link=Nothing|alt=This does not exist.]]' | ||
else | else | ||
image = mw.ustring.format('[[File: | image = mw.ustring.format('[[File:%s|alt=%s: %s drops %s with rarity %s%s in quantity %s]]', image_n, name, image_n, title, name, rollstext, rarity, quantity) | ||
end | end | ||
local rdt = string.lower(args.rdt or '') == 'yes' | local rdt = string.lower(args.rdt or '') == 'yes' | ||
local ret = p._main(name, | local ret = p._main(name, | ||
altname,namenotes, | altname,namenotes, | ||
Line 321: | Line 308: | ||
approx,rolls) | approx,rolls) | ||
local cats = '' | local cats = '' | ||
local onMain = ns == '' or ns == 'RuneScape' | local onMain = ns == '' or ns == 'RuneScape' | ||
Line 330: | Line 316: | ||
end | end | ||
function p._main(name, | function p._main(name, | ||
altname,namenotes, | altname,namenotes, | ||
Line 343: | Line 328: | ||
rdt,useSmw, | rdt,useSmw, | ||
approx, rolls) | approx, rolls) | ||
local total, alchtotal, vsort, vasort, _h, _l | local total, alchtotal, vsort, vasort, _h, _l | ||
quantity, _h, _l = qty(quantity, isNothing) | quantity, _h, _l = qty(quantity, isNothing) | ||
Line 350: | Line 334: | ||
total = total or 'Not sold' | total = total or 'Not sold' | ||
end | end | ||
if type(vsort) ~= 'number' then | if type(vsort) ~= 'number' then | ||
vsort = 0 | vsort = 0 | ||
Line 360: | Line 342: | ||
end | end | ||
if #quantitynotes > 3 then | if #quantitynotes > 3 then | ||
quantity = quantity..quantitynotes | quantity = quantity..quantitynotes | ||
end | end | ||
local rare_class, rare_sort | local rare_class, rare_sort | ||
if rarity_value == | if rarity_value == nil then | ||
rare_class, rare_sort = unpack(rarities[rarity:lower()] or rarities._default) | rare_class, rare_sort = unpack(rarities[rarity:lower()] or rarities._default) | ||
elseif rarity_value == false then | elseif rarity_value == false then | ||
Line 387: | Line 367: | ||
local _r = rarity | local _r = rarity | ||
local hasRowwideVersion = false | local hasRowwideVersion = false | ||
local tblVers = frameArgs.version | local tblVers = frameArgs.version | ||
local versionKey = 'DEFAULT' | local versionKey = 'DEFAULT' | ||
if params.has_content(tblVers) then | if params.has_content(tblVers) then | ||
versionKey = tblVers | versionKey = tblVers | ||
end | end | ||
if params.has_content(monVers) then | if params.has_content(monVers) then | ||
versionKey = monVers | versionKey = monVers | ||
hasRowwideVersion = true | hasRowwideVersion = true | ||
Line 402: | Line 379: | ||
local quantityClassOverride = isNothing and 'table-na' or nil | local quantityClassOverride = isNothing and 'table-na' or nil | ||
local ret = mw.html.create('tr') | local ret = mw.html.create('tr') | ||
:css('text-align','center') | :css('text-align','center') | ||
:tag('td') | :tag('td') | ||
:addClass('inventory-image') | :addClass('inventory-image') | ||
:wikitext(image) | :wikitext(image) | ||
:done() | :done() | ||
:tag('td') | :tag('td') | ||
:css('text-align','left') | :css('text-align','left') | ||
:addClass('item-col') | :addClass('item-col') | ||
:wikitext(string.format(' | :wikitext(string.format('%s',name,altname,#namenotes > 3 and namenotes or '')) | ||
:done() | :done() | ||
:tag('td') | :tag('td') | ||
:addClass(quantityClassOverride) | :addClass(quantityClassOverride) | ||
Line 424: | Line 396: | ||
:done() | :done() | ||
local rarity_cell = ret:tag('td') | local rarity_cell = ret:tag('td') | ||
local rarity_span = rarity_cell:tag('span') | local rarity_span = rarity_cell:tag('span') | ||
Line 464: | Line 435: | ||
end | end | ||
-- | -- Adjusted rarity for donator ranks | ||
local donator_rarity_cells = generate_donator_rarity_cells(rarity_value) | |||
for _, donator_rarity in ipairs(donator_rarity_cells) do | |||
ret:tag('td') | |||
:wikitext(donator_rarity) | |||
:addClass(rare_class) | |||
:attr('title', rollstext .. tilde .. 'Adjusted rarity for donator rank') | |||
end | |||
local ge_td = ret:tag('td') | local ge_td = ret:tag('td') | ||
local ge_td_title, ge_td_content, alch_td_title, alch_td_content | local ge_td_title, ge_td_content, alch_td_title, alch_td_content | ||
if isNothing then | if isNothing then | ||
ge_td_content = 'N/A' | ge_td_content = 'N/A' | ||
Line 504: | Line 471: | ||
if ge_td_content == nil then | if ge_td_content == nil then | ||
ge_td_content = 'Not sold' | ge_td_content = 'Not sold' | ||
ge_td_title = 'This item cannot be traded on the | ge_td_title = 'This item cannot be traded on the Trading Post.' | ||
ge_td:addClass('table-na'):css('text-decoration', 'underline dotted') | ge_td:addClass('table-na'):css('text-decoration', 'underline dotted') | ||
end | end | ||
Line 511: | Line 478: | ||
ge_td:wikitext(ge_td_content):attr('title', ge_td_title) | ge_td:wikitext(ge_td_content):attr('title', ge_td_title) | ||
local onMain = ns == '' or ns == 'RuneScape' | local onMain = ns == '' or ns == 'RuneScape' | ||
local unrecognizedDropVersionCategory = '' | local unrecognizedDropVersionCategory = '' | ||
if onMain and useSmw and isNothing ~= true then | if onMain and useSmw and isNothing ~= true then | ||
local smw_sub = {} | local smw_sub = {} | ||
dropFrom = pgTitle | dropFrom = pgTitle | ||
Line 528: | Line 492: | ||
end | end | ||
local smw_json = { | local smw_json = { | ||
['Dropped item']=smwname, | ['Dropped item']=smwname, | ||
Line 556: | Line 519: | ||
function qty(quantity, isNothing) | function qty(quantity, isNothing) | ||
if string.lower(quantity) == 'varies' then | if string.lower(quantity) == 'varies' then | ||
return 'Varies' | return 'Varies' | ||
Line 564: | Line 526: | ||
return 'Unknown' | return 'Unknown' | ||
end | end | ||
quantity = mw.ustring.gsub(quantity,'[-—]','–') | quantity = mw.ustring.gsub(quantity,'[-—]','–') | ||
:gsub('%s','') | :gsub('%s','') | ||
:gsub('%(noted%)','$n') | :gsub('%(noted%)','$n') | ||
local vals = mw.text.split(quantity,'[,;]') | local vals = mw.text.split(quantity,'[,;]') | ||
local low = 2147483648 | local low = 2147483648 | ||
local high = 0 | local high = 0 | ||
local numstr = {} | local numstr = {} | ||
for i, v in ipairs(vals) do | for i, v in ipairs(vals) do | ||
local clean = v:gsub('$n','') | local clean = v:gsub('$n','') | ||
if mw.ustring.find(v,'–') then | if mw.ustring.find(v,'–') then | ||
local splitvals = mw.text.split(clean,'–') | local splitvals = mw.text.split(clean,'–') | ||
local a = tonumber(splitvals[1]) | local a = tonumber(splitvals[1]) | ||
local b = tonumber(splitvals[2]) | local b = tonumber(splitvals[2]) | ||
if a > b then | if a > b then | ||
a,b = b,a | a,b = b,a | ||
Line 618: | Line 568: | ||
end | end | ||
end | end | ||
if #numstr > 11 then | if #numstr > 11 then | ||
local mid = math.floor(#numstr/2) | local mid = math.floor(#numstr/2) | ||
numstr[mid] = '<br/>'..numstr[mid] | numstr[mid] = '<br/>'..numstr[mid] | ||
end | end | ||
numstr = table.concat(numstr,'; ') | numstr = table.concat(numstr,'; ') | ||
if not numstr:find('%d') then | if not numstr:find('%d') then | ||
return 'Unknown', price | return 'Unknown', price | ||
Line 636: | Line 581: | ||
function get_total(value,qhigh,qlow) | function get_total(value,qhigh,qlow) | ||
if not value or string.lower(value) == 'unknown' then | if not value or string.lower(value) == 'unknown' then | ||
return value | return value | ||
end | end | ||
if tonumber(value) and tonumber(value) < 0 then | if tonumber(value) and tonumber(value) < 0 then | ||
return false | return false | ||
end | end | ||
if not tonumber(value) and not value:find('%d') then | if not tonumber(value) and not value:find('%d') then | ||
return false | return false | ||
end | end | ||
value = mw.ustring.gsub(value,'[-—]','–') | value = mw.ustring.gsub(value,'[-—]','–') | ||
:gsub('%s','') | :gsub('%s','') | ||
local vals = mw.text.split(value,'[,;]') | local vals = mw.text.split(value,'[,;]') | ||
local low = 2147483648 | local low = 2147483648 | ||
local high = 0 | local high = 0 | ||
for i, v in ipairs(vals) do | for i, v in ipairs(vals) do | ||
local clean = v:gsub('$n','') | local clean = v:gsub('$n','') | ||
if mw.ustring.find(v,'–') then | if mw.ustring.find(v,'–') then | ||
local splitvals = mw.text.split(clean,'–') | local splitvals = mw.text.split(clean,'–') | ||
local a = tonumber(splitvals[1]) | local a = tonumber(splitvals[1]) | ||
local b = tonumber(splitvals[2]) | local b = tonumber(splitvals[2]) | ||
if a > b then | if a > b then | ||
a,b = b,a | a,b = b,a | ||
Line 716: | Line 642: | ||
end | end | ||
function categories(...) | function categories(...) | ||
local name,quantity,rarity = unpack(...) | local name,quantity,rarity = unpack(...) | ||
Line 723: | Line 648: | ||
quantity = quantity:lower() | quantity = quantity:lower() | ||
if name:find('clue scroll') then | if name:find('clue scroll') then | ||
ret = ret .. ' | ret = ret .. '' | ||
end | end | ||
if rarity == nil or rarity == '' or rarity:lower() == 'unknown' then | if rarity == nil or rarity == '' or rarity:lower() == 'unknown' then | ||
ret = ret .. ' | ret = ret .. '' | ||
end | end | ||
if quantity:find('Unknown') then | if quantity:find('Unknown') then | ||
ret = ret .. ' | ret = ret .. '' | ||
end | end | ||
return ret | return ret |
Latest revision as of 00:44, 4 April 2024
Documentation for this module may be created at Module:DropsLine/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 yesno = require('Module:Yesno')
local var = mw.ext.VariablesLua
-- precalculated cached data
local droppeditem_data = mw.loadJsonData('Module:DropsLine/itemData.json')
local geprices_data = mw.loadJsonData('Module:GEPrices/data.json')
local highalch_data = mw.loadJsonData('Module:GEHighAlchs/data.json')
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' }
}
function get_rarity_class(val)
for i,v in ipairs(rarities_class) do
curr = v
if val >= v[1] then
break
end
end
return curr[2]
end
function commas(n)
if tonumber(n) then
return lang:formatNum(tonumber(n))
else
return n
end
end
function expr(t)
local noerr, val = pcall(mw.ext.ParserFunctions.expr, t)
if noerr then
return tonumber(val)
else
return false
end
end
function sigfig(n, f)
f = math.floor(f-1)
if n == 0 then return 0 end
local m = math.floor(math.log10(n))
f = math.max(m, f)
local v = n / (10^(m-f))
v = math.floor(v + 0.5) * 10^(m-f)
return v
end
p.sigfig = sigfig
p.commas = commas
-- Function to adjust rarity based on donator rank
function adjust_rarity(rarity_value, adjustment)
if not rarity_value or not tonumber(rarity_value) then return nil end
local adjusted_value = 1 / ((1 / rarity_value) * (1 - adjustment))
return adjusted_value
end
-- Function to generate adjusted rarity cells
function generate_donator_rarity_cells(rarity_value)
local adjustments = {
['Normal Donator'] = 0.15,
['Super Donator'] = 0.25,
['Extreme Donator'] = 0.30,
['Legendary Donator'] = 0.35,
['Royal Donator'] = 0.40
}
local cells = {}
for rank, adjustment in pairs(adjustments) do
local adjusted_rarity = adjust_rarity(rarity_value, adjustment)
if adjusted_rarity then
local rarity_text = string.format('1/%d', math.floor(adjusted_rarity))
table.insert(cells, rarity_text)
else
table.insert(cells, 'N/A')
end
end
return cells
end
function p.main(frame)
local args = frame:getParent().args
local frameArgs = frame.args
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.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)
local cleanedName
local dropVers = ''
if _smwname:match(' ?%(%d%)$') then
cleanedName, dropVers = mw.ustring.match(gemwname, '^(.-) ?(%(%d%))$')
elseif _smwname:match(' ?%(p%+*%)$') then
cleanedName, dropVers = mw.ustring.match(_smwname, '^(.-) ?(%(p%+*%))$')
elseif _smwname:match('%#') then
cleanedName, dropVers = mw.ustring.match(_smwname, '^(.-)%#([%w%s%(%)]+)$')
else
cleanedName = mw.ustring.gsub(_smwname, ' %(%d%)$', '')
end
cleanedName = mw.text.trim(cleanedName)
dropVers = mw.text.trim(dropVers)
local smwname = cleanedName
if dropVers ~= '' then
smwname = cleanedName..'#'..dropVers
end
local useSmw = true
if params.has_content(args.smw) then
useSmw = args.smw:lower() ~= 'no'
end
if params.has_content(frameArgs.smw) then
useSmw = frameArgs.smw:lower() ~= 'no'
end
local rarity_value
if rarities[rarity:lower()] then
rarity = params.ucflc(rarity)
else
rarity_value = rarity:gsub(',','')
local rv1, rv2 = string.match(rarity_value, '([%d%.]+)/([%d%.]+)')
if rv1 and rv2 then
rarity = commas(rv1) .. '/' .. commas(rv2)
rarity_value = rv1/rv2
else
rarity_value = expr(rarity)
end
end
local alt_rarity_value
if rarities[alt_rarity:lower()] then
alt_rarity = params.ucflc(alt_rarity)
else
alt_rarity_value = alt_rarity:gsub(',','')
local rv1, rv2 = string.match(alt_rarity_value, '([%d%.]+)/([%d%.]+)')
if rv1 and rv2 then
alt_rarity = commas(rv1) .. '/' .. commas(rv2)
alt_rarity_value = rv1/rv2
else
alt_rarity_value = expr(alt_rarity)
end
end
quantity = mw.ustring.lower(quantity)
local gemw = yesno(args.gemw or 'yes', false)
local alch = yesno(args.alch or 'yes', false)
local cached_dropdata = droppeditem_data[smwname]
local cached_alch = nil
if type(cached_dropdata) == 'table' then
if cached_dropdata[1] ~= nil and cached_dropdata[2] ~= nil then
cached_alch = cached_dropdata[2]
elseif cached_dropdata[1] ~= nil then
cached_dropdata = cached_dropdata[1]
if type(cached_dropdata) == 'boolean' then
elseif type(cached_dropdata) == 'number' then
cached_alch = cached_dropdata
end
end
end
local geprice_frombulk = geprices_data[gemwname]
if not (type(geprice_frombulk) == 'number' and geprice_frombulk > 0) then
geprice_frombulk = nil
end
if cached_alch == nil then
cached_alch = highalch_data[gemwname]
if not (type(cached_alch) == 'number' and cached_alch > -1) then
cached_alch = nil
end
end
if isNothing then
gemw = false
elseif isCoins then
valueInfo = {
alch = {
has = true,
value = 1
},
ge = {
has = true,
value = 1
}
}
else
if alch then
if cached_alch ~= nil then
valueInfo.alch = {
has = true,
value = cached_alch
}
elseif gemw then
local hasgealch, gealchval = pcall(f_gealch,gemwname)
if hasgealch then
if gealchval > -1 then
valueInfo.alch = {
has = true,
value = tonumber(gealchval)
}
end
end
end
if not valueInfo.alch.has then
alch = false
end
end
if gemw then
if geprice_frombulk ~= nil then
valueInfo.ge = {
has = true,
value = geprice_frombulk
}
else
gemw = false
end
end
end
local image,image_n
if isCoins then
image_n = coins_image(quantity)
else
image_n = params.default_to(args.image or args.Image, name .. '.png')
image_n = mw.ustring.gsub(image_n, '#.+$', '.png')
end
if image_n:lower() == 'no' or params.is_empty(args.name or args.Name) then
image = ''
elseif isNothing then
image = '[[File:Bank filler.png|link=Nothing|alt=This does not exist.]]'
else
image = mw.ustring.format('[[File:%s|alt=%s: %s drops %s with rarity %s%s in quantity %s]]', image_n, name, image_n, title, name, rollstext, rarity, quantity)
end
local rdt = string.lower(args.rdt or '') == 'yes'
local ret = p._main(name,
altname,namenotes,
quantity,quantitynotes,
rarity,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)
local cats = ''
local onMain = ns == '' or ns == 'RuneScape'
if onMain and useSmw then
cats = categories{name,quantity,rarity}
end
return ret..cats
end
function p._main(name,
altname,namenotes,
quantity,quantitynotes,
rarity,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)
local total, alchtotal, vsort, vasort, _h, _l
quantity, _h, _l = qty(quantity, isNothing)
if valueInfo.ge.has then
total, vsort, totalavg = get_total(valueInfo.ge.value,_h,_l)
total = total or 'Not sold'
end
if type(vsort) ~= 'number' then
vsort = 0
end
if type(vasort) ~= 'number' then
vasort = 0
end
if #quantitynotes > 3 then
quantity = quantity..quantitynotes
end
local rare_class, rare_sort
if rarity_value == nil 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 = ''
if rolls then
rollstext = rolls .. ' × '
rare_sort = rare_sort / rolls
rare_class = get_rarity_class(math.min(1/rare_sort,0.99))
end
local tilde = ''
if approx then
tilde = '~'
end
local _r = rarity
local hasRowwideVersion = false
local tblVers = frameArgs.version
local versionKey = 'DEFAULT'
if params.has_content(tblVers) then
versionKey = tblVers
end
if params.has_content(monVers) then
versionKey = monVers
hasRowwideVersion = true
end
local quantityClassOverride = isNothing and 'table-na' or nil
local ret = mw.html.create('tr')
:css('text-align','center')
:tag('td')
:addClass('inventory-image')
:wikitext(image)
:done()
:tag('td')
:css('text-align','left')
:addClass('item-col')
:wikitext(string.format('%s',name,altname,#namenotes > 3 and namenotes or ''))
:done()
:tag('td')
:addClass(quantityClassOverride)
:attr('data-sort-value',_h)
:wikitext(quantity)
:done()
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
-- Adjusted rarity for donator ranks
local donator_rarity_cells = generate_donator_rarity_cells(rarity_value)
for _, donator_rarity in ipairs(donator_rarity_cells) do
ret:tag('td')
:wikitext(donator_rarity)
:addClass(rare_class)
:attr('title', rollstext .. tilde .. 'Adjusted rarity for donator rank')
end
local ge_td = ret:tag('td')
local ge_td_title, ge_td_content, alch_td_title, alch_td_content
if isNothing then
ge_td_content = 'N/A'
ge_td_title = 'This does not exist.'
ge_td:addClass('table-na'):css('text-decoration', 'underline dotted')
alch_td_content = 'N/A'
alch_td_title = 'This does not exist.'
alch_td:addClass('table-na'):css('text-decoration', 'underline dotted')
elseif isCoins then
local coinsStr = lang:plural(vsort, '', 's')
ge_td_title = mw.ustring.format(coins_priceString, total, coinsStr)
ge_td_content = total
alch_td_title = mw.ustring.format(coins_priceString, total, coinsStr)
alch_td_content = total
else
if valueInfo.ge.has then
ge_td_title = mw.ustring.format(other_priceString, commas(valueInfo.ge.value), lang:plural(valueInfo.ge.value, '', 's'))
ge_td_content = total
end
if valueInfo.alch.has then
alch_td_title = mw.ustring.format(other_priceString, commas(valueInfo.alch.value), lang:plural(valueInfo.alch.value, '', 's'))
alch_td_content = alchtotal
end
if ge_td_content == nil then
ge_td_content = 'Not sold'
ge_td_title = 'This item cannot be traded on the Trading Post.'
ge_td:addClass('table-na'):css('text-decoration', 'underline dotted')
end
end
ge_td:wikitext(ge_td_content):attr('title', ge_td_title)
local onMain = ns == '' or ns == 'RuneScape'
local unrecognizedDropVersionCategory = ''
if onMain and useSmw and isNothing ~= true then
local smw_sub = {}
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,
['Drop Value'] = valueInfo.alch.value or 0,
['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 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
quantity = mw.ustring.gsub(quantity,'[-—]','–')
:gsub('%s','')
:gsub('%(noted%)','$n')
local vals = mw.text.split(quantity,'[,;]')
local low = 2147483648
local high = 0
local numstr = {}
for i, v in ipairs(vals) do
local clean = v:gsub('$n','')
if mw.ustring.find(v,'–') then
local splitvals = mw.text.split(clean,'–')
local a = tonumber(splitvals[1])
local b = tonumber(splitvals[2])
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
if #numstr > 11 then
local mid = math.floor(#numstr/2)
numstr[mid] = '<br/>'..numstr[mid]
end
numstr = table.concat(numstr,'; ')
if not numstr:find('%d') then
return 'Unknown', price
end
return numstr, high, low
end
function get_total(value,qhigh,qlow)
if not value or string.lower(value) == 'unknown' then
return value
end
if tonumber(value) and tonumber(value) < 0 then
return false
end
if not tonumber(value) and not value:find('%d') then
return false
end
value = mw.ustring.gsub(value,'[-—]','–')
:gsub('%s','')
local vals = mw.text.split(value,'[,;]')
local low = 2147483648
local high = 0
for i, v in ipairs(vals) do
local clean = v:gsub('$n','')
if mw.ustring.find(v,'–') then
local splitvals = mw.text.split(clean,'–')
local a = tonumber(splitvals[1])
local b = tonumber(splitvals[2])
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
function categories(...)
local name,quantity,rarity = unpack(...)
local ret = ''
name = name:lower()
quantity = quantity:lower()
if name:find('clue scroll') then
ret = ret .. ''
end
if rarity == nil or rarity == '' or rarity:lower() == 'unknown' then
ret = ret .. ''
end
if quantity:find('Unknown') then
ret = ret .. ''
end
return ret
end
return p