Module:CombatAreas: Difference between revisions

Update for v1.3
(p.getAreaStat now handles Slayer areas)
(Update for v1.3)
(31 intermediate revisions by 3 users not shown)
Line 1: Line 1:
--NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters
local p = {}
local p = {}


local Constants = mw.loadData('Module:Constants/data')
local Constants = require('Module:Constants')
local AreaData = mw.loadData('Module:CombatAreas/data')
 
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Common = require('Module:Common')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')


function processArea(area, index)
local areaMap = {
  local result = Shared.clone(area)
["combat"] = 'combatAreas',
  result.id = index - 1
["dungeon"] = 'dungeons',
  if result.name == nil then
["slayer"] = 'slayerAreas',
    result.name = result.areaName
["depth"] = 'abyssDepths'
  end
}
  if Shared.contains(result.type, 'Dungeon') then
 
    result.type = 'dungeon'
function p.getArea(name)
  end
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
  return result
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, areaType)
for aType, areaKey in pairs(areaMap) do
if areaType == nil or areaType == aType then
local area = GameData.getEntityByID(areaKey, id)
if area ~= nil then
return area
end
end
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
end


function p.getArea(name)
--Returns the expansion icon for the area if it has one
  local result = nil
function p.getExpansionIcon(frame)
  --There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
local areaName = frame.args ~= nil and frame.args[1] or frame
  for i, area in pairs(AreaData.combatAreas) do
local area = p.getArea(areaName)
    if area.areaName == name then
if area == nil then
      return processArea(area, i)
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
    end
end
  end
return Icons.getExpansionIcon(area.id)
end
 
function p._getAreaRequirements(area)
local resultArray = {}
if area.entryRequirements ~= nil then
local reqText = Common.getRequirementString(area.entryRequirements)
if reqText ~= nil then
table.insert(resultArray, reqText)
end
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
local reqText = Common.getRequirementString(area.unlockRequirement)
if reqText ~= nil then
table.insert(resultArray, reqText)
end
end
end


  for i, area in pairs(AreaData.slayerAreas) do
return table.concat(resultArray, '<br/>')
    if area.areaName == name then
end
      return processArea(area, i)
    end
  end


  for i, area in pairs(AreaData.dungeons) do
function p.getAreaRequirementsForBox(frame)
    if area.name == name then
--Returns infobox formatting for requirements, or returns nothing if there are none.
      return processArea(area, i)
local areaName = frame.args ~= nil and frame.args[1] or frame
    end
local area = p.getArea(areaName)
  end
if area == nil then
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
end


  return nil
local reqs = p._getAreaRequirements(area)
if reqs ~= '' then
reqs = "|-\r\n|'''Requirements:'''\r\n"..reqs
end
return reqs
end
end


function p.getAreaByID(type, id)
function p._getAreaStat(area, statName)
  if type == 'dungeon' then type = 'dungeons'
if statName == 'requirements' then
  elseif type == 'combat' then type = 'combatAreas'
return p._getAreaRequirements(area)
  elseif type == 'slayer' then type = 'slayerAreas' end
elseif statName == 'areaEffectDesc' then
  return processArea(AreaData[type][id + 1], id + 1)
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
end


function p.getAreaStat(frame)
function p.getAreaStat(frame)
  local areaName = frame.args ~= nil and frame.args[1] or frame[1]
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 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 Shared.printError('No area named "' .. areaName .. '" exists in the data module')
  end
end
  if statName == 'slayerLevel' then
    return Icons._SkillReq('Slayer', area.slayerLevel)
  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


  return area[statName]
return p._getAreaStat(area, statName)
end
end


function p.getMonsterAreas(monsterID)
function p._isMonsterInArea(monster, area)
  local areaArray = {}
return (
  --There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
Shared.contains(area.monsterIDs, monster.id)
  for i, area in pairs(AreaData.combatAreas) do
-- Check for Lair of the Spider Queen random spiders
    if Shared.contains(area.monsters, monsterID) then
or (
      table.insert(areaArray, processArea(area, i))
Shared.contains(area.monsterIDs, 'melvorTotH:RandomSpiderLair')
    end
and Shared.contains(GameData.rawData.spiderLairMonsters, monster.id)
  end
)
)
end
 
function p._getMonsterAreas(monster)
-- Special handling for Lair of the Spider Queen, which has a random list of enemies
local randomSpiderCheck = Shared.contains(GameData.rawData.spiderLairMonsters, monster.id)
return p.getAreas(
function(area)
return p._isMonsterInArea(monster, area)
end)
end


  for i, area in pairs(AreaData.slayerAreas) do
function p.getDungeonRequirements(frame)
    if Shared.contains(area.monsters, monsterID) then
local areaName = frame.args ~= nil and frame.args[1] or frame
      table.insert(areaArray, processArea(area, i))
local area = p.getArea(areaName)
    end
if area == nil then
  end
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
end


  for i, area in pairs(AreaData.dungeons) do
local result = p._getAreaStat(area, 'requirements')
    if Shared.contains(area.monsters, monsterID) then
if result ~= '' then
      table.insert(areaArray, processArea(area, i))
result = "\r\n|-\r\n|'''Requirements:'''<br/>"..result
    end
end
  end
return result
  return areaArray
end
end


return p
return p