4,951
edits
Falterfire (talk | contribs) (fixed a typo) |
Falterfire (talk | contribs) (Tweaked processArea code to make sure a type is always added properly) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local | local Items = require('Module:Items') | ||
function processArea(area, index, type) | |||
local result = Shared.clone(area) | |||
result.id = index - 1 | |||
if result.name == nil then | |||
result.name = result.areaName | |||
end | |||
result.type = type | |||
return result | |||
end | |||
function p.getArea(name) | function p.getArea(name) | ||
local result = nil | local result = nil | ||
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue | --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 | for i, area in pairs(AreaData.combatAreas) do | ||
if area.areaName == name then | if area.areaName == name then | ||
return processArea(area, i, 'combat') | |||
end | end | ||
end | end | ||
Line 22: | Line 29: | ||
for i, area in pairs(AreaData.slayerAreas) do | for i, area in pairs(AreaData.slayerAreas) do | ||
if area.areaName == name then | if area.areaName == name then | ||
return processArea(area, i, 'slayer') | |||
end | end | ||
end | end | ||
Line 30: | Line 35: | ||
for i, area in pairs(AreaData.dungeons) do | for i, area in pairs(AreaData.dungeons) do | ||
if area.name == name then | if area.name == name then | ||
return processArea(area, i, 'dungeon') | |||
end | end | ||
end | end | ||
Line 40: | Line 42: | ||
end | end | ||
function p. | function p.getAreaByID(type, id) | ||
local areaName = frame.args ~= nil and frame.args[1] or frame | 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) | local area = p.getArea(areaName) | ||
if area == nil then | if area == nil then | ||
return "ERROR: Could not find an area named "..areaName | return "ERROR: Could not find an area named "..areaName | ||
end | end | ||
if statName == 'slayerLevel' then | |||
if area. | return Icons._SkillReq('Slayer', area.slayerLevel) | ||
return | end | ||
if statName == 'slayerItem' then | |||
if area.slayerItem ~= nil and area.slayerItem > 0 then | |||
local slayItem = Items.getItemByID(area.slayerItem) | |||
return Icons.Icon({slayItem.name, type='item'}) | |||
else | |||
return 'None' | |||
end | |||
end | end | ||
return area[statName] | |||
end | end | ||
function p. | function p.getMonsterAreas(monsterID) | ||
local | 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, 'combat')) | |||
end | |||
end | end | ||
for i, area in pairs(AreaData.slayerAreas) do | |||
if Shared.contains(area.monsters, monsterID) then | |||
for i, | table.insert(areaArray, processArea(area, i, 'slayer')) | ||
if | |||
end | end | ||
end | end | ||
for i, area in pairs(AreaData.dungeons) do | |||
if Shared.contains(area.monsters, monsterID) then | |||
table.insert(areaArray, processArea(area, i, 'dungeon')) | |||
for i, | |||
if | |||
end | end | ||
end | end | ||
return areaArray | |||
return | |||
end | end | ||
return p | return p |