Module:CombatAreas: Difference between revisions

Fixed an issue with getting difficulty not working when multiple difficulties were present
(getAreaFilterType)
(Fixed an issue with getting difficulty not working when multiple difficulties were present)
(7 intermediate revisions by 2 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 AreaData = mw.loadData('Module:CombatAreas/data')
local AreaData = mw.loadData('Module:CombatAreas/data')


local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
Line 68: Line 69:
end
end


function p.getAreaStat(frame)
function p._getAreaStat(area, statName)
  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
   if statName == 'slayerLevel' then
   if statName == 'slayerLevel' then
     return Icons._SkillReq('Slayer', area.slayerLevel)
     return Icons._SkillReq('Slayer', area.slayerLevel)
   end
   elseif statName == 'slayerItem' then
  if statName == 'slayerItem' then
     if area.slayerItem ~= nil and area.slayerItem > 0 then
     if area.slayerItem ~= nil and area.slayerItem > 0 then
       local slayItem = Items.getItemByID(area.slayerItem)
       local slayItem = Items.getItemByID(area.slayerItem)
Line 85: Line 79:
       return 'None'
       return 'None'
     end
     end
  elseif statName == 'dungeonReq' then
    if area.requiresCompletion ~= nil and area.requiresCompletion >= 0 then
      local dung = p.getAreaByID('dungeon', area.requiresCompletion)
      local compCount = area.requiresCompletionCount ~= nil and area.requiresCompletionCount or 1
      if compCount > 1 then
        return compCount..'x '..Icons.Icon({dung.name, type='dungeon'})..' Completions'
      else
        return Icons.Icon({dung.name, type='dungeon'})..' Completed'
      end
    else
      return ''
    end
  elseif statName == 'areaEffectDesc' then
    if area.areaEffect ~= nil and area.areaEffect then
      return area.areaEffectDescription
    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
   end


   return area[statName]
   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 "ERROR: Could not find an area named "..areaName
  end
  return p._getAreaStat(area, statName)
end
end


Line 105: Line 134:
   end
   end


   for i, area in pairs(AreaData.dungeons) do
   --Hill Giants specifically ignore dungeons to prevent the issue with Into the Mist incorrectly being listed.
    if Shared.contains(area.monsters, monsterID) then
  if monsterID ~= 1 then
      table.insert(areaArray, processArea(area, i, 'dungeon'))
    for i, area in pairs(AreaData.dungeons) do
      if Shared.contains(area.monsters, monsterID) then
        table.insert(areaArray, processArea(area, i, 'dungeon'))
      end
     end
     end
   end
   end
   return areaArray
   return areaArray
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 "ERROR: Could not find an area named "..areaName
  end
  local result = p._getAreaStat(area, 'dungeonReq')
  if result ~= '' then
    result = "\r\n|-\r\n|'''Requirements:'''<br/>"..result
  end
  return result
end
end


return p
return p