Home
Random
Log in
Settings
About Brighter Shores Wiki
Disclaimers
Search
Editing
Module:ItemSources
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local hc = require('Module:Param Parse').has_content local pcp = require('Module:Profession clickpic')._main local params = require('Module:Paramtest') local purge = require('Module:Purge')._purge local lang = mw.language.getContentLanguage() local commas = function (n) return lang:formatNum(tonumber(n)) end function p.main(frame) local args = frame:getParent().args return p._main(args) end --class, sort local frequencies = { always = { 'table-bg-blue', 1 }, common = { 'table-bg-green', 16 }, uncommon = { 'table-bg-yellow', 64 }, rare = { 'table-bg-orange', 256 }, ['very rare'] = { 'table-bg-red', 1024 }, conditional = { 'table-bg-pink', 2048 }, random = { 'table-bg-pink', 4096 }, varies = { 'table-bg-pink', 4096 }, _default = { 'table-bg-gray', 65536 } } -- arbitrary numbers local frequencies2 = { { 1, 'table-bg-blue' }, { 1/16, 'table-bg-green' }, { 1/64, 'table-bg-yellow' }, { 1/256, 'table-bg-orange' }, { 1/1024, 'table-bg-red' } } -- supporting function for number => colour local function get_frequency_class(val) local curr for i,v in ipairs(frequencies2) do curr = v if val >= v[1] then break end end return curr[2] end local function expr(t) local noerr, val = pcall(mw.ext.ParserFunctions.expr, t) if noerr then return tonumber(val) else return false end end local function parseDropJson(out, source, drop) local dropJSON = mw.text.jsonDecode(drop or '{}') local q2 = { '[[:' .. dropJSON['Dropped from'] .. ']]', '?Profession Requirement A=professionreq', } local sourcesmwdata = mw.smw.ask(q2) for _, v in ipairs(sourcesmwdata) do local professionreq = v.professionreq or 'Unknown' local professionlevel = professionreq if professionreq ~= 'Unknown' then local profession, level = v.professionreq:match("([^,]+),([^,]+)") professionlevel = pcp(profession, level) end local frequency = dropJSON['Frequency'] local frequency_value if frequencies[string.lower(tostring(frequency))] then frequency = params.ucflc(frequency) else frequency_value = frequency:gsub(',','') --temp place to put this without overriding frequency local rv1, rv2 = string.match(frequency_value, '([%d%.]+)/([%d%.]+)') if rv1 and rv2 then frequency = commas(rv1) .. '/' .. commas(rv2) frequency_value = rv1/rv2 else frequency_value = expr(frequency) end end local freq_class, freq_sort = '', nil if frequency_value == nil then freq_class, freq_sort = unpack(frequencies[string.lower(tostring(frequency))] or frequencies._default) elseif frequency_value == false then freq_class, freq_sort = unpack(frequencies._default) else freq_sort = 1/frequency_value freq_class = get_frequency_class(frequency_value) end out:tag('tr') :tag('td'):wikitext(source.source):done() :tag('td'):wikitext(professionlevel):done() :tag('td'):wikitext(dropJSON['Dropped quantity']):done() :tag('td'):wikitext(frequency) :attr('data-sort-value', freq_sort) :addClass(freq_class) :done() :done() end return out end function p._main(args) local item = args[1] or mw.title.getCurrentTitle().fullText local q = { '[[Dropped item::' .. item .. ']]', '?Dropped from=source', '?Drop JSON' } local sourcessmwdata = mw.smw.ask(q) if not sourcessmwdata then return ":''No sources found. To force an update, click " ..purge('source-'..mw.uri.anchorEncode(item), 'here', 'span') ..".''[[Category:Empty source lists]]" end local out = mw.html.create('table') :addClass('wikitable sortable autosort=4,a align-center-2 align-center-3 align-center-4') :tag('tr') :tag('th'):wikitext('Source'):done() :tag('th'):wikitext('Level'):done() :tag('th'):wikitext('Quantity'):done() :tag('th'):wikitext('Frequency'):done() :done() for _, source in ipairs(sourcessmwdata) do local drop = source['Drop JSON'] if type(drop) == 'string' then out = parseDropJson(out, source, drop) elseif type(drop) == 'table' then for _, v in ipairs(drop) do out = parseDropJson(out, source, v) end end end return out end return p
Summary:
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see
Brighter Shores:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Templates used on this page:
Template:DependencyList
(
edit
)
Template:Documentation
(
edit
)
Template:Extension DPL
(
edit
)
Template:ItemSources
(
edit
)
Template:ItemSources/doc
(
edit
)
Template:No documentation
(
edit
)
Template:PageType
(
edit
)
Module:Array
(
edit
)
Module:DPLlua
(
edit
)
Module:DependencyList
(
edit
)
Module:Documentation
(
edit
)
Module:ItemSources
(
edit
)
Module:ItemSources/doc
(
edit
)
Module:Param Parse
(
edit
)
Module:Paramtest
(
edit
)
Module:Tooltip
(
edit
)
Module:Yesno
(
view source
) (semi-protected)
This page is a member of a hidden category:
Category:Pages using DynamicPageList3 parser function