Module:Township: Difference between revisions

_getTaskRow: Support new AoD requirements, add exception reporting for unrecognized requirements
(Fix monster lookup)
(_getTaskRow: Support new AoD requirements, add exception reporting for unrecognized requirements)
Line 764: Line 764:
-- Requirements
-- Requirements
table.insert(ret, '\n|')
table.insert(ret, '\n|')
local requirements = {}
-- Determines order of requirements output
for _, item in ipairs(task.goals.items) do
local reqOrder = {
local itemname = GameData.getEntityByID('items', item.id).name
["items"] = 10,
table.insert(requirements, Shared.formatnum(item.quantity)..' '..Icons.Icon({itemname, type='item'}))
["monsters"] = 20,
["monsterWithItems"] = 30,
["skillXP"] = 40,
["buildings"] = 50,
["numPOIs"] = 60,
["numRefinements"] = 70
}
local reqTextPart = {}
 
local function getItemText(itemID)
local item = Items.getItemByID(itemID)
if item == nil then
return Shared.printError('Unknown item: ' .. (itemID or 'nil'))
else
return Icons.Icon({item.name, type='item'})
end
end
end
for _, monster in ipairs(task.goals.monsters) do
local function getMonsterText(monsterID)
local monstername = Monsters.getMonsterName(Monsters.getMonsterByID(monster.id))
local monster = Monsters.getMonsterByID(monsterID)
table.insert(requirements, Shared.formatnum(monster.quantity)..' '..Icons.Icon({monstername, type='monster'}))
if monster == nil then
return Shared.printError('Unknown monster: ' .. (monsterID or 'nil'))
else
return Icons.Icon({Monsters.getMonsterName(monster), type='monster'})
end
end
end
if type(task.goals.monsterWithItems) == 'table' then
 
for _, monWithItem in ipairs(task.goals.monsterWithItems) do
for goalType, goalData in pairs(task.goals) do
local monsterName = GameData.getEntityByID('monsters', monWithItem.monsterID).name
local typeOrder = reqOrder[goalType] or 0
local itemsText = {}
local goalText = nil
for i, itemID in ipairs(monWithItem.itemIDs) do
if type(goalData) == 'table' then
local itemName = GameData.getEntityByID('items', itemID).name
-- Goal data is a table
table.insert(itemsText, Icons.Icon({itemName, type='item'}))
for goalIdx, goalObj in ipairs(goalData) do
if goalType == 'items' then
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getItemText(goalObj.id)
elseif goalType == 'monsters' then
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getMonsterText(goalObj.id)
elseif goalType == 'monsterWithItems' then
local itemsText = {}
for i, itemID in ipairs(goalObj.itemIDs) do
table.insert(itemsText, getItemText(itemID))
end
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. getMonsterText(goalObj.monsterID) .. ' with ' .. table.concat(itemsText, ', ') .. ' equipped'
elseif goalType == 'skillXP' then
local skillName = GameData.getSkillData(goalObj.id).name
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. Icons.Icon({skillName, type='skill'}) .. ' XP'
elseif goalType == 'buildings' then
local buildingName = p._GetBuildingByID(goalObj.id).name
goalText = Shared.formatnum(goalObj.quantity) .. ' ' .. Icons.Icon({buildingName, type='building'})
elseif goalType == 'numPOIs' then
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
else
goalText = Shared.printError('Unknown goal type: ' .. (goalType or 'nil'))
end
table.insert(reqTextPart, {
["goalOrder"] = typeOrder,
["subOrder"] = goalIdx,
["text"] = goalText
})
end
else
-- Goal data is another value of some type
if goalType == 'numRefinements' then
goalText = 'Refine dig site maps in ' .. Icons.Icon({'Cartography', type='skill'}) .. ' ' .. Shared.formatnum(goalData) .. ' times'
else
goalText = Shared.printError('Unknown goal type: ' .. (goalType or 'nil'))
end
end
table.insert(requirements, Shared.formatnum(monWithItem.quantity) .. ' ' .. Icons.Icon({monsterName, type='monster'}) .. ' with ' .. table.concat(itemsText, ', ') .. ' equipped')
table.insert(reqTextPart, {
["goalOrder"] = typeOrder,
["subOrder"] = 0,
["text"] = goalText
})
end
end
end
end
for _, skill in ipairs(task.goals.skillXP) do
 
local skillname = GameData.getSkillData(skill.id).name
table.sort(reqTextPart,
table.insert(requirements, Shared.formatnum(skill.quantity)..' '..Icons.Icon({skillname, type='skill'})..' XP')
function(a, b)
end
if a.goalOrder == b.goalOrder then
for _, building in ipairs(task.goals.buildings) do
return a.subOrder < b.subOrder
local buildingname = p._GetBuildingByID(building.id).name
else
table.insert(requirements, Shared.formatnum(building.quantity)..' '..Icons.Icon({buildingname, type='building'}))
return a.goalOrder < b.goalOrder
end
end
)
 
local requirements = {}
for i, req in ipairs(reqTextPart) do
table.insert(requirements, req.text)
end
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)
-- 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)
Line 853: Line 917:
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 stickyHeader" style="text-align:left"')
table.insert(ret, '\n|- class="headerRow-0"')
table.insert(ret, '\n!Task')
table.insert(ret, '\n!Task')
table.insert(ret, '\n!Requirements')
table.insert(ret, '\n!Requirements')