Module:DetectivePassiveList: Difference between revisions

offload much of the search, screen, and format functions to the new ProfessionList module, so they work the same for all table
m (detective icon)
(offload much of the search, screen, and format functions to the new ProfessionList module, so they work the same for all table)
Line 1:
require('strict')
require('Module:Mw.html extension')
local lang = mw.getContentLanguage()
local param = require( 'Module:Paramtest' )
local currencyplist = require('Module:CurrencyProfessionList')
local rts = require('Module:RecipeTreeSearch')
local lang = mw.getContentLanguage()
 
local p = {}
Line 10:
function p.main()
local queryString = '[[Category:Detective]] AND [[Category:Pages with activities]]'
-- returns only directly needed parameter needed for the row,
-- other parameters are determined by subqueries of chained pages
local queryfunction = {screenFunction(item)
return item.passive
'[[Variant of::Forensics (activity)||Evidence Filing||Interrogation||Stakeout]]',
end
'?Variant of #- = variant',
'?Profession Level A = lvl',
local results = plist.generate_recipe_table(queryString,screenFunction)
'? #- = name',
'?Image #- = Image',
'?Activity XP = XP',
'?Activity duration = duration',
'?Activity coins = coins',
'?Activity input #- = material',
'?Skill node name = product',
'sort = Profession Level A',
'limit = 500'
}
local results = mw.smw.ask(query)
results = p.formatResults(results)
Line 35 ⟶ 25:
--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>'
 
end
 
-- makes the html for the cells containing currency directly
-- Replaces nil with an "unknown" cell
local function currency_cell(amount)
if not amount then
return mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:attr{ colspan = '10' }
:wikitext("''unknown''")
:done()
end
return currency._cell(amount, { html = 'yes' })
end
 
-- do calculations and determine strings to go in cells
function p.formatResults(results)
--simple check for nil results
if results==nil or results[1]==nil then
return nil
end
-- iterate through products
for _, item in ipairs(results) do
item.materialpotion = item.material or ''
-- work out if the product is coins or items
item.usesPotion = string.find(item.variant==product,'Forensics (activity)')
if not item.usesPotion then
item.profit = item.coins
-- it it uses a potion, need to account for that in profit
else
item.buy = 0
item.potion = (item.materials and item.materials[1] and item.materials[1].name) or ''
if item.usesPotion then
item.profit = item.coins and item.buyPrice and item.coins - item.buyPrice
--shamelessley lifted from Module:Products
local shopPriceQuery = '[[:+]][[Sold item::' .. item.material .. ']]|?Shop buy price=data|mainlabel=' .. item.material
local shopPriceResult = mw.smw.ask(shopPriceQuery) or {}
local shopPrice = 0
if shopPriceResult[1] and shopPriceResult[1]["data"] then
shopPrice = tonumber(shopPriceResult[1]["data"]) or 0
else
item.buy = nil
end
item.buy = shopPrice * 0.005
end
 
item.profit = item.coins and item.buy and item.coins - item.buy
-- no downtime for passives
item.productPerHour = item.duration and 1 / item.duration * 3600
 
-- properties per hour
item.XPPerHourxpPerHour = item.XPxp and item.productPerHour and math.floor(item.XPxp * item.productPerHour)
item.profitPerHour = item.coinsprofit and item.productPerHour and math.floor(item.profit * item.productPerHour)
end
 
Line 92 ⟶ 62:
-- make the table
function p.displayTable(results)
--simple check for nil results
if results==nil or results[1]==nil then
return 'No data found for table'
end
local out = mw.html.create('table')
:addClass('wikitable sortable')
Line 103 ⟶ 79:
:done()
:tag('th')
:attr{ colspan = '3' }
:wikitext('Materials')
:done()
Line 112 ⟶ 89:
:attr{ colspan = '10' }
:wikitext('Payment')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Profit')
:done()
:tag('th')
Line 128 ⟶ 101:
:done()
:done()
 
local unknown_value_cell = mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:wikitext("''unknown''")
 
for i, item in ipairs(results) do
Line 138 ⟶ 106:
--level
:IF(item.lvllevel)
:tag('td')
:css{ ['text-align'] = 'center' }
:wikitext(item.lvllevel)
:done()
:ELSE()
:node(plist.unknown_value_edit_cell(item.pageName,1))
:node(unknown_value_cell)
:END()
-- activity
:node(plist.two_column_image_text(item.pageName,item.pageImage,item.pageName,item.pageName))
:tag('td')
 
:css{ ['border-right'] = '0', ['text-align'] = 'right', ['max-width'] = '100px' }
:addClass('plinkt-link no-border')
:attr{ ['data-sort-value'] = item.name }
:wikitext('[[' .. item.Image .. '|link=' .. item.name .. '|30x30px]]')
:done()
:tag('td')
:addClass('plinkt-link no-border')
:wikitext('[[' .. item.name .. ']]')
:done()
-- materials
:IF(item.usesPotion)
:node(plist.three_column_image_text(item.potion,item.output[1].quantity,'File:'..item.potion..'.png',item.potion,item.potion))
:tag('td')
:node(plist.currency_cell(item.buyPrice))
:wikitext('0.005 &times; [[File:' .. item.material .. '.png|link=' .. item.material .. '|30x30px]] [[' .. item.material .. ']]')
:done()
:node(currency_cell(item.buy))
:node(currency_cell(item.coins))
:ELSE()
:tag('td')
:addClass('table-na')
:attr{ colspan = '2113' }
:wikitext('N/A')
:done()
:END()
-- payment
-- products (coins or items)
:node(currency_cellIF(item.profit)coins)
:node(plist.currency_cell(item.coins))
:ELSE()
:node(plist.unknown_value_edit_cell(item.pageName,10))
:END()
-- productsprofit per hour (coins or items)
:node(plist.currency_cell(item.profitPerHour))
-- XP
:IF(item.XPxp)
:tag('td')
:wikitext(item.XPxp and lang:formatNum(tonumber(item.XPxp)))
:done()
:ELSE()
:node(plist.unknown_value_edit_cell(item.pageName,1))
:node(unknown_value_cell)
:END()
-- XP per hour
:IF(item.XPPerHourxpPerHour)
:tag('td')
:wikitext(item.XPPerHourxpPerHour and lang:formatNum(tonumber(item.XPPerHourxpPerHour)))
:done()
:ELSE()
:node(plist.unknown_value_cell(1))
:END()
 
21,295

edits