Anonymous

Module:Skills/Cartography: Difference between revisions

From Melvor Idle
Added discovery rewards & unlock requirements
(Swapped output of test to a table)
(Added discovery rewards & unlock requirements)
Line 6: Line 6:
local SkillData = GameData.skillData
local SkillData = GameData.skillData
local Items = require('Module:Items')
local Items = require('Module:Items')
local Common = require('Module:Common')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')


function p.convertAxialToXY(HexCoords)
function p.getPointOfInterest(name)
local Y = HexCoords.r + (HexCoords.q - (HexCoords.q % 2)) / 2
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do
local X = HexCoords.q
if POI.name == name then
return POI
end
end
return nil
end
 
function p.getHexByAxial(Q, R)
--Assume if R is nil that a pair was sent in
if R == nil then
R = Q.r
Q = Q.q
end
for i, hex in pairs(SkillData.Cartography.worldMaps[1].hexes) do
local coords = hex.coordinates
if coords.q == Q and coords.r == R then
return hex
end
end
return nil
end
 
function p.getHexByXY(X, Y)
local Q, R = p.convertXYToAxial(X, Y)
return p.getHexByAxial(Q, R)
end
 
function p.convertXYToAxial(X, Y)
--Assume that if Y is nil that a pair was sent in
if Y == nil then
Y = X.y
X = X.x
end
local Q = X
local R = Y - (X - (X % 2)) / 2
return Q, R
end
 
function p.convertAxialToXY(Q, R)
--Assume if r is nil that a pair was sent in
if R == nil then
R = Q.r
Q = Q.q
end
local Y = R + (Q - (Q % 2)) / 2
local X = Q
return X, Y
return X, Y
end
end


function p.test()
function p.test()
--WIP for building table of Points of Interest
--TODO:
-- Handle discoveryRewards
local POIs = {}
local POIs = {}
local POI_Strings = {}
local POI_Strings = {}
local tableStr = {}
local tableStr = {}
table.insert(tableStr, '{| class="wikitable sortable"')
table.insert(tableStr, '{| class="wikitable sortable"')
table.insert(tableStr, '\r\n|-\r\n!Name!!Type!!X!!Y!!Description')
table.insert(tableStr, '\r\n|-\r\n!colspan="2"|Name!!Type!!X!!Y!!Requirements!!Discovery Rewards!!Active Effect')
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do
for i, POI in pairs(SkillData.Cartography.worldMaps[1].pointsOfInterest) do
Line 37: Line 87:
for i, POI in pairs(POIs) do
for i, POI in pairs(POIs) do
local X, Y = p.convertAxialToXY(POI.coords)
local X, Y = p.convertAxialToXY(POI.coords)
local Hex = p.getHexByAxial(POI.coords)
table.insert(POI_Strings, POI.name..' ('..X..', '..Y..')')
table.insert(POI_Strings, POI.name..' ('..X..', '..Y..')')
table.insert(tableStr,'\r\n|-\r\n|')
table.insert(tableStr,'\r\n|-\r\n|')
table.insert(tableStr, POI.name)
table.insert(tableStr, Icons.Icon({POI.name, type='poi', notext='true', nolink='true'}))
table.insert(tableStr, '||'..POI.name)
table.insert(tableStr, '||'..POI.type)
table.insert(tableStr, '||'..POI.type)
table.insert(tableStr, '||'..X)
table.insert(tableStr, '||'..X)
table.insert(tableStr, '||'..Y)
table.insert(tableStr, '||'..Y)
table.insert(tableStr, '||'..POI.description)
--Add Requirements
table.insert(tableStr, '\r\n|')
local reqTable = {}
local HexReqs = Common.getRequirementString(Hex.requirements, '')
if HexReqs ~= '' then
table.insert(reqTable, HexReqs)
end
if POI.hidden ~= nil then
local POIReqs = Common.getRequirementString(POI.hidden.requirements, '')
if POIReqs ~= '' then
table.insert(reqTable, POIReqs)
end
end
table.insert(tableStr, table.concat(reqTable, '<br/>'))
--Add Discovery Rewards
table.insert(tableStr, '\r\n|')
if POI.discoveryRewards ~= nil then
local rewardTable = {}
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
table.insert(tableStr, table.concat(rewardTable,'<br/>'))
end
--TODO: Add Active Modifiers
table.insert(tableStr, '\r\n|')
end
end
Line 52: Line 141:
local n=0
local n=0
for k,v in pairs(POIs[1]) do
for k,v in pairs(SkillData.Cartography.worldMaps[1]) do
  n=n+1
  n=n+1
  keyset[n]=k
  keyset[n]=k
end
end
mw.logObject(POIs[1])
--mw.log(mw.text.jsonEncode(SkillData.Cartography.worldMaps[1].hexes))
return table.concat(tableStr, '')
return table.concat(tableStr, '')
end
end


return p
return p