Module:ModifierTables: Difference between revisions

Update for new skill modifier data structure
(Update for v1.1)
(Update for new skill modifier data structure)
Line 30: Line 30:
--By default, attempt to add the increased and decreased prefixes to the modifier
--By default, attempt to add the increased and decreased prefixes to the modifier
--But if getOpposites is false, only look for an exact match
--But if getOpposites is false, only look for an exact match
local increaseMod, decreaseMod = '', ''
local mods = {}
if getOpposites == nil or getOpposites then
if getOpposites == nil or getOpposites then
increaseMod = 'increased'..modifier
mods.inc = 'increased'..modifier
decreaseMod = 'decreased'..modifier
mods.dec = 'decreased'..modifier
else
else
increaseMod = modifier
mods.inc = modifier
end
end
local magnitude = { inc = 0, dec = 0 }
for modType, modName in pairs(mods) do
if modifiers[modName] ~= nil then
local valueArray = nil
            if type(modifiers[modName]) ~= 'table' then
                valueArray = {modifiers[modName]}
            else
                valueArray = modifiers[modName]
            end


local increaseVal, decreaseVal = 0, 0
            for i, subVal in ipairs(valueArray) do
if modifiers[increaseMod] ~= nil and modifiers[increaseMod] ~= nil then
                if type(subVal) == 'table' and subVal.skillID ~= nil then
if type(modifiers[increaseMod]) == 'table' then
                    -- Modifier value is skill specific
for i, subVal in Shared.skpairs(modifiers[increaseMod]) do
                    if skill == nil or skill == '' or subVal.skillID == skill then
if subVal[1] == skill then
                        magnitude[modType] = magnitude[modType] + subVal.value
increaseVal = subVal[2]
                    end
elseif skill == nil or skill == '' then
                else
increaseVal = increaseVal + subVal[2]
                    magnitude[modType] = magnitude[modType] + subVal
end
                end
end
            end
else
increaseVal = modifiers[increaseMod]
end
end
end
end


if modifiers[decreaseMod] ~= nil and modifiers[decreaseMod] ~= nil then
    return magnitude.inc - magnitude.dec
if type(modifiers[decreaseMod]) == 'table' then
for i, subVal in Shared.skpairs(modifiers[decreaseMod]) do
if subVal[1] == skill then
decreaseVal = subVal[2]
elseif skill == nil or skill == '' then
decreaseVal = decreaseVal + subVal[2]
end
end
else
decreaseVal = modifiers[decreaseMod]
end
end
 
return increaseVal - decreaseVal
end
end


Line 225: Line 220:
local mainModText = {}
local mainModText = {}
for modName, modValue in Shared.skpairs(modifiers) do
for modName, modValue in Shared.skpairs(modifiers) do
if Shared.contains(modifierNames, modName) then
                local includedMod = Shared.contains(modifierNames, modName)
if type(modValue) == 'table' and type(modValue[1]) == 'table' then
                local valueArray = nil
for j, subVal in ipairs(modValue) do
                if type(modValue) ~= 'table' then
if subVal[1] == skill or skill == nil or skill == '' then
                    valueArray = {modValue}
table.insert(mainModText, Constants._getModifierText(modName, subVal))
                else
else
                    valueArray = modValue
otherModCount = otherModCount + 1
                end
local key = ((maxOtherMods == nil or otherModCount <= maxOtherMods) and 'visible') or 'overflow'
 
table.insert(modTextArray[key], Constants._getModifierText(modName, subVal))
                for j, subVal in ipairs(valueArray) do
end
                    local includeInMainText = includedMod
end
                    if type(subVal) == 'table' and subVal.skillID ~= nil then
else
                        -- Modifier value is skill specific
table.insert(mainModText, Constants._getModifierText(modName, modValue))
                        if includeInMainText then
end
                            -- If the skill doesn't match then don't include in the main text
else
                            includeInMainText = skill == nil or skill == '' or subVal.skillID == skill
modValue = (type(modValue) == 'table' and type(modValue[1]) == 'table' and modValue or {modValue})
                        end
for j, subValue in ipairs(modValue) do
                    end
otherModCount = otherModCount + 1
 
local key = ((maxOtherMods == nil or otherModCount <= maxOtherMods) and 'visible') or 'overflow'
                    if includeInMainText then
table.insert(modTextArray[key], Constants._getModifierText(modName, subValue))
                        table.insert(mainModText, Constants._getModifierText(modName, subVal))
end
                    else
end
                        otherModCount = otherModCount + 1
end
                        local key = ((maxOtherMods == nil or otherModCount <= maxOtherMods) and 'visible') or 'overflow'
                        table.insert(modTextArray[key], Constants._getModifierText(modName, subVal))
                    end
                end
            end


local overflowModCount = Shared.tableCount(modTextArray['overflow'])
local overflowModCount = Shared.tableCount(modTextArray['overflow'])