local currtb = require('Module:CurrencyTrailblazer Region')._amount_badge
local dpl = require('Module:DPLlua')
local geprices = mw.loadJsonData('Module:GEPrices/data.json')
local p = {}
function p.main(frame)
-- TODO move to helper function
local a_an_arrargs = {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
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 i_loargs[region] == 'ecumenical keyauto' then
auto = auto .. tb(region)
if options.ecumenical ~= nil then
else
price = 61500
ret:tag('td'):wikitext(tb(region) .. ' ' .. args[region])
else
price = 0end
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)
price = geprices[item] or alchprice or 0
ret:tag('td'):wikitext(tb(required))
end
if notargs['playable'] price== '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
elseif args['playable'] == 'No' then
rarity = tonumber(rarity)
if notargs['incompletable'] rarity== '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
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
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
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
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
|