Module:CombatAreas: Difference between revisions

Added requirements code and made it work with slayer stuff
(areaName => name)
(Added requirements code and made it work with slayer stuff)
Line 94: Line 94:
end
end


function p._getAreaStat(area, statName)
function p._getAreaRequirements(area)
  if statName == 'slayerLevel' then
  local result = ''
    return Icons._SkillReq('Slayer', area.slayerLevel)
  local resultArray = {}
  elseif statName == 'slayerItem' then
  local addReqsToArray = function(reqArray, requirements)
    if area.slayerItem ~= nil and area.slayerItem > 0 then
      for i, reqDetails in Shared.skpairs(requirements) do
      local slayItem = Items.getItemByID(area.slayerItem)
        mw.log(reqDetails.type)
      return Icons.Icon({slayItem.name, type='item'})
        if reqDetails.type == 'Level' then
    else
          for j, lvlDetails in Shared.skpairs(reqDetails.levels) do
      return 'None'
            local skill = Constants.getSkillName(lvlDetails.skill)
    end
            table.insert(reqArray, Icons._SkillReq(skill, lvlDetails.level))
  elseif statName == 'dungeonReq' then
          end
    if area.requiresCompletion ~= nil and area.requiresCompletion >= 0 then
        elseif reqDetails.type == 'SlayerItem' then
      local dung = p.getAreaByID('dungeon', area.requiresCompletion)
          local item = Items.getItemByID(reqDetails.itemID)
      local compCount = area.requiresCompletionCount ~= nil and area.requiresCompletionCount or 1
          table.insert(reqArray, Icons.Icon({item.name, type='item'})..' Equipped')
      if compCount > 1 then
        elseif reqDetails.type == 'Dungeon' then
        return compCount..'x '..Icons.Icon({dung.name, type='dungeon'})..' Completions'
          for j, dungDetails in Shared.skpairs(reqDetails.dungeons) do
      else
            local dung = p.getAreaByID('dungeon', dungDetails.dungeonID)
        return Icons.Icon({dung.name, type='dungeon'})..' Completed'
            if dungDetails.count > 1 then
              table.insert(reqArray, dungDetails.count..'x '..Icons.Icon({dung.name, type='dungeon'})..' Completions')
            else
              table.insert(reqArray, Icons.Icon({dung.name, type='dungeon'})..' Completed')
            end
          end
        end
       end
       end
    else
      return ''
     end
     end
 
  if area.entryRequirements ~= nil then
    addReqsToArray(resultArray, area.entryRequirements)
  end
  if area.unlockRequirement ~= nil then
    addReqsToArray(resultArray, { area.unlockRequirement })
  end
  result = table.concat(resultArray, '<br/>')
  return result
end
function p._getAreaStat(area, statName)
  if statName == 'requirements' then
    return p._getAreaRequirements(area)
   elseif statName == 'areaEffectDesc' then
   elseif statName == 'areaEffectDesc' then
     if area.areaEffect ~= nil and area.areaEffect then
     if area.areaEffect ~= nil and area.areaEffect then
Line 177: Line 197:
   end
   end


   local result = p._getAreaStat(area, 'dungeonReq')
   local result = p._getAreaStat(area, 'requirements')
   if result ~= '' then
   if result ~= '' then
     result = "\r\n|-\r\n|'''Requirements:'''<br/>"..result
     result = "\r\n|-\r\n|'''Requirements:'''<br/>"..result