Module:GathererList: Difference between revisions

m
add purge link
m (spacing around images)
m (add purge link)
(4 intermediate revisions by one other user not shown)
Line 1:
require('strict')
require('Module:Mw.html extension')
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local lang = mw.getContentLanguage()
local plist = require('Module:ProfessionList')
local purge = require('Module:Purge')._purge
 
local p = {}
Line 10:
function p.main()
local queryString = '[[Category:Gatherer]] 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 not item.passive
'[[Category:Gatherer]] AND [[~*(skill node)]]',
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',
'?Skill node name = product',
'?Activity input #- = material',
'sort = Profession Level A',
'limit = 500'
}
local results = mw.smw.ask(query)
 
results = p.formatResults(results)
 
Line 34 ⟶ 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
 
-- downtime is very important for gathering-type professions
--catch badly submitted data
-- initial values, it will be obvious if these get used
item.material = item.material or ''
item.productdowntime = item.product10000 or ''
item.Imagenodes = item.Image or ''1
-- these numbers are based roughly on how far the nodes are from a storage rift or shop or bank
-- price20s ofper resourceroom to traverse
-- duration and relocation times arent used for fisher, only respawn time and number of nodes
-- query is: there is a shop object page that has this item AND has buy price cannot be "N/A"
if string.find(item.pageName,'Globeplant') then
local query = mw.smw.ask('[[Sold item::' .. item.product .. ']][[Shop sell price::!~N/A]]|?Shop sell price=data|mainlabel=-')
item.downtime = 40
if type(query)=='table' then
item.nodes = 8
-- price is returned as a number
elseif string.find(item.pageName,'Dandelion') then
item.profit = tonumber(query[1].data) or 0
item.downtime = 20
else
item.nodes = 8
-- will return nil if the item is not in a shop, or if it is in a shop but can only be sold to the shop
elseif string.find(item.pageName,'Goat Horn') then
item.profit = nil
item.downtime = 60
end
item.nodes = 8
elseif string.find(item.pageName,'Apple') then
item.downtime = 80
item.nodes = 6
elseif string.find(item.pageName,'Leek') then
item.downtime = 40
item.nodes = 8
elseif string.find(item.pageName,'Haleberries') then
item.downtime = 50 -- portal back after depositing
item.nodes = 8
elseif string.find(item.pageName,'Rams Horn') then
item.downtime = 100
item.nodes = 8
elseif string.find(item.pageName,'Bitterfruit') then
item.downtime = 160 -- cannot be banked, must be sold
item.nodes = 8
elseif string.find(item.pageName,'Chestnut') then
item.downtime = 80
item.nodes = 6
elseif string.find(item.pageName,'Bone Spike') then
item.downtime = 0
item.nodes = 8
elseif string.find(item.pageName,'Tangfruit') then
item.downtime = 150 -- cannot be banked, must be sold
item.nodes = 6
elseif string.find(item.pageName,'Catkin') then
item.downtime = 60
item.nodes = 6
elseif string.find(item.pageName,'Femur Shard') then
item.downtime = 80
item.nodes = 8
elseif string.find(item.pageName,'Clover') then
item.downtime = 40
item.nodes = 8
elseif string.find(item.pageName,'Snake Scale') then
item.downtime = 60
item.nodes = 8
elseif string.find(item.pageName,'Orchid') then
item.downtime = 60
item.nodes = 8
elseif string.find(item.pageName,'Dock Leaf') then
item.downtime = 80 -- portal back after depositing
item.nodes = 8
elseif string.find(item.pageName,'Sage') then
item.downtime = 120 -- portal to deposit then run back
item.nodes = 6
elseif string.find(item.pageName,'Thistle') then
item.downtime = 100
item.nodes = 6
end
 
-- profitability
item.profitPerXPprofit = item.profit and item.XP and item.profit / item.XPsellPrice
-- products per hour
-- DOWNTIME VERY IMPORTANT FOR GATHERING TYPE PROFESSIONS
item.downtime = 60 -- THIS IS AN INITIAL GUESS, DO NOT USE THIS VALUE
item.batch = 24
item.productPerHourdurationEffective = item.duration and 1item.respawn /and (item.duration + item.downtimerespawn) / item.batch) * 3600nodes
item.productPerHour = item.durationEffective and math.floor(1 / (item.durationEffective + item.downtime / item.batch) * 3600)
item.productPerHourDropping = item.durationEffective and 1 / (item.durationEffective) * 3600
 
-- properties per hour
item.XPPerHourxpPerHour = item.XPxp and item.productPerHour and math.floor(item.XPxp * item.productPerHour)
item.xpPerHourDropping = item.xp and item.productPerHourDropping and math.floor(item.xp * item.productPerHourDropping)
item.profitPerHour = item.profit and item.productPerHour and math.floor(item.profit * item.productPerHour)
end
 
Line 90 ⟶ 125:
-- 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')
:tag('caption')
:wikitext('This list is updated dynamically. '..purge())
:done()
:tag('tr')
:tag('th')
:wikitext('[[File:GathererForager small icon.png|15px]] Level')
:done()
:tag('th')
:attr{ colspan = '2' }
:wikitext('Node')
:done()
:tag('th')
:attr{ colspan = '2' }
:wikitext('Gathering nodeTool')
:done()
:tag('th')
Line 120 ⟶ 168:
:tag('th')
:wikitext('XP/hr')
:done()
:tag('th')
:wikitext('XP/hr<br>(Discarding)')
: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 132 ⟶ 178:
--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()
-- gathering node
: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' }
:attr{ ['data-sort-value'] = IF(item.name }tool)
:wikitextnode(plist.two_column_image_text(item.tool,' [[File:' .. (item.Imagetool ..or '|link=' )..' (grade 1).png',(item.nametool or ''),(item..tool or '|30x30px]]')))
:doneELSE()
:tag('td')
:addClass('plinkttable-link no-borderna')
:attr{ colspan = '2' }
:wikitext('[[' .. item.name .. '|' .. item.product ..']]')
:donewikitext('N/A')
:done()
:END()
-- resource
:node(plist.two_column_image_text(item.product,'File:' .. item.product .. '.png',item.product,item.product))
:tag('td')
:css{ ['border-right'] = '0', ['text-align'] = 'right', ['max-width'] = '100px' }
:attr{ ['data-sort-value'] = item.product }
:wikitext('[[File:' .. item.product .. '.png|link=' .. item.product .. '|30x30px]]')
:done()
:tag('td')
:addClass('plinkt-link no-border')
:wikitext('[[' .. item.product .. ']]')
:done()
-- resource/hr
Line 169 ⟶ 209:
:done()
:ELSE()
:node(plist.unknown_value_edit_cell(item.pageName,1))
:node(unknown_value_cell)
:END()
-- economics
:node(plist.currency_cell(item.profit))
:node(plist.currency_cell(item.profitPerHour))
 
-- XP
:IF(item.XPxp)
:tag('td')
:wikitext(item.xp and lang:formatNum(tonumber(item.xp)))
:done()
:ELSE()
:node(plist.unknown_value_edit_cell(item.pageName,1))
:END()
-- XP per hour
:IF(item.xpPerHour)
:tag('td')
:wikitext(item.XPxpPerHour and lang:formatNum(tonumber(item.XPxpPerHour)))
:done()
:ELSE()
:node(plist.unknown_value_cell(1))
:END()
-- XP per hour
:IF(item.XPPerHourxpPerHourDropping)
:tag('td')
:wikitext(item.XPPerHourxpPerHourDropping and lang:formatNum(tonumber(item.XPPerHourxpPerHourDropping)))
:done()
:ELSE()
:node(plist.unknown_value_cell(1))
:END()
 
7,248

edits