4,683
edits
(Added Discovery Modifier column to POI table) |
(Added getDiscoveryRewardsTable for item sources from POIs) |
||
Line 105: | Line 105: | ||
end | end | ||
return reqTable | return reqTable | ||
end | |||
function p._getDiscoveryRewards(POI) | |||
local rewardTable = {} | |||
if POI.discoveryRewards ~= nil then | |||
if POI.discoveryRewards.gp ~= nil then | |||
table.insert(rewardTable, Icons.GP(POI.discoveryRewards.gp)) | |||
end | |||
if POI.discoveryRewards.sc ~= nil then | |||
table.insert(rewardTable, Icons.SC(POI.discoveryRewards.sc)) | |||
end | |||
if POI.discoveryRewards.items ~= nil then | |||
for j, reward in pairs(POI.discoveryRewards.items) do | |||
local item = Items.getItemByID(reward.id) | |||
local qty = reward.quantity | |||
table.insert(rewardTable, Icons.Icon({item.name, type='item', qty = qty})) | |||
end | |||
end | |||
end | |||
return rewardTable | |||
end | |||
function p.sortPOIByCoords(array) | |||
table.sort(array, function(a, b) | |||
local aX, aY = p.convertAxialToXY(a.coords) | |||
local bX, bY = p.convertAxialToXY(b.coords) | |||
if aX ~= bX then | |||
return aX < bX | |||
else | |||
return aY < bY | |||
end | |||
end) | |||
end | end | ||
Line 117: | Line 149: | ||
table.insert(POIs, POI) | table.insert(POIs, POI) | ||
end | end | ||
p.sortPOIByCoords(POIs) | |||
for i, POI in pairs(POIs) do | for i, POI in pairs(POIs) do | ||
Line 162: | Line 185: | ||
--Add Discovery Rewards | --Add Discovery Rewards | ||
table.insert(tableStr, '\r\n|') | table.insert(tableStr, '\r\n|') | ||
local rewardTable = p._getDiscoveryRewards(POI) | |||
table.insert(tableStr, table.concat(rewardTable,'<br/>')) | |||
--Add Discovery Modifiers | --Add Discovery Modifiers | ||
Line 196: | Line 204: | ||
return table.concat(tableStr, '') | return table.concat(tableStr, '') | ||
end | |||
function p._getDiscoveryRewardsTable(item) | |||
local POIs = {} | |||
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | |||
if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | |||
for i, reward in pairs(POI.discoveryRewards.items) do | |||
if reward.id == item.id then | |||
table.insert(POIs, POI) | |||
end | |||
end | |||
end | |||
end | |||
p.sortPOIByCoords(POIs) | |||
-- Build the table | |||
local resultTable = mw.html.create('table') | |||
resultTable:addClass('wikitable sortable') | |||
resultTable:tag('tr'):addClass('headerRow-0') | |||
:tag('th'):wikitext('Point of Interest') | |||
:tag('th'):wikitext('X') | |||
:tag('th'):wikitext('Y') | |||
:tag('th'):wikitext('Requirements') | |||
:tag('th'):wikitext('Discovery Rewards') | |||
for _, POI in ipairs(POIs) do | |||
local X, Y = p.convertAxialToXY(POI.coords) | |||
local tr = mw.html.create('tr') | |||
tr:tag('td'):wikitext(Icons.Icon({POI.name, type='poi'})) | |||
tr:tag('td'):wikitext(X) | |||
tr:tag('td'):wikitext(Y) | |||
tr:tag('td'):wikitext(table.concat(p._getPOIRequirements(POI), '<br/>')) | |||
tr:tag('td'):wikitext(table.concat(p._getDiscoveryRewards(POI), '<br/>')) | |||
resultTable:node(tr) | |||
end | |||
return tostring(resultTable) | |||
end | |||
function p.getDiscoveryRewardsTable(frame) | |||
local itemName = frame.args ~= nil and frame.args[1] or frame | |||
local item = Items.getItem(itemName) | |||
if item == nil then | |||
return Shared.printError('No item named "' .. itemName .. '" exists in the data module') | |||
end | |||
return '==POI Discovery Rewards==\n' .. p._getDiscoveryRewardsTable(item) | |||
end | |||
function p.testDiscoveryRewards() | |||
local testTable = {} | |||
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | |||
if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | |||
local item = Items.getItemByID(POI.discoveryRewards.items[1].id) | |||
table.insert(testTable, p._getDiscoveryRewardsTable(item)) | |||
end | |||
end | |||
return table.concat(testTable) | |||
end | end | ||