Module:GauTest/Township: Difference between revisions

no edit summary
(Tasks)
No edit summary
 
(17 intermediate revisions by the same user not shown)
Line 3: Line 3:
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')


local p = {}
local p = {}
Line 302: Line 301:
function p._GetBuildingByName(name)
function p._GetBuildingByName(name)
-- Check for the special statue case
-- Check for the special statue case
if name == 'STATUE_NAME' then
if name == 'Statues' 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.getEntityByName(Township.buildings, 'STATUE_NAME'))
local building = Shared.clone(GameData.getEntityByID(Township.buildings, 'melvorF:Statues'))
building.name = name
building.name = name
return building
return building
Line 754: Line 753:
end
end
end
end
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)
end
-- Returns all the tasks of a given category
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
taskcount = taskcount + 1
local title = categoryname..' '..taskcount
table.insert(ret, p._GetTaskRow(title, task))
end
end
table.insert(ret, '\r\n|}')
return table.concat(ret)
end
-- Returns a table containing all the tasks that reference an item or monster
-- e.g. p.GetTaskReferenceTable({'Chicken Coop', 'dungeon'})
-- name = item or monster name
-- type = 'item' or 'monster' or 'dungeon'
function p.GetTaskReferenceTable(frame)
-- Returns a set containing all the desired IDs
local function GetReferenceIDs(referenceName, referenceType)
local IDs = {}
if referenceType == 'dungeon' then
-- We get the tasks associated with all monsters in the dungeon
local monsters = GameData.getEntityByName('dungeons', referenceName).monsterIDs
for _, monster in ipairs(monsters) do
IDs[monster] = true
end
end
if referenceType == 'item' then
IDs[GameData.getEntityByName('items', referenceName).id] = true
end
if referenceType == 'monster' then
IDs[GameData.getEntityByName('monsters', referenceName).id] = true
end
return IDs
end
-- For a task, returns where to search for the desired IDs, given the type
local function GetGetSearchTables(referenceType)
local function searchItems(task)
return {task.goals.items, task.rewards.items}
end
local function searchMonsters(task)
return {task.goals.monsters}
end
-- item -> searchItems; monster or dungeon -> searchMonsters
return referenceType == 'item' and searchItems or searchMonsters
end
local args = frame.args ~= nil and frame.args or frame
local referenceName = Shared.fixPagename(args[1])
local referenceType = args[2]
local referenceIDs = GetReferenceIDs(referenceName, referenceType)
-- GetSearchTables = function searchItems/Monsters(task)
local GetSearchTables = GetGetSearchTables(referenceType)
local function checkTask(task)
local function checkID(entry)
return referenceIDs[entry.id] ~= nil
end
for _, searchTable in ipairs(GetSearchTables(task)) do
-- Check to see if the table contains any of the IDs in referenceIDs
if searchTable[1] ~= nil then -- Make sure table is not empty
if #GameData.getEntities(searchTable, checkID) ~= 0 then -- Make sure we have at least 1 match
return true
end
end
end
return false
end
-- Find all tasks that contain the desired ids
local tasks = GameData.getEntities(Township.tasks, checkTask)
if #tasks == 0 then
return ''
end
-- Build the table
local ret = {}
table.insert(ret, '==Tasks==')
table.insert(ret, '\r\n{| class="wikitable" 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(tasks) do
local categoryname = GameData.getEntityByID(Township.taskCategories, task.category).name
local title = '[[Township/Tasks#'..categoryname..'|'..categoryname..']]'
table.insert(ret, p._GetTaskRow(title, task))
end
table.insert(ret, '\r\n|}')
return table.concat(ret)
end
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