Anonymous

Module:CombatAreas: Difference between revisions

From Melvor Idle
_getAreaRequirements: Crude attempt to prevent the same requirement appearing twice
(Expose eventData for use in other modules)
(_getAreaRequirements: Crude attempt to prevent the same requirement appearing twice)
Line 98: Line 98:


function p._getAreaRequirements(area)
function p._getAreaRequirements(area)
  local result = ''
local result = ''
  local resultArray = {}
local resultArray = {}
  local addReqsToArray = function(reqArray, requirements)
local addReqsToArray = function(reqArray, requirements)
      for i, reqDetails in Shared.skpairs(requirements) do
for i, reqDetails in Shared.skpairs(requirements) do
        if reqDetails.type == 'Level' then
if reqDetails.type == 'Level' then
          for j, lvlDetails in Shared.skpairs(reqDetails.levels) do
for j, lvlDetails in Shared.skpairs(reqDetails.levels) do
            local skill = Constants.getSkillName(lvlDetails.skill)
local skill = Constants.getSkillName(lvlDetails.skill)
            table.insert(reqArray, Icons._SkillReq(skill, lvlDetails.level))
table.insert(reqArray, Icons._SkillReq(skill, lvlDetails.level))
          end
end
        elseif reqDetails.type == 'SlayerItem' then
elseif reqDetails.type == 'SlayerItem' then
          local item = Items.getItemByID(reqDetails.itemID)
local item = Items.getItemByID(reqDetails.itemID)
          table.insert(reqArray, Icons.Icon({item.name, type='item'})..' Equipped')
table.insert(reqArray, Icons.Icon({item.name, type='item'})..' Equipped')
        elseif reqDetails.type == 'Dungeon' then
elseif reqDetails.type == 'Dungeon' then
          for j, dungDetails in Shared.skpairs(reqDetails.dungeons) do
for j, dungDetails in Shared.skpairs(reqDetails.dungeons) do
            local dung = p.getAreaByID('dungeon', dungDetails.dungeonID)
local dung = p.getAreaByID('dungeon', dungDetails.dungeonID)
            if dungDetails.count > 1 then
if dungDetails.count > 1 then
              table.insert(reqArray, dungDetails.count..'x '..Icons.Icon({dung.name, type='dungeon'})..' Completions')
table.insert(reqArray, dungDetails.count..'x '..Icons.Icon({dung.name, type='dungeon'})..' Completions')
            else
else
              table.insert(reqArray, Icons.Icon({dung.name, type='dungeon'})..' Completed')
table.insert(reqArray, Icons.Icon({dung.name, type='dungeon'})..' Completed')
            end
end
          end
end
        elseif reqDetails.type == 'ShopPurchase' then
elseif reqDetails.type == 'ShopPurchase' then
          local shopPurchase = Shop.processPurchase(reqDetails.category, reqDetails.id)
local shopPurchase = Shop.processPurchase(reqDetails.category, reqDetails.id)
          if shopPurchase ~= nil then
if shopPurchase ~= nil then
          table.insert(reqArray, Shop._getPurchaseIcon({ shopPurchase }) .. ' Purchased')
table.insert(reqArray, Shop._getPurchaseIcon({ shopPurchase }) .. ' Purchased')
          end
end
        else
else
          table.insert(reqArray, 'ERROR: Unknown requirement type ' .. (reqDetails.type or 'nil') .. '[[Category:Pages with script errors]]')
table.insert(reqArray, 'ERROR: Unknown requirement type ' .. (reqDetails.type or 'nil') .. '[[Category:Pages with script errors]]')
        end
end
      end
end
    end
end
 
  if area.entryRequirements ~= nil then
    addReqsToArray(resultArray, area.entryRequirements)
  end


  if area.unlockRequirement ~= nil then
if area.entryRequirements ~= nil then
    addReqsToArray(resultArray, { area.unlockRequirement })
addReqsToArray(resultArray, area.entryRequirements)
  end
end


  result = table.concat(resultArray, '<br/>')
if area.unlockRequirement ~= nil then
  return result
-- Ensure this requirement isn't already part of the entry requirements
local addReq = true
if area.entryRequirements ~= nil then
local unlockReqStr = mw.dumpObject(area.unlockRequirement)
for i, reqDetails in ipairs(area.entryRequirements) do
-- Using mw.dumpObject() as a lazy way to compare tables
if area.unlockRequirement.type == reqDetails.type and mw.dumpObject(reqDetails) == unlockReqStr then
addReq = false
break
end
end
end
if addReq then
addReqsToArray(resultArray, { area.unlockRequirement })
end
end
 
result = table.concat(resultArray, '<br/>')
return result
end
end