572
edits
(Accidentally overwrote Auron's edits - Re-implementing fix) |
(Refactor p.GetTaskTable to include a subroutine p._GetTaskRow) |
||
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 GameData = require('Module:GameData') | local GameData = require('Module:GameData') | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
Line 757: | Line 755: | ||
end | end | ||
table.insert(ret, '\r\n|}') | table.insert(ret, '\r\n|}') | ||
return table.concat(ret) | |||
end | |||
-- Returns a row containing a task given a title and a task table | |||
function p._GetTaskRow(title, task) | |||
local ret = {} | |||
-- 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|-') | |||
table.insert(ret, '\r\n!'..titlespan..title) | |||
-- 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 = GameData.getEntityByID('items', 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 = GameData.getEntityByID('monsters', 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 = GameData.getEntityByID('items', 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>')) | |||
return table.concat(ret) | return table.concat(ret) | ||
end | end | ||
Line 774: | Line 837: | ||
-- Filter out other categories | -- Filter out other categories | ||
if task.category == category then | if task.category == category then | ||
taskcount = taskcount + 1 | taskcount = taskcount + 1 | ||
local title = categoryname..' '..taskcount | |||
table.insert(ret, p._GetTaskRow(title, task)) | |||
end | end | ||
end | end |
edits