|
|
(72 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| local p = {} | | local p = {} |
|
| |
| local params = require('Module:Paramtest')
| |
| local lang = mw.language.getContentLanguage() | | 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' }
| |
| }
| |
|
| |
|
| |
|
| | -- Function to get rarity class based on value |
| | local function get_rarity_class(val) |
| | 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' } |
| | } |
| | for i, v in ipairs(rarities_class) do |
| | if val >= v[1] then |
| | return v[2] |
| | end |
| | end |
| | return rarities_class[#rarities_class][2] -- default to the last rarity class |
| | end |
|
| |
|
| -- Params and defaults
| | -- Function to format numbers with commas |
| local name,namenotes,
| | local function commas(n) |
| quantity,quantitynotes,
| | if tonumber(n) then |
| rarity,alt_rarity,alt_rarity_endash, | | return lang:formatNum(tonumber(n)) |
| raritynotes,citation,monVers = params.defaults{
| | else |
| {args.name or args.Name,'Item'},
| | return n |
| {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 | | end |
| local approx = yesno(args.approx or args.Approx or 'no', false)
| | end |
| 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)
| |
|
| |
|
| | -- Main function |
| | function p.main(frame) |
| | local args = frame:getParent().args |
|
| |
|
| -- Table row | | local name = args.name or args.Name or 'Item' |
| local ret = p._main(name, | | local quantity = args.quantity or args.Quantity or 'Unknown' |
| altname,namenotes,
| | local rarity = args.rarity or args.Rarity or 'Unknown' |
| 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)
| |
|
| |
|
| | local output = string.format('|-\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n', name, quantity, rarity) |
|
| |
|
| | return mw.text.tag('tr', output) |
| | end |
|
| |
|
| | | return p |
| -- 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
| |