Anonymous

Module:LevelUpTable/Data: Difference between revisions

From Melvor Idle
Add agility requirements
(Add additional requirements for Astrology)
(Add agility requirements)
Line 31: Line 31:
     end
     end
     return result
     return result
end
function First(list, predicate)
for _, item in ipairs(list) do
if predicate(item) == true then
return item
end
end
error('No item found that matches predicate.')
end
end


Line 138: Line 147:
return UnlockData.new(x.id, x.name, Skills.getRecipeLevel(skillID, x), skillID)
return UnlockData.new(x.id, x.name, Skills.getRecipeLevel(skillID, x), skillID)
end)
end)
end
function getAgilityData(realm)
return getAgilityRequirements('Agility', realm)
end
end


Line 160: Line 173:
     return nil
     return nil
end
end
 
-- Gets the unlockRequirement for the tagged skill.
function getSkillUnlock(unlockRequirements)
for _, req in ipairs(unlockRequirements) do
if req.skillID == skillID then
return req
end
end
end
-- Gets all unlockRequirements that are not for the tagged skill.
function getOtherUnlock(unlockRequirements)
return Where(unlockRequirements,
function(req)
return req.skillID ~= skillID
end)
end
local filterFunc = function(x)
local filterFunc = function(x)
return Skills.getRecipeRealm(x) == realm.id and getUnlockReqs(x)
return Skills.getRecipeRealm(x) == realm.id and getUnlockReqs(x)
Line 185: Line 181:
return Select(constellations, function(const)
return Select(constellations, function(const)
local unlockReqs = getUnlockReqs(const)
local unlockReqs = getUnlockReqs(const)
local myUnlocks = getSkillUnlock(unlockReqs)
local myUnlocks = First(unlockReqs, function(req) return req.skillID == skillID end)
local otherUnlocks = getOtherUnlock(unlockReqs)
local otherUnlocks = Where(unlockReqs, function(req) return req.skillID ~= skillID end)
local data = UnlockData.new(const.id, const.name, myUnlocks.level, skill)
local data = UnlockData.new(const.id, const.name, myUnlocks.level, skill)
Line 193: Line 189:
for _, req in ipairs(otherUnlocks) do
for _, req in ipairs(otherUnlocks) do
table.insert(data.otherRequirements, UnlockData.new(const.id, const.name, req.level, req.type))
table.insert(data.otherRequirements, UnlockData.new(const.id, const.name, req.level, req.type))
end
return data
end)
end
function getAgilityRequirements(skill, realm)
local skillID = Constants.getSkillID(skill)
local AgilitySkillID = Constants.getSkillID('Agility')
local AgilityID = 'Agility'
function hasSkill(obstacle)
if obstacle.skillRequirements == nil then
return false
end
for _, req in pairs(obstacle.skillRequirements) do
if req.skillID == skillID then return true end
end
return false
end
function flattenRequirements(obstacle)
local skillRequirements = {}
for _, req in pairs(obstacle.skillRequirements) do
table.insert(skillRequirements, { level = req.level, skillID = req.skillID })
end
table.insert(skillRequirements, { level = Skills.getRecipeLevelRealm('Agility', obstacle), skillID = AgilitySkillID })
return skillRequirements
end
local filterFunc = function(x)
return Skills.getRecipeRealm(x) == realm.id and hasSkill(x)
end
local obstacles = nil
if skill == 'Agility' then
obstacles = getDataSet(SkillData.Agility.obstacles, realm)
else
obstacles = GameData.getEntities(SkillData.Agility.obstacles, filterFunc)
end
-- Add agility skill requirement to requirements list.
return Select(obstacles, function(o)
local unlockReqs = flattenRequirements(o)
local myUnlock = First(unlockReqs, function(req) return req.skillID == skillID end)
local otherUnlocks = Where(unlockReqs, function(req) return req.skillID ~= skillID end)
local data = UnlockData.new(o.id, o.name, myUnlock.level, skill)
data.otherRequirements = {}
for _, req in ipairs(otherUnlocks) do
local _, skillName = GameData.getLocalID(req.skillID)
table.insert(data.otherRequirements, UnlockData.new(o.id, o.name, req.level, skillName))
end
end
return data
return data
Line 201: Line 249:
local realmName = 'Abyssal Realm'
local realmName = 'Abyssal Realm'
local realm = Skills.getRealmFromName(realmName)
local realm = Skills.getRealmFromName(realmName)
Debug.log(getAstrologyRequirements('Herblore', realm))
Debug.log(getAgilityData(realm))
end
end


p.UnlockData = UnlockData
p.UnlockData = UnlockData
return p
return p
2,875

edits