17,101
edits
mNo edit summary |
(Amend logic for obtaining skill level requirements, implements _getItemLevelReqs()) |
||
Line 12: | Line 12: | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local Num = require('Module:Number') | local Num = require('Module:Number') | ||
-- Used by p._getItemLevelReqs() | |||
local LevelReqCache = {} | |||
p.EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon', 'Easter Egg', | p.EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon', 'Easter Egg', | ||
Line 79: | Line 82: | ||
return slot | return slot | ||
end | end | ||
end | |||
end | |||
-- Given an item, returns a table containing the item's level requirements (if any) | |||
-- The table structure is as follows: | |||
-- { ['normal'] = { SkillID = SkillLevel, ... }, ['abyssal'] = { SkillID = SkillLevel, ... } } | |||
-- If optional parameter 'condense' is specified as true, any normal requirements are excluded | |||
-- from the output if there should exist an abyssal level requirement for the same skill | |||
function p._getItemLevelReqs(item, condense) | |||
local condenseResult = (type(condense) == 'boolean' and condense) or false | |||
local reqTypeMap = { | |||
['SkillLevel'] = 'normal', | |||
['AbyssalLevel'] = 'abyssal' | |||
} | |||
local levelReqs = LevelReqCache[item.id] | |||
if levelReqs == nil then | |||
-- Item not in cache - obtain level requirements data | |||
if item.equipRequirements == nil then | |||
return nil | |||
end | |||
levelReqs = { ['normal'] = {}, ['abyssal'] = {} } | |||
for _, requirement in ipairs(item.equipRequirements) do | |||
local reqTypeKey = reqTypeMap[requirement.type] | |||
if reqTypeKey ~= nil then | |||
-- Requirement is a level requirement | |||
local reqSkillID, reqLevel = requirement.skillID, requirement.level | |||
local reqCurrentLevel = levelReqs[reqTypeKey][reqSkillID] | |||
if reqCurrentLevel == nil or reqLevel > reqCurrentLevel then | |||
levelReqs[reqTypeKey][reqSkillID] = reqLevel | |||
end | |||
end | |||
end | |||
-- Cache level requirements data for any subsequent lookups | |||
LevelReqCache[item.id] = levelReqs | |||
end | |||
if not condenseResult then | |||
-- Return requirements as is | |||
return levelReqs | |||
else | |||
-- Exclude any normal level requirements should an abyssal requirement exist for | |||
-- the same skill | |||
local levelReqsCondensed = { ['normal'] = {}, ['abyssal'] = levelReqs.abyssal } | |||
for skillID, reqLevel in pairs(levelReqs.normal) do | |||
if levelReqs.abyssal[skillID] == nil then | |||
levelReqsCondensed.normal[skillID] = reqLevel | |||
end | |||
end | |||
return levelReqsCondensed | |||
end | end | ||
end | end | ||
Line 97: | Line 149: | ||
result = false | result = false | ||
end | end | ||
elseif string.find(StatName, '^(.+)LevelRequired$') ~= nil and item.equipRequirements ~= nil then | elseif ( | ||
local skillName = | string.find(StatName, '^(.+)LevelRequired$') ~= nil | ||
if skillName | or string.find(StatName, '^(.+)AbyssalLevel$') ~= nil | ||
) and item.equipRequirements ~= nil then | |||
local levelType = 'normal' | |||
local skillName = string.match(StatName, '^(.+)LevelRequired$') | |||
if skillName == nil then | |||
levelType = 'abyssal' | |||
skillName = string.match(StatName, '^(.+)AbyssalLevel$') | |||
end | end | ||
if skillName ~= nil then | if skillName ~= nil then | ||
local skillID = Constants.getSkillID(skillName) | local skillID = Constants.getSkillID(Shared.titleCase(skillName)) | ||
if skillID ~= nil then | if skillID ~= nil then | ||
local levelReqs = p._getItemLevelReqs(item) | |||
result = levelReqs ~= nil and levelReqs[levelType][skillID] | |||
end | end | ||
end | end | ||
Line 286: | Line 329: | ||
function p._hasLevelRequirements(item) | function p._hasLevelRequirements(item) | ||
--Function true if an item has at least one level requirement to equip | --Function true if an item has at least one level requirement to equip | ||
if | local levelReqs = p._getItemLevelReqs(item) | ||
for | if levelReqs ~= nil then | ||
if | for levelType, reqs in pairs(levelReqs) do | ||
if not Shared.tableIsEmpty(reqs) then | |||
return true | return true | ||
end | end |