Anonymous

Module:Constants: Difference between revisions

From Melvor Idle
Refactor Slayer tier functions
m (typo)
(Refactor Slayer tier functions)
Line 417: Line 417:


function p.getSlayerTierNameByLevel(lvl)
function p.getSlayerTierNameByLevel(lvl)
for i, tier in Shared.skpairs(ConstantData.Slayer.Tiers) do
local tier = p.getSlayerTierByLevel(lvl)
if tier.minLevel <= lvl and (tier.maxLevel == nil or tier.maxLevel >= lvl) then
if tier == nil then
return tier.display
return 'N/A'
end
else
return tier.display
end
end
return 'N/A'
end
end


function p.getSlayerTierByLevel(level)
function p.getSlayerTierByID(tierID)
return p.getSlayerTier(p.getSlayerTierNameByLevel(level))
if ConstantData.Slayer.Tiers[tierID + 1] == nil then
return nil
else
local result = Shared.clone(ConstantData.Slayer.Tiers[tierID + 1])
result.id = tierID
return result
end
end
end


function p.getSlayerTier(name)
function p.getSlayerTier(name)
for i, tier in Shared.skpairs(ConstantData.Slayer.Tiers) do
local tierID = ConstantData.slayerTier[name]
if tier.display == name then
if tierID == nil then
local result = Shared.clone(tier)
return nil
result.id = i - 1
else
return result
return p.getSlayerTierByID(tierID)
end
end
end
end
end


function p.getSlayerTierByID(tierID)
function p.getSlayerTierByLevel(level)
if ConstantData.Slayer.Tiers[tierID + 1] == nil then
for i, tier in ipairs(ConstantData.Slayer.Tiers) do
return nil
if tier.minLevel <= level and (tier.maxLevel == nil or tier.maxLevel >= level) then
return p.getSlayerTierByID(i - 1)
end
end
end
local result = Shared.clone(ConstantData.Slayer.Tiers[tierID + 1])
result.id = tierID
return result
end
end