17,101
edits
(_buildAstrologyModifierArray: Add option to return standard modifier key/value pairs) |
(_buildAstrologyModifierArray: Further fixes to key/value pair return value) |
||
Line 739: | Line 739: | ||
local addToArray = function(modArray, modNew) | local addToArray = function(modArray, modNew) | ||
if not isDistinct or (isDistinct and not containsMod(modArray, modNew)) then | if not isDistinct or (isDistinct and not containsMod(modArray, modNew)) then | ||
table.insert(modArray, modNew) | |||
end | end | ||
end | end | ||
local modArray = {} | local modArray = {} | ||
local isSkillMod = {} | |||
-- Standard modifiers | -- Standard modifiers | ||
if includeStandard then | if includeStandard then | ||
Line 760: | Line 753: | ||
local modBaseName, modText, sign, isNegative, unsign, modBase = Constants.getModifierDetails(modName) | local modBaseName, modText, sign, isNegative, unsign, modBase = Constants.getModifierDetails(modName) | ||
-- Check if modifier varies by skill, and amend the modifier value accordingly | -- Check if modifier varies by skill, and amend the modifier value accordingly | ||
local modVal = | local modVal = modValue | ||
if Shared.contains(modText, '{SV0}') then | |||
isSkillMod[modName] = true | |||
modVal = {skillID, modValue} | |||
end | |||
addToArray(modArray, {modName, modVal}) | addToArray(modArray, {modName, modVal}) | ||
end | end | ||
Line 779: | Line 776: | ||
local modBaseName, modText, sign, isNegative, unsign, modBase = Constants.getModifierDetails(modName) | local modBaseName, modText, sign, isNegative, unsign, modBase = Constants.getModifierDetails(modName) | ||
if Shared.contains(modText, '{SV0}') then | if Shared.contains(modText, '{SV0}') then | ||
isSkillMod[modName] = true | |||
-- Check which skills the current modifier can be used for | -- Check which skills the current modifier can be used for | ||
for j, skillID in ipairs(cons.skills) do | for j, skillID in ipairs(cons.skills) do | ||
Line 791: | Line 789: | ||
end | end | ||
return modArray | if asKeyValue then | ||
local modArrayKV = {} | |||
for i, modDefn in ipairs(modArray) do | |||
local modName, modVal = modDefn[1], modDefn[2] | |||
local isSkill = isSkillMod[modName] | |||
if modArrayKV[modName] == nil then | |||
modArrayKV[modName] = (isSkill and { modVal } or modVal) | |||
elseif isSkill then | |||
table.insert(modArrayKV[modName], modVal) | |||
else | |||
modArrayKV[modName] = modArrayKV[modName] + modVal | |||
end | |||
end | |||
return modArrayKV | |||
else | |||
return modArray | |||
end | |||
end | end | ||