Module:Township: Difference between revisions

Fixed currencies not showing up in task list
m (Added Eternal Darkness season requirement)
(Fixed currencies not showing up in task list)
(7 intermediate revisions by 4 users not shown)
Line 162: Line 162:
education = 'Education',
education = 'Education',
storage = 'Storage',
storage = 'Storage',
worship = 'Worship'
worship = 'Worship',
fortification = 'Fortification'
}
}
local resourceText = function(resName, resType, quantity)
local resourceText = function(resName, resType, quantity)
local elemClass = (quantity < 0 and 'text-negative') or 'text-positive'
local elemClass = (quantity < 0 and 'text-negative') or 'text-positive'
local resIcon = Icons.Icon({resName, type=resType, notext=true})
local resIcon = Icons.Icon({resName, type=resType, notext=true})
return resIcon .. '&nbsp;<span class="' .. elemClass .. '">' .. Shared.numStrWithSign(quantity) .. '</span>'
return resIcon .. '&nbsp;<span class="' .. elemClass .. '">' .. Num.numStrWithSign(quantity) .. '</span>'
end
end


Line 257: Line 258:
end
end


-- Gets the Township level and population requirements for a tier
-- Gets the Township level or abyssalLevel, population and fortification requirements for a tier
-- Returns {population=X, level=X}
-- Returns {population=X, level=X} for non-abyssal tiers
function p._getTierRequirements(tier)
-- Returns {population=X, abyssalLevel=X, fortification=X} for abyssal tiers
return Township.populationForTier[tier]
function p._getTierRequirements(tier, abyssalTier)
local tierData = Township.populationForTier[tier]
if abyssalTier ~= nil then
local abyssalTierData = Shared.clone(Township.abyssalTierRequirements[abyssalTier + 1])
abyssalTierData.population = tierData.population
return abyssalTierData
else
return tierData
end
end
end


-- Returns a string containing the Township level and population requirements for a tier
-- Returns a string containing the Township level and population requirements for a tier
function p._getTierText(tier)
function p._getTierText(tier, abyssalTier)
local tierData = p._getTierRequirements(tier)
local realmID = (abyssalTier ~= nil and 'melvorItA:Abyssal' or 'melvorD:Melvor')
local tierData = p._getTierRequirements(tier, abyssalTier)
if tierData ~= nil then
if tierData ~= nil then
local tierText = Icons._SkillReq('Township', tierData.level, false)
local tierText = Icons._SkillReq('Township', tierData.abyssalLevel or tierData.level, false, realmID)
if tierData.population > 0 then
if tierData.population ~= nil and tierData.population > 0 then
tierText = tierText .. '<br/>' .. Icons.Icon({'Population', type='township', notext=true}) .. '&nbsp;' .. Shared.formatnum(tierData.population)
tierText = tierText .. '<br/>' .. Icons.Icon({'Population', type='township', notext=true}) .. '&nbsp;' .. Num.formatnum(tierData.population)
end
if tierData.fortification ~= nil and tierData.fortification > 0 then
tierText = tierText .. '<br/>' .. Icons.Icon({'Fortification', type='township', notext=true}) .. '&nbsp;' .. Num.formatnum(tierData.fortification) .. '%'
end
end
return tierText
return tierText
Line 315: Line 328:
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '\n|- class="headerRow-0"')
table.insert(resultPart, '\n|- class="headerRow-0"')
table.insert(resultPart, '\n!rowspan="2" colspan="2"| Biome\n!colspan="2"| Requirements')
table.insert(resultPart, '\n!rowspan="2" colspan="2"| Biome\n!colspan="3"| Requirements')
table.insert(resultPart, '\n|- class="headerRow-1"')
table.insert(resultPart, '\n|- class="headerRow-1"')
table.insert(resultPart, '\n! ' .. Icons.Icon({'Township', 'Level', type='skill', nolink=true}))
table.insert(resultPart, '\n! ' .. Icons.Icon({'Township', 'Level', type='skill', nolink=true}))
table.insert(resultPart, '\n! ' .. Icons.Icon({'Township', 'Population', img='Population', type='township', section='Population' }))
table.insert(resultPart, '\n! ' .. Icons.Icon({'Township', 'Population', img='Population', type='township', section='Population' }))
table.insert(resultPart, '\n! ' .. Icons.Icon({'Township', 'Forification', img='Fortification', type='township', section='Fortification' }))


for i, biome in ipairs(Township.biomes) do
for i, biome in ipairs(Township.biomes) do
local reqs = p._getTierRequirements(biome.tier)
local reqs = p._getTierRequirements(biome.tier, biome.abyssalTier)
local fortification = reqs.fortification or 0
table.insert(resultPart, '\n|-\n|class="table-img"| ' .. Icons.Icon({biome.name, type='biome', size=50, nolink=true, notext=true}))
table.insert(resultPart, '\n|-\n|class="table-img"| ' .. Icons.Icon({biome.name, type='biome', size=50, nolink=true, notext=true}))
table.insert(resultPart, '\n| ' .. biome.name)
table.insert(resultPart, '\n| ' .. biome.name)
table.insert(resultPart, '\n|style="text-align:right"| ' .. reqs.level)
table.insert(resultPart, '\n|style="text-align:right"| ' .. (reqs.abyssalLevel or reqs.level))
table.insert(resultPart, '\n|style="text-align:right" data-sort-value="' .. reqs.population .. '"| ' .. Shared.formatnum(reqs.population))
table.insert(resultPart, '\n|style="text-align:right" data-sort-value="' .. reqs.population .. '"| ' .. Num.formatnum(reqs.population))
table.insert(resultPart, '\n|style="text-align:right" data-sort-value="' .. fortification .. '"| ' .. Num.formatnum(fortification))
end
end
table.insert(resultPart, '\n|}')
table.insert(resultPart, '\n|}')
Line 342: Line 358:
local level = mw.html.create('tr'):addClass('sorttop')
local level = mw.html.create('tr'):addClass('sorttop')
local pop = mw.html.create('tr'):addClass('sorttop')
local pop = mw.html.create('tr'):addClass('sorttop')
local fort = mw.html.create('tr'):addClass('sorttop')


header:tag('th')
header:tag('th')
Line 350: Line 367:
pop:tag('th')
pop:tag('th')
:wikitext(Icons.Icon({'Township', 'Population', img='Population', type='township', section='Population' }))
:wikitext(Icons.Icon({'Township', 'Population', img='Population', type='township', section='Population' }))
fort:tag('th')
:wikitext(Icons.Icon({'Township', 'Fortification', img='Fortification', type='township', section='Fortification' }))
for _, biome in ipairs(Township.biomes) do
for _, biome in ipairs(Township.biomes) do
local reqs = p._getTierRequirements(biome.tier)
local reqs = p._getTierRequirements(biome.tier, biome.abyssalTier)
header:tag('th')
header:tag('th')
:wikitext(Icons.Icon({biome.name, type='biome', notext=true, nolink=true}).. '<br/>' .. biome.name)
:wikitext(Icons.Icon({biome.name, type='biome', notext=true, nolink=true}).. '<br/>' .. biome.name)
level:tag('td')
level:tag('td')
:wikitext(Num.formatnum(reqs.level))
:wikitext(Num.formatnum((reqs.abyssalLevel or reqs.level)))
pop:tag('td')
pop:tag('td')
:wikitext(Num.formatnum(reqs.population))
:wikitext(Num.formatnum(reqs.population))
fort:tag('td')
:wikitext(Num.formatnum((reqs.fortification or 0)))
end
end
Line 364: Line 385:
tbl:node(level)
tbl:node(level)
tbl:node(pop)
tbl:node(pop)
tbl:node(fort)


for _, _building in ipairs(p._sortedBuildings(false)) do
for _, _building in ipairs(p._sortedBuildings(false)) do
Line 429: Line 451:
table.insert(resultPart, '\n|class="table-img"' .. rowSpan .. '| ' .. Icons.Icon({buildingName, type='building', notext=true, size=50}))
table.insert(resultPart, '\n|class="table-img"' .. rowSpan .. '| ' .. Icons.Icon({buildingName, type='building', notext=true, size=50}))
table.insert(resultPart, '\n' .. rowSpanOnly .. '| ' .. Icons.getExpansionIcon(building.id) .. Icons.Icon({buildingName, type='building', noicon=true}))
table.insert(resultPart, '\n' .. rowSpanOnly .. '| ' .. Icons.getExpansionIcon(building.id) .. Icons.Icon({buildingName, type='building', noicon=true}))
table.insert(resultPart, '\n|' .. 'data-sort-value="' .. building.tier .. '"' .. rowSpan .. '| ' .. (p._getTierText(building.tier) or ''))
table.insert(resultPart, '\n|' .. 'data-sort-value="' .. building.tier .. '"' .. rowSpan .. '| ' .. (p._getTierText(building.tier, building.abyssalTier) or ''))
table.insert(resultPart, '\n|style="text-align:right"' .. rowSpan .. '| ' .. building.maxUpgrades)
table.insert(resultPart, '\n|style="text-align:right"' .. rowSpan .. '| ' .. building.maxUpgrades)
firstRow = false
firstRow = false
Line 494: Line 516:
function p.getWorshipTable()
function p.getWorshipTable()
local function getCheckpointCell(checkpoint)
local function getCheckpointCell(checkpoint)
return '\n|-\n!' .. checkpoint .. '%<br/>' .. Shared.formatnum(checkpoint * Township.maxWorship / 100) .. '/' .. Shared.formatnum(Township.maxWorship)
return '\n|-\n!' .. checkpoint .. '%<br/>' .. Num.formatnum(checkpoint * Township.maxWorship / 100) .. '/' .. Num.formatnum(Township.maxWorship)
end
end


Line 592: Line 614:
table.insert(ret, '\n|-\n| <b>Building ID:</b> ' .. building.id)
table.insert(ret, '\n|-\n| <b>Building ID:</b> ' .. building.id)
-- Tier
-- Tier
local tier = p._getTierText(building.tier)
local tier = p._getTierText(building.tier, building.abyssalTier)
table.insert(ret, '\n|-\n| <b>Requirements:</b><br/>' .. tier)
table.insert(ret, '\n|-\n| <b>Requirements:</b><br/>' .. tier)


Line 638: Line 660:
-- Maximum built
-- Maximum built
local biomeCount = Shared.tableCount(building.biomes)
local biomeCount = Shared.tableCount(building.biomes)
local maxText = Shared.formatnum(building.maxUpgrades)
local maxText = Num.formatnum(building.maxUpgrades)
if biomeCount > 1 then
if biomeCount > 1 then
maxText = maxText .. ' per biome, ' .. Shared.formatnum(biomeCount * building.maxUpgrades) .. ' total'
maxText = maxText .. ' per biome, ' .. Num.formatnum(biomeCount * building.maxUpgrades) .. ' total'
end
end
table.insert(ret, '\n|-\n| <b>Maximum Built:</b><br/>' .. maxText)
table.insert(ret, '\n|-\n| <b>Maximum Built:</b><br/>' .. maxText)
Line 709: Line 731:
table.insert(ret, '\n|-\n!colspan="2"| Requirements')
table.insert(ret, '\n|-\n!colspan="2"| Requirements')
for _, building in ipairs(buildingList) do
for _, building in ipairs(buildingList) do
table.insert(ret, '\n|' .. p._getTierText(building.tier))
table.insert(ret, '\n|' .. p._getTierText(building.tier, building.abyssalTier))
end
end


Line 811: Line 833:
for goalIdx, goalObj in ipairs(goalData) do
for goalIdx, goalObj in ipairs(goalData) do
if goalType == 'items' then
if goalType == 'items' then
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getItemText(goalObj.id)
goalText = Num.formatnum(goalObj.quantity) .. ' ' .. getItemText(goalObj.id)
elseif goalType == 'monsters' then
elseif goalType == 'monsters' then
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getMonsterText(goalObj.id)
goalText = Num.formatnum(goalObj.quantity) .. ' ' .. getMonsterText(goalObj.id)
elseif goalType == 'monsterWithItems' then
elseif goalType == 'monsterWithItems' then
local itemsText = {}
local itemsText = {}
Line 819: Line 841:
table.insert(itemsText, getItemText(itemID))
table.insert(itemsText, getItemText(itemID))
end
end
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getMonsterText(goalObj.monsterID) .. ' with ' .. table.concat(itemsText, ', ') .. ' equipped'
goalText = Num.formatnum(goalObj.quantity) .. ' ' .. getMonsterText(goalObj.monsterID) .. ' with ' .. table.concat(itemsText, ', ') .. ' equipped'
elseif goalType == 'skillXP' then
elseif goalType == 'skillXP' then
local skillName = GameData.getSkillData(goalObj.id).name
local skillName = GameData.getSkillData(goalObj.id).name
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. Icons.Icon({skillName, type='skill'}) .. ' XP'
goalText = Num.formatnum(goalObj.quantity) .. ' ' .. Icons.Icon({skillName, type='skill'}) .. ' XP'
elseif goalType == 'buildings' then
elseif goalType == 'buildings' then
local buildingName = p._GetBuildingByID(goalObj.id).name
local buildingName = p._GetBuildingByID(goalObj.id).name
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. Icons.Icon({buildingName, type='building'})
goalText = Num.formatnum(goalObj.quantity) .. ' ' .. Icons.Icon({buildingName, type='building'})
elseif goalType == 'numPOIs' then
elseif goalType == 'numPOIs' then
local mapName = GameData.getEntityByID(GameData.skillData.Cartography.worldMaps, goalObj.worldMapID).name
local mapName = GameData.getEntityByID(GameData.skillData.Cartography.worldMaps, goalObj.worldMapID).name
goalText = 'Discover ' .. Shared.formatnum(goalObj.quantity) .. ' Points of Interest in ' .. Icons.Icon({'Cartography', type='skill'}) .. ' world map of ' .. mapName
goalText = 'Discover ' .. Num.formatnum(goalObj.quantity) .. ' Points of Interest in ' .. Icons.Icon({'Cartography', type='skill'}) .. ' world map of ' .. mapName
else
else
goalText = Shared.printError('Unknown goal type: ' .. (goalType or 'nil'))
goalText = Shared.printError('Unknown goal type: ' .. (goalType or 'nil'))
Line 841: Line 863:
-- Goal data is another value of some type
-- Goal data is another value of some type
if goalType == 'numRefinements' then
if goalType == 'numRefinements' then
goalText = 'Refine dig site maps in ' .. Icons.Icon({'Cartography', type='skill'}) .. ' ' .. Shared.formatnum(goalData) .. ' times'
goalText = 'Refine dig site maps in ' .. Icons.Icon({'Cartography', type='skill'}) .. ' ' .. Num.formatnum(goalData) .. ' times'
else
else
goalText = Shared.printError('Unknown goal type: ' .. (goalType or 'nil'))
goalText = Shared.printError('Unknown goal type: ' .. (goalType or 'nil'))
Line 873: Line 895:
local rewards = {}
local rewards = {}
local rewardsVariableQty = {}
local rewardsVariableQty = {}
if task.rewards.currency ~= nil then
if task.rewards.currencies ~= nil then
for _, currReward in ipairs(task.rewards.currency) do
for _, currReward in ipairs(task.rewards.currencies) do
if isDailyTask then
if isDailyTask and currReward.id ~= 'melvorD:GP' then
table.insert(rewardsVariableQty, Icons._Currency(currReward.id))
table.insert(rewardsVariableQty, Icons._Currency(currReward.id))
else
elseif not isDailyTask then
table.insert(rewards, Icons._Currency(currReward.id, currReward.qty))
table.insert(rewards, Icons._Currency(currReward.id, currReward.quantity))
end
end
end
end
Line 884: Line 906:
for _, item in ipairs(task.rewards.items) do
for _, item in ipairs(task.rewards.items) do
local itemname = GameData.getEntityByID('items', item.id).name
local itemname = GameData.getEntityByID('items', item.id).name
table.insert(rewards, Shared.formatnum(item.quantity)..' '..Icons.Icon({itemname, type='item'}))
table.insert(rewards, Num.formatnum(item.quantity)..' '..Icons.Icon({itemname, type='item'}))
end
end
for _, skill in ipairs(task.rewards.skillXP) do
for _, skill in ipairs(task.rewards.skillXP) do
if not (isDailyTask and skill.id == 'melvorD:Township') then
if not (isDailyTask and skill.id == 'melvorD:Township') then
local skillname = GameData.getSkillData(skill.id).name
local skillname = GameData.getSkillData(skill.id).name
table.insert(rewards, Shared.formatnum(skill.quantity)..' '..Icons.Icon({skillname, type='skill'})..' XP')
table.insert(rewards, Num.formatnum(skill.quantity)..' '..Icons.Icon({skillname, type='skill'})..' XP')
end
end
end
end
for _, townshipResource in ipairs(task.rewards.townshipResources) do
for _, townshipResource in ipairs(task.rewards.townshipResources) do
local resourcename = p._getResourceByID(townshipResource.id).name
local resourcename = p._getResourceByID(townshipResource.id).name
table.insert(rewards, Shared.formatnum(townshipResource.quantity)..' '..Icons.Icon({resourcename, type='resource'}))
table.insert(rewards, Num.formatnum(townshipResource.quantity)..' '..Icons.Icon({resourcename, type='resource'}))
end
end
if not Shared.tableIsEmpty(rewardsVariableQty) then
if not Shared.tableIsEmpty(rewardsVariableQty) then
Line 933: Line 955:
table.insert(ret, '\n!Rewards')
table.insert(ret, '\n!Rewards')
if isDailyTask then
if isDailyTask then
table.insert(ret, '<br/>(In addition to [[Township#Casual Tasks|Variable]] ' .. Icons.GP() .. ' & ' .. Icons.Icon({'Township', type='skill', notext=true}) .. ' XP)')
table.insert(ret, '<br/>(In addition to [[Township#Casual Tasks|Variable]] ' .. Icons._Currency('melvorD:GP') .. ' & ' .. Icons.Icon({'Township', type='skill', notext=true}) .. ' XP)')
end
end
if isDailyTask then
if isDailyTask then
Line 966: Line 988:
if referenceType == 'dungeon' then
if referenceType == 'dungeon' then
-- We get the tasks associated with all monsters in the dungeon
-- We get the tasks associated with all monsters in the dungeon
local monsters = GameData.getEntityByName('dungeons', referenceName).monsterIDs
local area = nil
local areaTypes = {'dungeons', 'abyssDepths'}
for _, areaType in ipairs(areaTypes) do
area = GameData.getEntityByName(areaType, referenceName)
if area ~= nil then
break
end
end
local monsters = area.monsterIDs
for _, monster in ipairs(monsters) do
for _, monster in ipairs(monsters) do
IDs[monster] = true
IDs[monster] = true
Line 1,002: Line 1,032:
return referenceIDs[entry.id] ~= nil
return referenceIDs[entry.id] ~= nil
end
end
for _, searchTable in ipairs(GetSearchTables(task)) do
for _, searchTable in pairs(GetSearchTables(task)) do -- ipairs won't work if first table is nil
-- Check to see if the table contains any of the IDs in referenceIDs
-- Check to see if the table contains any of the IDs in referenceIDs
if searchTable[1] ~= nil then -- Make sure table is not empty
if searchTable[1] ~= nil then -- Make sure table is not empty