Module:Sandbox/User:Habblet/Get drop info
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Sandbox/User:Habblet/Get drop info/doc
-- <nowiki>
local line = require('Module:ItemDropsLine')._main
local yesno = require('Module:Yesno')
local purge = require('Module:Purge')._purge
local p = {}
local _comimg = '<span class="drops-combat" style="margin-left:0.3em;">[[File:Multicombat.png|link=Combat level|frameless|20px]]</span>'
local _thvimg = '<span class="drops-thieving" style="margin-left:0.3em;">[[File:Thieving-icon.png|link=Thieving|frameless|20px]]</span>'
local _hunimg = '<span class="drops-hunter" style="margin-left:0.3em;">[[File:Hunter-icon.png|link=Hunter|frameless|20px]]</span>'
local _farimg = '<span class="drops-farming" style="margin-left:0.3em;">[[File:Farming-icon.png|link=|frameless|20px]]</span>'
local _rewimg = '<span class="drops-reward" style="margin-left:0.3em;">[[File:Casket.png|link=|frameless|20px|Reward]]</span>'
local rewimg = '<span class="drops-reward" style="margin-left:0.3em;">[[File:%s|link=|frameless|20px|%s]]</span>'
local rewsrcs = mw.loadData('Module:get drop info/rewards')
local memberstring = {
yes = 'yes',
[true] = 'yes',
['true'] = 'yes',
no = 'no',
[false] = 'no',
['false'] = 'no',
both = 'both',
['?'] = '?',
['n/a'] = 'n/a'
}
function p.main(frame)
return p._main(frame:getParent().args)
end
function p.test(i)
return p._main({item = i})
end
function p._main(args)
local item = args.item or args[1]
local smwitem
if item then
local cleanedName = item
local dropVers = ''
if item:match(' %(%d%)$') then
cleanedName, dropVers = mw.ustring.match(item, '^(.-) (%(%d%))$')
elseif item:match('%#') then
cleanedName, dropVers = mw.ustring.match(item, '^(.-)%#([%w%s%(%)]+)$')
end
if dropVers ~= nil and dropVers ~= '' then
smwitem = cleanedName .. '#' .. dropVers
end
else
item = mw.title.getCurrentTitle().text
end
if not smwitem then
smwitem = item
end
local difrdt = '[[Dropped item from RDT::'..smwitem..']]'
local q = {
'[[Dropped item::'..smwitem..']]',
'?Dropped item text',
'?Drop from#-',
'?Loot from#-',
'?Hunted from#-',
'?Produce from#-',
'?Reward from#-',
'?Name Notes',
'?Drop Quantity',
'?Quantity High',
'?Quantity Low',
'?Rarity',
'?Rarity Notes',
'?RarityNote Ref',
limit = args.limit or 100,
sort = args.sort,
order = args.order
}
local smwdata = mw.smw.ask(q)
if not smwdata then
return ":''No drop sources found. To force an update, click "
..purge('dml-'..mw.uri.anchorEncode(item), 'here', 'span')
..".''[[Category:Empty drop lists]]"
end
local ret = {}
local hasRefs = false
if smwdata then
for i,v in ipairs(smwdata) do
if v['RarityNote Ref'] then
hasRefs = true
end
for j,u in ipairs(makeLines(item, v) or {}) do
table.insert(ret, u)
end
end
end
local t = mw.html.create('table')
t :addClass('wikitable sortable item-drops autosort=4,a')
:css('text-align', 'center')
:tag('tr')
:tag('th'):wikitext('Source'):done()
:tag('th'):wikitext('Level'):done()
:tag('th'):wikitext('Quantity'):done()
:tag('th'):wikitext('Rarity'):addClass('drops-rarity-header'):done()
:tag('th'):wikitext('Members'):done()
for i,v in ipairs(ret) do
t:node(v)
end
local text = {
"<div class=\"seealso\">This list was created dynamically. For help, see [[Template:Dropping monsters list/FAQ|the FAQ]].</div>\n",
"<div class=\"seealso\">To force an update of this list, click ", purge('dml-'..mw.uri.anchorEncode(item), 'here', 'span'), ".</div>\n",
"<div class=\"seealso\">For an exhaustive list of all known sources for this item, see <span class='plainlinks'>[", tostring(mw.uri.fullUrl('Special:Ask', {q=q[1], po = '?Drop Quantity\n?Rarity', p = { mainlabel = 'Monster', format = 'table'}, limit = 500})), " here]</span> (<span class='plainlinks'>[", tostring(mw.uri.fullUrl('Special:Ask', {q=q[1]..' OR '..difrdt, po = '?Drop Quantity\n?Rarity', p = { mainlabel = 'Monster', format = 'table'}, limit = 500})), " include RDT]</span>).</div>\n",
tostring(t)
}
if hasRefs then
local refList = mw.getCurrentFrame():getParent():extensionTag( 'references', '', {group='dr'} )
table.insert(text, refList)
end
return table.concat(text, '')
end
function makeLines(item, data)
-- iterate through different drop from parameters, get variant names
local srcs = {drop=data['Drop from'],loot=data['Loot from'],hunter=data['Hunted from'],produce=data['Produce from'],reward=data['Reward from']}
local srcsTable = {}
for i,v in pairs(srcs) do
if type(v) == 'string' then
table.insert(srcsTable, {dtype=i,src=v})
elseif type(v) == 'table' then
for _,k in pairs(v) do
table.insert(srcsTable, {dtype=i,src=k})
end
end
end
-- iterate through found variants, get stats for each
local srcsData, srcsDataGr = {}, {}
local _found = false
for _,v in ipairs(srcsTable) do
local qs = {'[['..v['src']..']]','?Is members only','?All Is members only'}
local members, level, levelsort, img
local initfound = false
if v['dtype'] == 'drop' then
table.insert(qs, '?Combat level')
table.insert(qs, '?All Combat level')
local smwdata = mw.smw.ask(qs)
smwdata = smwdata[1]
if smwdata then
level = smwdata['Combat level'] or smwdata['All Combat level'] or 'Not available'
members = smwdata['Is members only'] or smwdata['All Is members only'] or '?'
img = _comimg
levelsort = smwdata['Combat level'] or smwdata['All Combat level'] or -1
_found = true
initfound = true
end
elseif v['dtype'] == 'loot' then
table.insert(qs, '?Thieving level')
table.insert(qs, '?All Thieving level')
local smwdata = mw.smw.ask(qs)
smwdata = smwdata[1]
if smwdata then
level = smwdata['Thieving level'] or smwdata['All Thieving level'] or 'Not available'
members = smwdata['Is members only'] or smwdata['All Is members only'] or '?'
img = _thvimg
levelsort = smwdata['Thieving level'] or smwdata['All Thieving level'] or 99
_found = true
initfound = true
end
elseif v['dtype'] == 'hunter' then
table.insert(qs, '?Hunter level')
table.insert(qs, '?All Hunter level')
local smwdata = mw.smw.ask(qs)
smwdata = smwdata[1]
if smwdata then
level = smwdata['Hunter level'] or smwdata['All Hunter level'] or 'Not available'
members = smwdata['Is members only'] or smwdata['All Is members only'] or '?'
img = _hunimg
levelsort = smwdata['Hunter level'] or smwdata['All Hunter level'] or -1
_found = true
initfound = true
end
elseif v['dtype'] == 'produce' then
table.insert(qs, '?Farming level')
table.insert(qs, '?All Farming level')
local smwdata = mw.smw.ask(qs)
smwdata = smwdata[1]
if smwdata then
level = smwdata['Farming level'] or smwdata['All Farming level'] or 'Not available'
members = smwdata['Is members only'] or smwdata['All Is members only'] or '?'
img = _farimg
levelsort = smwdata['Farming level'] or smwdata['All Farming level'] or -1
_found = true
initfound = true
end
elseif v['dtype'] == 'reward' then
local smwdata = mw.smw.ask(qs)
smwdata = smwdata[1]
if smwdata then
level = 'N/A'
members = smwdata['Is members only'] or smwdata['All Is members only'] or '?'
img = _rewimg
levelsort = -1000
_found = true
initfound = true
if rewsrcs[v['src']] then
level = rewsrcs[v['src']][1]
img = string.format(rewimg, rewsrcs[v['src']][2], v['src'] )
end
end
end
if initfound then
if type(level) == 'table' then
levelsort = level[1]
level = table.concat(level, ', ')
end
if v['dtype'] == 'loot' then
levelsort = 100 - levelsort
end
if type(members) == 'table' then
members = memberstring.both
else
members = memberstring[members] or memberstring['?']
end
local noteref = data['RarityNote Ref'] or false
local cleanSrc = v['src']
local splitSrc = mw.text.split(v['src'], '%#')
if #splitSrc == 2 then
splitSrc[2] = splitSrc[2]:gsub('_', ' ')
cleanSrc = string.format('%s|%s <span class="beast-version">%s</span>', v['src'], splitSrc[1], splitSrc[2])
end
--[=[local lvlVers = string.match(partSrc, '#[%s_]*%d+$') or string.match(partSrc, '#[lL]evel[%s_]%d+$')
if lvlVers then
-- multiple versions that only differ in level
local baseMon = partSrc:gsub(lvlVers, '')
local cleanVers = lvlVers:gsub('[%D]', '')
local group = baseMon..v['dtype']..members
if not srcsDataGr[group] then
srcsDataGr[group] = {}
end
table.insert(srcsDataGr[group], {bmon=baseMon,link=lvlVers,vers=cleanVers,src=cleanSrc,dtype=v['dtype'],mems=members,lvl=level,lvlsort=levelsort,lvlimg=img})
else
table.insert(srcsData, {src=cleanSrc,dtype=v['dtype'],mems=members,lvl=level,lvlsort=levelsort,lvlimg=img})
end
--]=]
table.insert(srcsData, {src=cleanSrc,dtype=v['dtype'],mems=members,lvl=level,lvlsort=levelsort,lvlimg=img,ref=noteref})
end
end
if not _found then
return nil
end
local rows = {}
-- iterate through found sources, create line for each
for _, v in pairs(srcsData) do
-- name,namenotes,combat,cbnotes,dtype,quantity,quantitynotes,rarity,raritynotes,members,membersnotes,raritynoteref
local dropline = line({v['src'], data['Name Notes'], v['lvl'], v['lvlimg'], v['dtype'], data['Drop Quantity'], '', data['Rarity'], data['Rarity Notes'], v['mems'], '', v['ref']})
table.insert(rows, dropline)
end
-- iterate through found groups, create line for each
--[=[
for i,v in pairs(srcsDataGr) do
-- i = monster-dtype-members, v = table of version data tables
if #v > 1 then
-- more than 1 in group
local vers, lvl_l, lvl_h, gmems = {}, 9999, 0, v[1]['mems']
for _,k in ipairs(v) do
local versLink = '[['..k['bmon']..k['link']..'|'..k['vers']..']]'
vers[k['vers']] = versLink
if tonumber(k['lvl']) then
if k['lvl'] < lvl_l then lvl_l = k['lvl'] end
if k['lvl'] > lvl_h then lvl_h = k['lvl'] end
end
end
-- Create level display
local glevel
if lvl_h ~= 0 then
if lvl_l == lvl_h then
glevel = lvl_l
else
glevel = lvl_l..'-'..lvl_h
end
else
glevel = v[1]['lvl']
end
-- Sort versions
local keys, versSorted = {}, {}
for j in pairs(vers) do table.insert(keys, tonumber(j)) end
table.sort(keys)
for _,l in ipairs(keys) do table.insert(versSorted, vers[tostring(l)]) end
-- Create name/types string
local gname
if string.match(v[1]['link'], '[lL]evel') then
gname = '[['..v[1]['bmon']..']]'..' <span class="beast-version">Level: '..mw.text.listToText(versSorted, ', ', ', ')..'</span>'
else
gname = '[['..v[1]['bmon']..']]'..' <span class="beast-version">Version: '..mw.text.listToText(versSorted, ', ', ', ')..'</span>'
end
-- Generate line
local dropline = line({gname, data['Name Notes'], glevel, v[1]['lvlimg'], v[1]['lvlsort'], data['Drop Quantity'], '', data['Rarity'], data['Rarity Notes'], v[1]['mems'], ''})
table.insert(rows, dropline)
else
--only 1 in group
local dropline = line({v[1]['src'], data['Name Notes'], v[1]['lvl'], v[1]['lvlimg'], v[1]['lvlsort'], data['Drop Quantity'], '', data['Rarity'], data['Rarity Notes'], v[1]['mems'], ''})
end
end
--]=]
return rows
end
return p
-- </nowiki>