Module:Township: Difference between revisions

getTaskTable: Support casual/daily tasks
(getTraderTable, getBuildingUpgradeTable: Add TotH icon)
(getTaskTable: Support casual/daily tasks)
Line 722: Line 722:


-- Returns a row containing a task given a title and a task table
-- Returns a row containing a task given a title and a task table
function p._getTaskRow(title, task)
function p._getTaskRow(title, task, isDailyTask)
local ret = {}
local ret = {}


Line 734: Line 734:
-- Title
-- Title
table.insert(ret, '\n|-')
table.insert(ret, '\n|-')
table.insert(ret, '\n!'..titlespan..title)
table.insert(ret, '\n!' .. titlespan .. title)
-- Description
-- Description
if hasDescription then
if hasDescription then
table.insert(ret, '\n|colspan="2"|'..task.description)
table.insert(ret, '\n|colspan="2"|' .. task.description)
table.insert(ret, '\n|-')
table.insert(ret, '\n|-')
end
end
Line 750: Line 750:
local monstername = GameData.getEntityByID('monsters', monster.id).name
local monstername = GameData.getEntityByID('monsters', monster.id).name
table.insert(requirements, Shared.formatnum(monster.quantity)..' '..Icons.Icon({monstername, type='monster'}))
table.insert(requirements, Shared.formatnum(monster.quantity)..' '..Icons.Icon({monstername, type='monster'}))
end
if type(task.goals.monsterWithItems) == 'table' then
for _, monWithItem in ipairs(task.goals.monsterWithItems) do
local monsterName = GameData.getEntityByID('monsters', monWithItem.monsterID).name
local itemsText = {}
for i, itemID in ipairs(monWithItem.itemIDs) do
local itemName = GameData.getEntityByID('items', itemID).name
table.insert(itemsText, Icons.Icon({itemName, type='item'}))
end
table.insert(requirements, Shared.formatnum(monWithItem.quantity) .. ' ' .. Icons.Icon({monsterName, type='monster'}) .. ' with ' .. table.concat(itemsText, ', ') .. ' equipped')
end
end
end
for _, skill in ipairs(task.goals.skillXP) do
for _, skill in ipairs(task.goals.skillXP) do
Line 764: Line 775:
table.insert(ret, '\n|')
table.insert(ret, '\n|')
local rewards = {}
local rewards = {}
if task.rewards.gp ~= 0 then
local rewardsVariableQty = {}
if task.rewards.gp > 0 and not isDailyTask then
table.insert(rewards, Icons.GP(task.rewards.gp))
table.insert(rewards, Icons.GP(task.rewards.gp))
end
end
if task.rewards.slayerCoins ~= 0 then
if task.rewards.slayerCoins > 0 then
table.insert(rewards, Icons.SC(task.rewards.slayerCoins))
if isDailyTask then
table.insert(rewardsVariableQty, Icons.SC())
else
table.insert(rewards, Icons.SC(task.rewards.slayerCoins))
end
end
end
for _, item in ipairs(task.rewards.items) do
for _, item in ipairs(task.rewards.items) do
Line 775: Line 791:
end
end
for _, skill in ipairs(task.rewards.skillXP) do
for _, skill in ipairs(task.rewards.skillXP) do
local skillname = GameData.getSkillData(skill.id).name
if not (isDailyTask and skill.id == 'melvorD:Township') then
table.insert(rewards, Shared.formatnum(skill.quantity)..' '..Icons.Icon({skillname, type='skill'})..' XP')
local skillname = GameData.getSkillData(skill.id).name
table.insert(rewards, Shared.formatnum(skill.quantity)..' '..Icons.Icon({skillname, type='skill'})..' XP')
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, Shared.formatnum(townshipResource.quantity)..' '..Icons.Icon({resourcename, type='resource'}))
end
if not Shared.tableIsEmpty(rewardsVariableQty) then
table.insert(ret, '[[Township#Casual Tasks|Variable]] ' .. table.concat(rewardsVariableQty, ', ') .. '<br/>')
end
end
table.insert(ret, table.concat(rewards, '<br/>'))
table.insert(ret, table.concat(rewards, '<br/>'))
-- Unlock requirements, daily task specific
if isDailyTask then
table.insert(ret, '\n|' .. Shop.getRequirementString(task.requirements))
end
return table.concat(ret)
return table.concat(ret)
end
end
Line 791: Line 817:
local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
local categoryData = GameData.getEntityByID(Township.taskCategories, category)
local categoryData = GameData.getEntityByID(Township.taskCategories, category)
if categoryData == nil then
local taskData, categoryName, isDailyTask = nil, nil, false
if category == 'Daily' then
isDailyTask = true
taskData = Township.casualTasks
categoryName = 'Casual'
elseif categoryData ~= nil then
taskData = Township.tasks
categoryName = categoryData.name
else
return Shared.printError('Invalid task category specified: ' .. (tostring(category) or 'nil'))
return Shared.printError('Invalid task category specified: ' .. (tostring(category) or 'nil'))
end
end
local categoryname = categoryData.name
 
local taskcount = 0
local taskcount = 0
local ret = {}
local ret = {}
table.insert(ret, '{| class="wikitable lighttable" style="text-align:left"')
table.insert(ret, '{| class="wikitable lighttable" style="text-align:left"')
Line 802: Line 835:
table.insert(ret, '\n!Requirements')
table.insert(ret, '\n!Requirements')
table.insert(ret, '\n!Rewards')
table.insert(ret, '\n!Rewards')
if isDailyTask then
table.insert(ret, '<br/>(In addition to [[Township#Casual Tasks|Variable]] ' .. Icons.GP() .. ' & ' .. Icons.Icon({'Township', type='skill', notext=true}) .. ' XP)')
end
if isDailyTask then
table.insert(ret, '\n!Unlock Requirements')
end
for _, task in ipairs(Township.tasks) do
for _, task in ipairs(taskData) do
-- 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
local title = categoryName .. ' ' .. taskcount
table.insert(ret, p._getTaskRow(title, task))
--mw.logObject(task)
--if true then
-- return ''
--end
table.insert(ret, p._getTaskRow(title, task, isDailyTask))
end
end
end
end
Line 887: Line 930:
local categoryname = GameData.getEntityByID(Township.taskCategories, task.category).name
local categoryname = GameData.getEntityByID(Township.taskCategories, task.category).name
local title = '[[Township/Tasks#'..categoryname..'|'..categoryname..']]'
local title = '[[Township/Tasks#'..categoryname..'|'..categoryname..']]'
table.insert(ret, p._getTaskRow(title, task))
table.insert(ret, p._getTaskRow(title, task, false))
end
end
table.insert(ret, '\n|}')
table.insert(ret, '\n|}')