Module:CombatAreas

Revision as of 19:36, 7 October 2020 by Falterfire (talk | contribs) (Moving getAreaMonsterTable out to Module:Monsters to prevent loop)

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.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