Module:CombatAreas
Data is pulled from Module:GameData/data
NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters
--NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters
local p = {}
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Common = require('Module:Common')
local Icons = require('Module:Icons')
local areaMap = {
["combat"] = 'combatAreas',
["dungeon"] = 'dungeons',
["slayer"] = 'slayerAreas'
}
function p.getArea(name)
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
for k, areaType in pairs(areaMap) do
local area = GameData.getEntityByName(areaType, name)
if area ~= nil then
return area
end
end
end
function p.getAreaByID(id, type)
local areaType = areaMap[type]
if areaType ~= nil then
return GameData.getEntityByID(areaType, id)
end
end
function p.getAreaFilterType(name, type)
local areaType = areaMap[type]
if areaType ~= nil then
return GameData.getEntityByName(areaType, name)
end
end
function p.getAreas(checkFunc)
local resultArray = nil
for i, areaType in pairs(areaMap) do
local areas = GameData.getEntities(areaType, checkFunc)
if resultArray == nil then
resultArray = areas
else
for k, area in ipairs(areas) do
table.insert(resultArray, area)
end
end
end
if resultArray == nil then
resultArray = {}
end
return resultArray
end
--Returns the expansion icon for the area if it has one
function p.getExpansionIcon(frame)
local areaName = frame.args ~= nil and frame.args[1] or frame
local area = p.getArea(areaName)
if area == nil then
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
end
return Icons.getExpansionIcon(area.id)
end
function p._getAreaRequirements(area)
local resultArray = {}
if area.entryRequirements ~= nil then
table.insert(resultArray, Common.getRequirementString(area.entryRequirements, ''))
end
if area.unlockRequirement ~= nil then
-- Avoid repeating the same requirements twice, can happen for some dungeons e.g. Impending Darkness
if area.entryRequirements == nil or mw.dumpObject(area.unlockRequirement) ~= mw.dumpObject(area.entryRequirements) then
table.insert(resultArray, Common.getRequirementString(area.unlockRequirement, ''))
end
end
return table.concat(resultArray, '<br/>')
end
function p._getAreaStat(area, statName)
if statName == 'requirements' then
return p._getAreaRequirements(area)
elseif statName == 'areaEffectDesc' then
if area.areaEffect ~= nil then
local descText, subIdx = string.gsub(area.areaEffectDescription, '${effectValue}', area.areaEffect.magnitude or 0)
return descText
else
return 'None'
end
elseif statName == 'difficulty' then
local result = Constants.getDifficultyString(area.difficulty[1])
if area.difficulty[2] ~= nil then
result = result..' - '..Constants.getDifficultyString(area.difficulty[2])
end
return result
end
return area[statName]
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 Shared.printError('No area named "' .. areaName .. '" exists in the data module')
end
return p._getAreaStat(area, statName)
end
function p.getMonsterAreas(monsterID)
-- Special handling for Lair of the Spider Queen, which has a random list of enemies
local randomSpiderCheck = Shared.contains(GameData.rawData.spiderLairMonsters, monsterID)
return p.getAreas(
function(area)
return Shared.contains(area.monsterIDs, monsterID) or
(randomSpiderCheck and Shared.contains(area.monsterIDs, 'melvorTotH:RandomSpiderLair'))
end)
end
function p.getDungeonRequirements(frame)
local areaName = frame.args ~= nil and frame.args[1] or frame
local area = p.getArea(areaName)
if area == nil then
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
end
local result = p._getAreaStat(area, 'requirements')
if result ~= '' then
result = "\r\n|-\r\n|'''Requirements:'''<br/>"..result
end
return result
end
return p