Anonymous

Module:Sandbox/GauTest/Township: Difference between revisions

From Melvor Idle
Worship V1
(WIP)
(Worship V1)
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 848: Line 847:


-- Returns a table containing all the tasks that reference an item or monster
-- 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
-- name = item or monster name
-- type = 'item' or 'monster' or 'dungeon'
-- type = 'item' or 'monster' or 'dungeon'
Line 856: Line 856:
if referenceType == 'dungeon' then
if referenceType == 'dungeon' then
-- We get the tasks associated with all monsters in the dungeon
-- We get the tasks associated with all monsters in the dungeon
local monsters = GameData.getEntityByName('dungeons', name).monsterIDs
local monsters = GameData.getEntityByName('dungeons', referenceName).monsterIDs
for _, monster in ipairs(monsters) do
for _, monster in ipairs(monsters) do
IDs[v] = monster
IDs[monster] = true
end
end
end
end
Line 882: Line 882:
local args = frame.args ~= nil and frame.args or frame
local args = frame.args ~= nil and frame.args or frame
local referenceName = args[1]
local referenceName = Shared.fixPagename(args[1])
local referenceType = args[2]
local referenceType = args[2]
local referenceIDs = GetReferenceIDs(referenceName, referenceType)
local referenceIDs = GetReferenceIDs(referenceName, referenceType)
-- GetSearchTables = function searchItems/Monsters(task)
-- GetSearchTables = function searchItems/Monsters(task)
local GetSearchTables = GetGetSearchTables(referenceType)
local GetSearchTables = GetGetSearchTables(referenceType)
local function checkTask(task)
local function checkTask(task)
local function checkID(entry)
local function checkID(entry)
Line 893: Line 894:
for _, searchTable in ipairs(GetSearchTables(task)) do
for _, searchTable in ipairs(GetSearchTables(task)) do
-- Check to see if the table contains any of the IDs in referenceIDs
-- Check to see if the table contains any of the IDs in referenceIDs
if GameData.getEntities(searchTable, checkID) ~= nil then
if searchTable[1] ~= nil then -- Make sure table is not empty
return true
if #GameData.getEntities(searchTable, checkID) ~= 0 then -- Make sure we have at least 1 match
return true
end
end
end
end
end
Line 901: Line 904:
-- Find all tasks that contain the desired ids
-- Find all tasks that contain the desired ids
local tasks = GameData.getEntities(Township.tasks, checkTask)
local tasks = GameData.getEntities(Township.tasks, checkTask)
if #tasks == 0 then
return ''
end
-- Build the table
-- Build the table
local ret = {}
local ret = {}
table.insert(ret, '==Tasks==')
table.insert(ret, '\r\n{| class="wikitable" style="text-align:left"')
table.insert(ret, '\r\n{| class="wikitable" style="text-align:left"')
table.insert(ret, '\r\n!Task')
table.insert(ret, '\r\n!Task')
Line 913: Line 920:
table.insert(ret, p._GetTaskRow(title, task))
table.insert(ret, p._GetTaskRow(title, task))
end
end
table.insert(ret, '\r\n|}')
return table.concat(ret)
end
function p.GetWorshipTable()
local function GetCheckpointCell(checkpoint)
return '\r\n!'..checkpoint..'%<br>'..Icons.Icon({'Worship', type=township, notext=true})..' '..(checkpoint*Township.maxWorship)..'/'..Township.maxWorship
end
local ret = {}
table.insert(ret, '\r\n{| class="wikitable" style="text-align:left"')
table.insert(ret, '\r\n!Checkpoint')
-- Names
for _, worship in ipairs(Township.worships) do
if worship.isHidden == false then
table.insert(ret, '\r\n!'..Icons.Icon({worship.name, type='monster'}))
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!Total')
for i, checkpoint in ipairs(Township.worshipCheckpoints) do
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
if modifiers[modifier] == nil then
modifiers[modifier] = magnitude
else
modifiers[modifier] = modifiers[modifier] + magnitude
end
end
end
table.insert(ret, '\r\n|'..Constants.getModifiersText(modifiers))
end
end
end
table.insert(ret, '\r\n|}')
table.insert(ret, '\r\n|}')
return table.concat(ret)
return table.concat(ret)
572

edits