Module:Sandbox/Constants: Difference between revisions

Updated Sign check in getModifierDetails
(Re-added nil check in the event a non-existent modifier gets pushed)
(Updated Sign check in getModifierDetails)
Line 907: Line 907:
--- End of slayer functions
--- End of slayer functions


--Turns a modifier name like 'increasedMeleeAccuracyBonus' into several pieces of data:
--Turns a modifier name like 'increasedHPRegenFlat' into several pieces of data:
--Base Name, Description, IsNegative, and modifierData
--Base Name, Description, Sign, IsNegative, valueUnsigned and modifyValue
--ex. "MeleeAccuracyBonus", "+${value}% Melee Accuracy Rating", false, table
--ex. "HPRegenFlat", "+${value} Flat Hitpoints Regeneration", "+", false, false, "multiplyByNumberMultiplier"
function p.getModifierDetails(modifierName)
function p.getModifierDetails(modifierName)
local baseName = modifierName
local baseName = modifierName
local valueUnsigned = false
local valueUnsigned = false
local modifier = GameData.rawData.modifierData[modifierName]
local modifier = GameData.rawData.modifierData[modifierName]
if Shared.startsWith(modifierName, "increased") or Shared.startsWith(modifierName, "decreased") then
baseName = string.sub(modifierName, 10)
end


if modifier == nil then
if modifier == nil then
Line 923: Line 919:
end
end


--TODO: Is this still needed?
if Shared.startsWith(modifierName, "increased") or Shared.startsWith(modifierName, "decreased") then
local sign = "+"
baseName = string.sub(modifierName, 10)
if string.match(modifier.description, '-${value}') then
end
sign = "-"
--TODO: This won't work for ReflectDamage: "+0-${value} Reflect Damage" and "-0-${value} Reflect Damage"
local i, j = string.find(modifier.description, '${value}')
local sign = string.sub(modifier.description, i-1, i-1)
if sign ~= "-" and sign ~= "+" then
sign = "+"
valueUnsigned = true
end
end


if string.match(modifier.description, ' ${value}') then valueUnsigned = true end
return baseName, modifier.description, sign, modifier.isNegative, valueUnsigned, modifier.modifyValue
 
return baseName, modifier.description, sign, modifier.isNegative, valueUnsigned, modifier
end
end


function p._getModifierText(modifier, value, doColor)
function p._getModifierText(modifier, value, doColor)
if doColor == nil then doColor = true end
if doColor == nil then doColor = true end
local modName, modText, sign, isNegative, valueUnsigned, modifierData = p.getModifierDetails(modifier)
local modName, modText, sign, isNegative, valueUnsigned, modifyValue = p.getModifierDetails(modifier)


if modName == nil then
if modName == nil then
return Shared.printError('Invalid modifier type for "' .. modifier .. '"')
return Shared.printError('Invalid modifier type for "' .. modifier .. '"')
end
end
--TODO: Untested: value+1; No items to test with
 
local formatModValue = function(value, rule)
local formatModValue = function(value, rule)
local ruleFunctions = {
local ruleFunctions = {
Line 964: Line 963:
end
end
}
}
local ruleFunc = ruleFunctions[modifierData.modifyValue] or ruleFunctions['value']
local ruleFunc = ruleFunctions[modifyValue] or ruleFunctions['value']
if type(value) == 'table' then
if type(value) == 'table' then