Anonymous

Module:Sandbox/AuronTest: Difference between revisions

From Melvor Idle
Implement _processEquipmentLevelReqs()
(_getItemStat: Don't waste time iterating over equipRequirements if the specified skill was not found)
(Implement _processEquipmentLevelReqs())
Line 117: Line 117:
       else
       else
         out[k] = out[k] + v
         out[k] = out[k] + v
      end
    end
  end
  return out
end
-- Input: equipRequirements property of an item
-- Output: Table in the format { ["Attack"] = 80, ... }
function p._processEquipmentLevelReqs(equipReqs)
  local out = {}
  if type(equipReqs) == 'table' then
    for i, req in pairs(equipReqs) do
      if req.type == 'Level' then
        for j, levelReq in pairs(req.levels) do
          local skillName = Constants.getSkillName(levelReq.skill)
          if skillName ~= nil then out[skillName] = levelReq.level end
        end
       end
       end
     end
     end
Line 138: Line 155:
   elseif string.find(StatName, '^(.+)LevelRequired$') ~= nil then
   elseif string.find(StatName, '^(.+)LevelRequired$') ~= nil then
     local skillName = Shared.titleCase(string.match(StatName, '^(.+)LevelRequired$'))
     local skillName = Shared.titleCase(string.match(StatName, '^(.+)LevelRequired$'))
     local skillID = Constants.getSkillID(skillName)
     if skillName ~= nil then
    if skillID ~= nil then
       local levelReqs = p._processEquipmentLevelReqs(item.equipRequirements)
       for i, req in pairs(item.equipRequirements) do
      result = levelReqs[skillName]
        if req.type == 'Level' then
          for j, levelReq in pairs(req.levels) do
            if levelReq.skill == skillID then
              result = levelReq.level
              break
            end
          end
          if result ~= nil then break end
        end
      end
     end
     end
   elseif StatName == 'attackType' then
   elseif StatName == 'attackType' then