432
edits
(Added getDiscoveryRewardsTable for item sources from POIs) |
No edit summary |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 12: | Line 12: | ||
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | ||
if POI.id == id then | if POI.id == id then | ||
return POI | |||
end | |||
end | |||
return nil | |||
end | |||
function p.getPointOfInterestByXY(X, Y) | |||
local hex = p.getHexByXY(X, Y) | |||
if hex == nil then | |||
return nil | |||
end | |||
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | |||
if (POI.coords.q == hex.coordinates.q and | |||
POI.coords.r == hex.coordinates.r) then | |||
return POI | return POI | ||
end | end | ||
Line 137: | Line 151: | ||
end | end | ||
end) | end) | ||
end | |||
function p.getHexMasteryBonusTable(frame) | |||
-- Build table header | |||
local resultTable = mw.html.create('table') | |||
resultTable:addClass('wikitable stickyHeaders') | |||
resultTable:tag('tr'):addClass('headerRow-0') | |||
:tag('th'):wikitext('Hexes Mastered') | |||
:tag('th'):wikitext('Passive Bonuses') | |||
:tag('th'):wikitext('Rewards') | |||
local masteryBonuses = Shared.shallowClone(SkillData.Cartography.worldMaps[1].masteryBonuses) | |||
table.sort(masteryBonuses, function(a, b) return a.masteredHexes < b.masteredHexes end) | |||
for i, bonus in ipairs(masteryBonuses) do | |||
-- Populate passive bonuses & rewards cell text | |||
local modText, rewardTextPart = nil, {} | |||
if bonus.modifiers ~= nil and not Shared.tableIsEmpty(bonus.modifiers) then | |||
modText = Constants.getModifiersText(bonus.modifiers, true, false) | |||
end | |||
if bonus.items ~= nil then | |||
for k, itemDef in ipairs(bonus.items) do | |||
local item = Items.getItemByID(itemDef.id) | |||
if item ~= nil then | |||
local expIcon = Icons.getExpansionIcon(itemDef.id) | |||
table.insert(rewardTextPart, expIcon .. Icons.Icon({item.name, type='item', qty = itemDef.quantity})) | |||
end | |||
end | |||
end | |||
if bonus.pets ~= nil then | |||
for k, petID in ipairs(bonus.pets) do | |||
local pet = GameData.getEntityByID('pets', petID) | |||
if pet ~= nil then | |||
local expIcon = Icons.getExpansionIcon(petID) | |||
table.insert(rewardTextPart, expIcon .. Icons.Icon({pet.name, type='pet'})) | |||
end | |||
end | |||
end | |||
local row = mw.html.create('tr') | |||
row:tag('td'):wikitext(Shared.formatnum(bonus.masteredHexes)) | |||
if modText == nil then | |||
row:tag('td') | |||
:addClass('table-na') | |||
:wikitext('None') | |||
else | |||
row:tag('td'):wikitext(modText) | |||
end | |||
if Shared.tableIsEmpty(rewardTextPart) then | |||
row:tag('td') | |||
:addClass('table-na') | |||
:wikitext('None') | |||
else | |||
row:tag('td'):wikitext(table.concat(rewardTextPart, '\n')) | |||
end | |||
resultTable:node(row) | |||
end | |||
return tostring(resultTable) | |||
end | end | ||
Line 206: | Line 277: | ||
end | end | ||
function p._getDiscoveryRewardsTable( | function p._getDiscoveryRewardsTable(items) | ||
local POIs = {} | local POIs = {} | ||
for i, POI in | for i, POI in ipairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do | ||
if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | ||
for i, reward in | for i, reward in ipairs(POI.discoveryRewards.items) do | ||
if reward.id == item.id then | for j, item in ipairs(items) do | ||
if reward.id == item.id then | |||
table.insert(POIs, POI) | |||
break | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
end | |||
if POIs[1] == nil then | |||
return '' | |||
end | end | ||
p.sortPOIByCoords(POIs) | p.sortPOIByCoords(POIs) | ||
Line 243: | Line 321: | ||
function p.getDiscoveryRewardsTable(frame) | function p.getDiscoveryRewardsTable(frame) | ||
local | local itemNames = frame.args ~= nil and frame.args[1] or frame | ||
local item = Items.getItem(itemName) | local items = {} | ||
if | for itemName in string.gmatch(itemNames, "[^,]*") do | ||
return Shared.printError('No | item = Items.getItem(itemName) | ||
if item ~= nil then | |||
table.insert(items, item) | |||
end | |||
end | |||
if #items == nil then | |||
return Shared.printError('No items found in game data for: "' .. itemNames .. '"') | |||
end | |||
local resultTable = p._getDiscoveryRewardsTable(items) | |||
if resultTable == '' then | |||
return '' | |||
else | |||
return '==POI Discovery Rewards==\n' .. resultTable | |||
end | |||
end | |||
function p.hex(frame) | |||
-- Default behavior, when no coords supplied | |||
if (frame == nil or frame.args['x'] == nil or frame.args['y'] == nil) then | |||
return 'Hex' | |||
end | |||
local X = tonumber(frame.args['x']) | |||
local Y = tonumber(frame.args['y']) | |||
if X == nil or Y == nil then | |||
return '<invalid XY format>' | |||
elseif X < 0 or Y < 0 or X > 31 or Y > 29 or (Y == 29 and X % 2 == 0) then | |||
return '<out of range (' .. X .. ',' .. Y .. ')>' | |||
end | end | ||
-- | |||
local noicon = frame.args['noicon'] or false | |||
local coords = '<span>(' .. X .. ',' .. Y .. ')</span>' | |||
local hex = p.getPointOfInterestByXY(X, Y) | |||
-- nil means just a normal hex | |||
if hex == nil or hex['id'] == nil or noicon then | |||
return coords | |||
end | |||
-- Valid POI so consider decorations | |||
local notext = frame.args['notext'] or false | |||
local nolink = frame.args['nolink'] or false | |||
local poi_icon = Icons.Icon({hex['name'], type='poi', notext=notext or nil, nolink=nolink or nil, size='25'}) | |||
return '<span>' .. poi_icon .. ' ' .. coords .. '</span>' | |||
end | end | ||
Line 257: | Line 372: | ||
if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | if POI.discoveryRewards ~= nil and POI.discoveryRewards.items ~= nil then | ||
local item = Items.getItemByID(POI.discoveryRewards.items[1].id) | local item = Items.getItemByID(POI.discoveryRewards.items[1].id) | ||
table.insert(testTable, p._getDiscoveryRewardsTable(item)) | table.insert(testTable, p._getDiscoveryRewardsTable({item})) | ||
end | |||
end | |||
return table.concat(testTable) | |||
end | |||
function p.testHex() | |||
local testTable = {} | |||
for x = 0, 31 do | |||
for y = 0, 29 do | |||
if y == 29 and x % 2 == 1 then | |||
-- no tile here | |||
else | |||
item = p.hex({args={x=x, y=y}}) | |||
table.insert(testTable, item) | |||
end | |||
end | end | ||
end | end |
edits