Anonymous

Module:Constants: Difference between revisions

From Melvor Idle
further rework of slayer
(Refactor Slayer tier functions)
(further rework of slayer)
Line 329: Line 329:
[4] = 'Very Hard',
[4] = 'Very Hard',
[5] = 'Elite',
[5] = 'Elite',
[6] = 'Insane'}
[6] = 'Insane'
}


function p.getTriangleAttribute(attribute, attackerStyle, targetStyle, mode)
function p.getTriangleAttribute(attribute, attackerStyle, targetStyle, mode)
Line 412: Line 413:
end
end


function p.getSlayerTierName(tier)
return type(tier) == 'number' and ConstantData.slayerTier[tier] or "ERROR: Invalid Slayer tier[[Category:Pages with script errors]]"
end


function p.getSlayerTierNameByLevel(lvl)
--- Slayer functions
local tier = p.getSlayerTierByLevel(lvl)
--
if tier == nil then
function p.getSlayerTierByID(tierID) -- returns a full table
return 'N/A'
if not type(tier) == 'number' then
else
return nil
return tier.display
elseif ConstantData.Slayer.Tiers[tierID + 1] == nil then
end
end
 
function p.getSlayerTierByID(tierID)
if ConstantData.Slayer.Tiers[tierID + 1] == nil then
return nil
return nil
else
else
Line 435: Line 428:
end
end


function p.getSlayerTier(name)
function p.getSlayerTierByLevel(level) -- returns a full table
if not type(level) == 'number' or tier < 0 then
return "ERROR: Invalid Slayer level [[Category:Pages with script errors]]"
end
for i, tier in ipairs(ConstantData.Slayer.Tiers) do
if tier.minLevel <= level then
-- is tier.maxLevel == nil really necessary?
if (tier.maxLevel == nil) or (tier.maxLevel >= level) then
return p.getSlayerTierByID(i - 1)
end
end
end
end
 
function p.getSlayerTierByName(name) -- returns a full table
local tierID = ConstantData.slayerTier[name]
local tierID = ConstantData.slayerTier[name]
if tierID == nil then
if tierID == nil then
Line 444: Line 452:
end
end


function p.getSlayerTierByLevel(level)
--
for i, tier in ipairs(ConstantData.Slayer.Tiers) do
-- the following function just return subsets of the slayer functions above
if tier.minLevel <= level and (tier.maxLevel == nil or tier.maxLevel >= level) then
--
return p.getSlayerTierByID(i - 1)
 
end
function p.getSlayerTierName(tier, fallback) -- consider replacing with comment
local tier = p.getSlayerTierByID(tier).display
if tier ~= nil then
return tier.display
else
return fallback or "ERROR: Invalid Slayer tier [[Category:Pages with script errors]]"
end
end
 
function p.getSlayerTierNameByLevel(lvl, fallback)
local tier = p.getSlayerTierByLevel(lvl)
if tier ~= nil then
return tier.display
else
return fallback or "ERROR: Invalid Slayer tier [[Category:Pages with script errors]]"
end
end
end
end
function p.getSlayerTier(name) -- consider removing this function (may break other pages)
return p.getSlayerTierIdByName(name)
end
--
--- End of slayer functions


--Turns a modifier name like 'increasedMeleeAccuracyBonus' into several pieces of data:
--Turns a modifier name like 'increasedMeleeAccuracyBonus' into several pieces of data:
892

edits