Module:CombatAreas: Difference between revisions
From Melvor Idle
Falterfire (talk | contribs) (Added getAreaByID) |
Falterfire (talk | contribs) (Added getAreaStat) |
||
Line 49: | Line 49: | ||
elseif type == 'slayer' then type = 'slayerAreas' end | elseif type == 'slayer' then type = 'slayerAreas' end | ||
return processArea(AreaData[type][id + 1], id + 1) | return processArea(AreaData[type][id + 1], id + 1) | ||
end | |||
function p.getAreaStat(frame) | |||
local areaName = frame.args ~= nil and frame.args[1] or frame[1] | |||
local statName = frame.args ~= nil and frame.args[2] or frame[2] | |||
local area = p.getArea(areaName) | |||
if area == nil then | |||
return "ERROR: Could not find an area named "..areaName | |||
end | |||
return area[statName] | |||
end | end | ||
Revision as of 17:23, 1 December 2020
Data is pulled from Module:GameData/data
NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters
local p = {}
local Constants = mw.loadData('Module:Constants/data')
local AreaData = mw.loadData('Module:CombatAreas/data')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
function processArea(area, index)
local result = Shared.clone(area)
result.id = index - 1
if result.name == nil then
result.name = result.areaName
end
if Shared.contains(result.type, 'Dungeon') then
result.type = 'dungeon'
end
return result
end
function p.getArea(name)
local result = nil
mw.log(name)
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
for i, area in pairs(AreaData.combatAreas) do
if area.areaName == name then
return processArea(area, i)
end
end
for i, area in pairs(AreaData.slayerAreas) do
if area.areaName == name then
return processArea(area, i)
end
end
for i, area in pairs(AreaData.dungeons) do
if area.name == name then
return processArea(area, i)
end
end
return nil
end
function p.getAreaByID(type, id)
if type == 'dungeon' then type = 'dungeons'
elseif type == 'combat' then type = 'combatAreas'
elseif type == 'slayer' then type = 'slayerAreas' end
return processArea(AreaData[type][id + 1], id + 1)
end
function p.getAreaStat(frame)
local areaName = frame.args ~= nil and frame.args[1] or frame[1]
local statName = frame.args ~= nil and frame.args[2] or frame[2]
local area = p.getArea(areaName)
if area == nil then
return "ERROR: Could not find an area named "..areaName
end
return area[statName]
end
function p.getMonsterAreas(monsterID)
local areaArray = {}
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
for i, area in pairs(AreaData.combatAreas) do
if Shared.contains(area.monsters, monsterID) then
table.insert(areaArray, processArea(area, i))
end
end
for i, area in pairs(AreaData.slayerAreas) do
if Shared.contains(area.monsters, monsterID) then
table.insert(areaArray, processArea(area, i))
end
end
for i, area in pairs(AreaData.dungeons) do
if Shared.contains(area.monsters, monsterID) then
table.insert(areaArray, processArea(area, i))
end
end
return areaArray
end
return p