Anonymous

Module:Township: Difference between revisions

From Melvor Idle
Added p.GetWorshipTable
(GetTaskReferenceTable: Fix for page names containing apostrophes)
(Added p.GetWorshipTable)
Line 920: Line 920:
table.insert(ret, p._GetTaskRow(title, task))
table.insert(ret, p._GetTaskRow(title, task))
end
end
table.insert(ret, '\r\n|}')
return table.concat(ret)
end
-- Generates a table showing all the worship options
function p.GetWorshipTable()
local function GetCheckpointCell(checkpoint)
return '\r\n|-\r\n!'..checkpoint..'%<br>'..(checkpoint*Township.maxWorship/100)..'/'..Township.maxWorship
end
local ret = {}
table.insert(ret, '\r\n{| class="wikitable" style="text-align:left"')
table.insert(ret, '\r\n!'..Icons.Icon({'Worship', type='township', nolink=true}))
-- Names
for _, worship in ipairs(Township.worships) do
if worship.isHidden == false then
table.insert(ret, '\r\n!'..Icons.Icon({worship.name, type='monster', size=50})..Icons.Icon({'Statue of '..worship.name, type='building', size=50, notext=true}))
end
end
-- Requirements
-- Hard-coded because there's only 1 requirement
table.insert(ret, '\r\n|-\r\n!Requirements')
local requirements = {
['melvorF:Bane'] = 'Completion of<br>'..Icons.Icon({'Impending Darkness Event', type='dungeon'})
}
for _, worship in ipairs(Township.worships) do
if worship.isHidden == false then
local requirement = requirements[worship.id] ~= nil and requirements[worship.id] or 'None'
table.insert(ret, '\r\n|style="text-align:center|'..requirement)
end
end
-- Base modifiers
table.insert(ret, GetCheckpointCell(0))
for _, worship in ipairs(Township.worships) do
mw.logObject(worship.isHidden == false)
if worship.isHidden == false then
table.insert(ret, '\r\n|'..Constants.getModifiersText(worship.modifiers))
end
end
-- Checkpoint modifiers
for i, checkpoint in ipairs(Township.worshipCheckpoints) do
table.insert(ret, GetCheckpointCell(checkpoint))
for _, worship in ipairs(Township.worships) do
if worship.isHidden == false then
table.insert(ret, '\r\n|'..Constants.getModifiersText(worship.checkpoints[i]))
end
end
end
-- Total sum
table.insert(ret, '\r\n|-\r\n!Total')
for _, worship in ipairs(Township.worships) do
if worship.isHidden == false then
local modifiers = Shared.clone(worship.modifiers)
for _, checkpoint in ipairs(worship.checkpoints) do
for modifier, magnitude in pairs(checkpoint) do
local swappedModifier = string.sub(modifier, 1, string.len('increased')) == 'increased' and string.gsub(modifier, 'increased', 'decreased') or string.gsub(modifier, 'decreased', 'increased')
-- The modifier already exists, so we add the two modifiers together
if modifiers[modifier] ~= nil then
modifiers[modifier] = modifiers[modifier] + magnitude
-- The inverse modifier already exists, so we subtract the negative value of the new modifier
elseif modifiers[swappedModifier] ~= nil then
modifiers[swappedModifier] = modifiers[swappedModifier] - magnitude
-- The modifier does not exist, so create the modifier
else
modifiers[modifier] = magnitude
end
end
end
table.insert(ret, '\r\n|'..Constants.getModifiersText(modifiers))
end
end
table.insert(ret, '\r\n|}')
table.insert(ret, '\r\n|}')
return table.concat(ret)
return table.concat(ret)
572

edits