Module:LevelUpTable/Data: Difference between revisions

Add additional requirements for Astrology
(Add farming plot data)
(Add additional requirements for Astrology)
Line 8: Line 8:
local Items = require('Module:Items')
local Items = require('Module:Items')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Constants = require('Module:Constants')


local UnlockData = {}
local UnlockData = {}
Line 18: Line 19:
     self.skill = skill
     self.skill = skill
     self.id = id
     self.id = id
    self.otherRequirements = nil
     return self
     return self
end
end
Line 27: Line 29:
     for _, item in ipairs(list) do
     for _, item in ipairs(list) do
         table.insert(result, selector(item))
         table.insert(result, selector(item))
    end
    return result
end
-- Mimicks the C# Where method.
function Where(tbl, predicate)
    local result = {}
    for _, v in ipairs(tbl) do
        if predicate(v) then
            table.insert(result, v)
        end
     end
     end
     return result
     return result
Line 116: Line 129:


return Concat(seeds, plots)
return Concat(seeds, plots)
end
function getAstrologyData(realm)
local skillID = 'Astrology'
local data = getDataSet(SkillData.Astrology.recipes, realm)
return Select(data, function(x)
return UnlockData.new(x.id, x.name, Skills.getRecipeLevel(skillID, x), skillID)
end)
end
--==== Other Requirements Collection ====--
function getAstrologyRequirements(skill, realm)
-- Only Abyssal Astrology has level unlock requirements as of V1.3
local skillID = Constants.getSkillID(skill)
local AstroID = 'Astrology'
-- Find if this constellation has the provided skill as an unlock requirement.
function getUnlockReqs(constellation)
if constellation.abyssalModifiers == nil then return nil end
for _, mod in ipairs(constellation.abyssalModifiers) do
        if mod.unlockRequirements then
            for _, req in ipairs(mod.unlockRequirements) do
                if req.skillID == skillID then
                -- Return the unlockRequirements table, so we can reuse this function later to retrieve unlock data.
                return mod.unlockRequirements
                end
                end
            end
end
    return nil
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)
return Skills.getRecipeRealm(x) == realm.id and getUnlockReqs(x)
end
local constellations = GameData.getEntities(SkillData.Astrology.recipes, filterFunc)
return Select(constellations, function(const)
local unlockReqs = getUnlockReqs(const)
local myUnlocks = getSkillUnlock(unlockReqs)
local otherUnlocks = getOtherUnlock(unlockReqs)
local data = UnlockData.new(const.id, const.name, myUnlocks.level, skill)
data.otherRequirements = {}
table.insert(data.otherRequirements, UnlockData.new(const.id, const.name, Skills.getRecipeLevel(AstroID, const), AstroID))
for _, req in ipairs(otherUnlocks) do
table.insert(data.otherRequirements, UnlockData.new(const.id, const.name, req.level, req.type))
end
return data
end)
end
end


function p.test()
function p.test()
--local realmName = 'Abyssal Realm'
local realmName = 'Abyssal Realm'
local realm = Skills.getRealmFromName(realmName)
local realm = Skills.getRealmFromName(realmName)
Debug.log(getFarmingData(realm))
Debug.log(getAstrologyRequirements('Herblore', realm))
end
end


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

edits