Module:Average drop value/Sandbox: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(Created page with "local curr = require('Module:Currency')._amount local dpl = require('Module:DPLlua') local geprices = mw.loadJsonData('Module:GEPrices/data.json') local p = {} -- TODO move to helper function local a_an_arr = { a = true, e = true, i = true, o = true, u = true } function a_an(x) local _x = mw.text.truncate(string.lower(x), 1, '') if a_an_arr[_x] then return 'an' end return 'a' end function calcValue(item, lowqty, highqty, rarity, rolls, alchprice, options)...") |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
local |
local tb = require('Module:Trailblazer Region')._badge |
||
local dpl = require('Module:DPLlua') |
|||
local geprices = mw.loadJsonData('Module:GEPrices/data.json') |
|||
local p = {} |
local p = {} |
||
function p.main(frame) |
|||
-- TODO move to helper function |
|||
local |
local args = frame:getParent().args |
||
local orRegions = args['or'] or 'No' |
|||
a = true, |
|||
e = true, |
|||
local regions = {'misthalin', 'karamja', 'asgarnia', 'desert', 'fremennik', 'kandarin', 'morytania', 'tirannwn', 'wilderness', 'kourend'} |
|||
i = true, |
|||
o = true, |
|||
local ret = mw.html.create('tr') |
|||
u = true |
|||
mw.log(args[1]) |
|||
} |
|||
if args['incompletable'] == 'Yes' then |
|||
function a_an(x) |
|||
ret:tag('th'):wikitext(args[1]):addClass('table-bg-red') |
|||
local _x = mw.text.truncate(string.lower(x), 1, '') |
|||
else ret:tag('th'):wikitext(args[1]) |
|||
if a_an_arr[_x] then |
|||
return 'an' |
|||
end |
end |
||
mw.log(tostring(ret)) |
|||
return 'a' |
|||
local required = '' |
|||
end |
|||
local auto = '' |
|||
for _, region in ipairs(regions) do |
|||
function calcValue(item, lowqty, highqty, rarity, rolls, alchprice, options) |
|||
if args[region] ~= nil then |
|||
local avgqty = (tonumber(lowqty) + tonumber(highqty)) / 2 |
|||
if args[region] == 'Yes' then |
|||
local rar_good, price |
|||
if #required ~= 0 then |
|||
-- parse price |
|||
required = required .. '&' |
|||
local i_lo = item:lower() |
|||
end |
|||
if i_lo == 'brimstone key' and options.brimstone ~= nil then |
|||
required = required .. region |
|||
price = tonumber(mw.getCurrentFrame():preprocess('{{KDTValue}}')) |
|||
elseif args[region] == 'auto' then |
|||
auto = auto .. tb(region) |
|||
if options.ecumenical ~= nil then |
|||
else |
|||
price = 61500 |
|||
ret:tag('td'):wikitext(tb(region) .. ' ' .. args[region]) |
|||
else |
|||
end |
|||
end |
end |
||
end |
|||
if args['incompletable'] == 'Yes' then |
|||
ret:tag('td'):addClass('table-bg-red') |
|||
ret:tag('td'):addClass('table-bg-red') |
|||
else |
else |
||
ret:tag('td'):wikitext(auto) |
|||
price = geprices[item] or alchprice or 0 |
|||
ret:tag('td'):wikitext(tb(required)) |
|||
end |
end |
||
if |
if args['playable'] == 'Yes' then |
||
if args['incompletable'] == 'Yes' then |
|||
mw.log('0 price for '..item) |
|||
ret:tag('td'):wikitext(string.format('[[File:Yes check.svg|20px|link=|alt=Quest may be played without autocompletion]] Partially playable')):addClass('table-bg-red') |
|||
return 0 |
|||
else ret:tag('td'):wikitext(string.format('[[File:Yes check.svg|20px|link=|alt=Quest may be played without autocompletion]] Fully playable')) |
|||
end |
|||
-- parse rarity |
|||
if rarity:lower() == 'always' then |
|||
rarity = 1 |
|||
else |
|||
rarity = rarity:gsub(',', '') |
|||
rar_good, rarity= pcall(mw.ext.ParserFunctions.expr, rarity) |
|||
if not rar_good then |
|||
mw.log('0 rarity for '..item) |
|||
return 0 |
|||
end |
end |
||
elseif args['playable'] == 'No' then |
|||
rarity = tonumber(rarity) |
|||
if |
if args['incompletable'] == 'Yes' then |
||
ret:tag('td'):wikitext(string.format('[[File:X mark.svg|20px|link=|alt=Quest may not be played through]] Not completeable')):addClass('table-bg-red') |
|||
mw.log('0 rarity for '..item) |
|||
else ret:tag('td'):wikitext(string.format('[[File:X mark.svg|20px|link=|alt=Quest may not be played through]] Autocomplete only')) |
|||
return 0 |
|||
end |
end |
||
else |
|||
end |
|||
if args['incompletable'] == 'Yes' then |
|||
ret:tag('td'):wikitext(''):addClass('table-bg-red') |
|||
local val = price * avgqty * rarity * rolls |
|||
else ret:tag('td'):wikitext('') |
|||
mw.log(string.format('item %s: %s * %s * %s * %s = %s', item, price, lowqty, rarity, rolls, val)) |
|||
return val |
|||
end |
|||
function _DPLcontains(arr,s) |
|||
for k, v in ipairs(arr) do |
|||
if v == s then return true end |
|||
end |
|||
return false |
|||
end |
|||
function p.getDropData(mobs) |
|||
--used in [[Module:Bestiary]] too |
|||
local query = {} |
|||
local smw = {} |
|||
for i,v in ipairs(mobs) do |
|||
mw.log("dropData", v) |
|||
query = { |
|||
'[[Dropped from::'..v..']]', |
|||
'?Drop JSON', |
|||
limit = 500 |
|||
} |
|||
smw = mw.smw.ask(query) |
|||
mw.logObject(smw) |
|||
if smw and smw ~= {} and smw ~='' then |
|||
break |
|||
end |
end |
||
end |
end |
||
if args['incompletable'] == 'Yes' then |
|||
return smw |
|||
ret:tag('td'):wikitext(args['notes'] or ''):addClass('table-bg-red') |
|||
end |
|||
else ret:tag('td'):wikitext(args['notes'] or '') |
|||
function p.totalvalfromdata(data,itemOptions,category, categoryFilter, exclude, excludeFilter) |
|||
--used in [[Module:Bestiary]] too |
|||
if (not data) or data == {} or data =='' then |
|||
return '?' |
|||
end |
end |
||
local totalval = 0 |
|||
local options = itemOptions or {} |
|||
for i,v in ipairs(data) do |
|||
local j = mw.text.jsonDecode(v['Drop JSON'] or '{}') |
|||
if (not category) or _DPLcontains(categoryFilter,j['Dropped item']) then |
|||
if (not exclude) or (not _DPLcontains(excludeFilter,j['Dropped item'])) then |
|||
totalval = totalval + calcValue(j['Dropped item'], j['Quantity Low'], j['Quantity High'], j['Rarity'], j['Rolls'], j['Drop Value'], options) |
|||
end |
|||
end |
|||
end |
|||
return totalval |
|||
end |
|||
return tostring(ret) |
|||
function p.totalval(mobs, itemOptions, category, categoryFilter, exclude, excludeFilter) |
|||
local data = p.getDropData(mobs) |
|||
return p.totalvalfromdata(data,itemOptions,category, categoryFilter, exclude, excludeFilter) |
|||
end |
end |
||
function p.main(frame) |
|||
return p._main(frame, frame:getParent().args) |
|||
end |
|||
function p._main(frame, args) |
|||
local pageName = mw.title.getCurrentTitle().text |
|||
local mobroot = '' |
|||
local moblevel = '' |
|||
local mob = '' |
|||
local mobs = {} |
|||
--mobs serves as a list of fallbacks to get drop data, e.g. maybe smw does not find data for barbarian#level 8 because they are the generic barbarian drop, but will display the data from just barbarian if mobs is {'Barbarian#level 8', 'Barbarian'} |
|||
if args.mob or args[1] then |
|||
mob = args.mob or args[1] |
|||
mobroot, moblevel = mob:match('([^#]*)#?(.*)') |
|||
table.insert(mobs, mob) |
|||
table.insert(mobs, mobroot) |
|||
else |
|||
mob = pageName |
|||
mobroot = pageName |
|||
table.insert(mobs, pageName) |
|||
end |
|||
local mobname = mob |
|||
if args.mobname then |
|||
mobname = args.mobname |
|||
elseif moblevel ~= "" then |
|||
mobname = string.format('%s (%s)',mobroot, moblevel) |
|||
end |
|||
if mobroot ~= pageName then |
|||
mobname = string.format('[[%s|%s]]',mobroot,mobname) |
|||
end |
|||
local killname = args.killname or 'kill' |
|||
local itemOptions = { |
|||
brimstone = args.brimstone, |
|||
ecumenical = args.ecumenical |
|||
} |
|||
local categoryFilter = {} |
|||
local excludeFilter = {} |
|||
local catReportString = "" |
|||
if args.category then |
|||
categoryFilter = dpl.ask({ |
|||
namespace = '', |
|||
ignorecase = 'true', |
|||
category = args.category, |
|||
allowcachedresults = 'true' |
|||
}) |
|||
catReportString = 'counting only '..(args.category:lower())..' ' |
|||
end |
|||
if args.exclude then |
|||
excludeFilter = dpl.ask({ |
|||
namespace = '', |
|||
ignorecase = 'true', |
|||
category = args.exclude, |
|||
allowcachedresults = 'true' |
|||
}) |
|||
catReportString = catReportString..'excluding all '..(args.exclude:lower())..' ' |
|||
end |
|||
local totalval = p.totalval(mobs, itemOptions, args.category, categoryFilter, args.exclude, excludeFilter) |
|||
if args.round and totalval ~= '?' then |
|||
totalval = math.floor(totalval) |
|||
end |
|||
if totalval == '?' then |
|||
return '' |
|||
end |
|||
if args.raw then |
|||
return totalval |
|||
elseif args.brimstone ~= nil then |
|||
return string.format('The average %s %s while on a [[Konar]] task %sis worth %s.', mobname, killname, catReportString, curr(totalval, 'coins')) |
|||
elseif args.ecumenical ~= nil then |
|||
return string.format('The average %s %s while in the [[Wilderness God Wars Dungeon]] %sis worth %s.', mobname, killname, catReportString, curr(totalval, 'coins')) |
|||
else |
|||
return string.format('The average %s %s %sis worth %s.', mobname, killname, catReportString, curr(totalval, 'coins')) |
|||
end |
|||
end |
|||
return p |
return p |
Revision as of 00:12, 17 October 2024
Documentation for this module may be created at Module:Average drop value/Sandbox/doc
local tb = require('Module:Trailblazer Region')._badge
local p = {}
function p.main(frame)
local args = frame:getParent().args
local orRegions = args['or'] or 'No'
local regions = {'misthalin', 'karamja', 'asgarnia', 'desert', 'fremennik', 'kandarin', 'morytania', 'tirannwn', 'wilderness', 'kourend'}
local ret = mw.html.create('tr')
mw.log(args[1])
if args['incompletable'] == 'Yes' then
ret:tag('th'):wikitext(args[1]):addClass('table-bg-red')
else ret:tag('th'):wikitext(args[1])
end
mw.log(tostring(ret))
local required = ''
local auto = ''
for _, region in ipairs(regions) do
if args[region] ~= nil then
if args[region] == 'Yes' then
if #required ~= 0 then
required = required .. '&'
end
required = required .. region
elseif args[region] == 'auto' then
auto = auto .. tb(region)
else
ret:tag('td'):wikitext(tb(region) .. ' ' .. args[region])
end
end
end
if args['incompletable'] == 'Yes' then
ret:tag('td'):addClass('table-bg-red')
ret:tag('td'):addClass('table-bg-red')
else
ret:tag('td'):wikitext(auto)
ret:tag('td'):wikitext(tb(required))
end
if args['playable'] == 'Yes' then
if args['incompletable'] == 'Yes' then
ret:tag('td'):wikitext(string.format('[[File:Yes check.svg|20px|link=|alt=Quest may be played without autocompletion]] Partially playable')):addClass('table-bg-red')
else ret:tag('td'):wikitext(string.format('[[File:Yes check.svg|20px|link=|alt=Quest may be played without autocompletion]] Fully playable'))
end
elseif args['playable'] == 'No' then
if args['incompletable'] == 'Yes' then
ret:tag('td'):wikitext(string.format('[[File:X mark.svg|20px|link=|alt=Quest may not be played through]] Not completeable')):addClass('table-bg-red')
else ret:tag('td'):wikitext(string.format('[[File:X mark.svg|20px|link=|alt=Quest may not be played through]] Autocomplete only'))
end
else
if args['incompletable'] == 'Yes' then
ret:tag('td'):wikitext(''):addClass('table-bg-red')
else ret:tag('td'):wikitext('')
end
end
if args['incompletable'] == 'Yes' then
ret:tag('td'):wikitext(args['notes'] or ''):addClass('table-bg-red')
else ret:tag('td'):wikitext(args['notes'] or '')
end
return tostring(ret)
end
return p