572
edits
(_GetrBuildingByName: Fix statue handling following localization changes) |
(Adding p.GetTaskTable(frame)) |
||
Line 1: | Line 1: | ||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local Items = require('Module:Items') -- We can always remove this dependancy if needed | |||
local Monsters = require('Module:Monsters') -- We can always remove this dependancy if needed | |||
local GameData = require('Module:GameData') | local GameData = require('Module:GameData') | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
Line 302: | Line 304: | ||
function p._GetBuildingByName(name) | function p._GetBuildingByName(name) | ||
-- Check for the special statue case | -- Check for the special statue case | ||
if name == ' | if name == 'STATUE_NAME' then | ||
name = 'Statue of Worship' | name = 'Statue of Worship' | ||
end | end | ||
local STATUE_OF = 'Statue of ' | local STATUE_OF = 'Statue of ' | ||
if string.sub(name, 1, string.len(STATUE_OF)) == STATUE_OF then | if string.sub(name, 1, string.len(STATUE_OF)) == STATUE_OF then | ||
local building = Shared.clone(GameData. | local building = Shared.clone(GameData.getEntityByName(Township.buildings, 'STATUE_NAME')) | ||
building.name = name | building.name = name | ||
return building | return building | ||
Line 752: | Line 754: | ||
-- Insert cell | -- Insert cell | ||
table.insert(ret, '\r\n|class="'..class..'"|'..count) | table.insert(ret, '\r\n|class="'..class..'"|'..count) | ||
end | |||
end | |||
table.insert(ret, '\r\n|}') | |||
return table.concat(ret) | |||
end | |||
function p.GetTaskTable(frame) | |||
local category = frame.args ~= nil and frame.args[1] or frame | |||
local categoryname = GameData.getEntityByID(Township.taskCategories, category).name | |||
local taskcount = 0 | |||
local ret = {} | |||
table.insert(ret, '\r\n{| class="wikitable lighttable" style="text-align:left"') | |||
table.insert(ret, '\r\n!Task') | |||
table.insert(ret, '\r\n!Requirements') | |||
table.insert(ret, '\r\n!Rewards') | |||
for _, task in ipairs(Township.tasks) do | |||
-- Filter out other categories | |||
if task.category == category then | |||
-- If has description, we will need to rowspan the title by 2, and insert a description with colspan 2 | |||
local hasDescription = false | |||
if task.description ~= nil then | |||
hasDescription = true | |||
end | |||
local titlespan = hasDescription == true and 'rowspan="2"|' or '' | |||
-- Title | |||
table.insert(ret, '\r\n|-') | |||
taskcount = taskcount + 1 | |||
table.insert(ret, '\r\n!'..titlespan..categoryname..' '..taskcount) | |||
-- Description | |||
if hasDescription then | |||
table.insert(ret, '\r\n|colspan="2"|'..task.description) | |||
table.insert(ret, '\r\n|-') | |||
end | |||
-- Requirements | |||
table.insert(ret, '\r\n|') | |||
local requirements = {} | |||
for _, item in ipairs(task.goals.items) do | |||
local itemname = Items.getItemByID(item.id).name | |||
table.insert(requirements, Shared.formatnum(item.quantity)..' '..Icons.Icon({itemname, type='item'})) | |||
end | |||
for _, monster in ipairs(task.goals.monsters) do | |||
local monstername = Monsters.getMonsterByID(monster.id).name | |||
table.insert(requirements, Shared.formatnum(monster.quantity)..' '..Icons.Icon({monstername, type='monster'})) | |||
end | |||
for _, skill in ipairs(task.goals.skillXP) do | |||
local skillname = GameData.getSkillData(skill.id).name | |||
table.insert(requirements, Shared.formatnum(skill.quantity)..' '..Icons.Icon({skillname, type='skill'})..' XP') | |||
end | |||
for _, building in ipairs(task.goals.buildings) do | |||
local buildingname = p._GetBuildingByID(building.id).name | |||
table.insert(requirements, Shared.formatnum(building.quantity)..' '..Icons.Icon({buildingname, type='building'})) | |||
end | |||
-- We don't check tasks.requirements (so far it's only used to enumerate the Tutorial tasks so you only see 1 at a time) | |||
table.insert(ret, table.concat(requirements, '<br>')) | |||
-- Rewards | |||
table.insert(ret, '\r\n|') | |||
local rewards = {} | |||
if task.rewards.gp ~= 0 then | |||
table.insert(rewards, Icons.GP(task.rewards.gp)) | |||
end | |||
if task.rewards.slayerCoins ~= 0 then | |||
table.insert(rewards, Icons.SC(task.rewards.slayerCoins)) | |||
end | |||
for _, item in ipairs(task.rewards.items) do | |||
local itemname = Items.getItemByID(item.id).name | |||
table.insert(rewards, Shared.formatnum(item.quantity)..' '..Icons.Icon({itemname, type='item'})) | |||
end | |||
for _, skill in ipairs(task.rewards.skillXP) do | |||
local skillname = GameData.getSkillData(skill.id).name | |||
table.insert(rewards, Shared.formatnum(skill.quantity)..' '..Icons.Icon({skillname, type='skill'})..' XP') | |||
end | |||
for _, townshipResource in ipairs(task.rewards.townshipResources) do | |||
local resourcename = p._GetResourceByID(townshipResource.id).name | |||
table.insert(rewards, Shared.formatnum(townshipResource.quantity)..' '..Icons.Icon({resourcename, type='resource'})) | |||
end | |||
table.insert(ret, table.concat(rewards, '<br>')) | |||
end | end | ||
end | end |
edits