Module:AuronTest: Difference between revisions

m
Adapt to revised data format
mNo edit summary
m (Adapt to revised data format)
Line 92: Line 92:
   end
   end
   return result
   return result
end
-- Input: equipmentStats property of an item in the format { { ["key"] = "stabAttackBonus", ["value"] = 2 }, ... }
-- Output: Table in the format { ["stabAttackBonus"] = 2, ... }
function p._processEquipmentStats(equipStats)
  local out = {}
  if type(equipStats) == 'table' then
    for i, stat in pairs(equipStats) do
      local k, v = stat["key"], stat["value"]
      if out[k] == nil then
        out[k] = v
      else
        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
  return out
end
end


Line 133: Line 99:
   -- Equipment stats first
   -- Equipment stats first
   if Shared.contains(ItemData.EquipmentStatKeys, StatName) and item.equipmentStats ~= nil then
   if Shared.contains(ItemData.EquipmentStatKeys, StatName) and item.equipmentStats ~= nil then
     local equipStats = p._processEquipmentStats(item.equipmentStats)
     result = item.equipmentStats[StatName]
    result = equipStats[StatName]
   elseif StatName == 'isTwoHanded' then
   elseif StatName == 'isTwoHanded' then
     if item.validSlots ~= nil and item.occupiesSlots ~= nil then
     if item.validSlots ~= nil and item.occupiesSlots ~= nil then
       return Shared.contains(item.validSlots, 'Weapon') and Shared.contains(item.occupiesSlots, 'Shield')
       result = Shared.contains(item.validSlots, 'Weapon') and Shared.contains(item.occupiesSlots, 'Shield')
     else
     else
       return false
       result = false
     end
     end
   elseif string.find(StatName, '^(.+)LevelRequired$') ~= nil then
   elseif string.find(StatName, '^(.+)LevelRequired$') ~= nil and item.equipRequirements ~= nil and item.equipRequirements.Level ~= nil then
     local skillName = Shared.titleCase(string.match(StatName, '^(.+)LevelRequired$'))
     local skillName = Shared.titleCase(string.match(StatName, '^(.+)LevelRequired$'))
     if skillName ~= nil then
     if skillName ~= nil then
       local levelReqs = p._processEquipmentLevelReqs(item.equipRequirements)
       local skillID = Constants.getSkillID(skillName)
       result = levelReqs[skillName]
       if skillID ~= nil then
        result = item.equipRequirements.Level[skillID]
      end
     end
     end
   elseif StatName == 'attackType' then
   elseif StatName == 'attackType' then
Line 154: Line 121:
   elseif StatName == 'completionReq' then
   elseif StatName == 'completionReq' then
     if item.ignoreCompletion == nil or not item.ignoreCompletion then
     if item.ignoreCompletion == nil or not item.ignoreCompletion then
       return 'Yes'
       result = 'Yes'
     else
     else
       return 'No'
       result = 'No'
     end
     end
   elseif StatName == 'slayerBonusXP' then
   elseif StatName == 'slayerBonusXP' then
Line 219: Line 186:
   if not item.isEquipment or item.validSlots == nil and item.equipmentStats ~= nil then
   if not item.isEquipment or item.validSlots == nil and item.equipmentStats ~= nil then
     -- Ensure at least one stat has a non-zero value
     -- Ensure at least one stat has a non-zero value
    local equipStats = p._processEquipmentStats(item.equipmentStats)
     for statName, statVal in pairs(item.equipmentStats) do
     for statName, statVal in pairs(equipStats) do
       if statVal ~= 0 then return true end
       if statVal ~= 0 then return true end
     end
     end