12,704
edits
(_buildAstrologyModifierArray: Initial implementation; _buildAstrologyConstellationTable: Use _buildAstrologyModifierArray) |
(_buildAstrologyModifierArray: Further fixes to key/value pair return value) |
||
(One intermediate revision by the same user not shown) | |||
Line 718: | Line 718: | ||
-- includeUnique: true|false, determines whether unique modifiers are included | -- includeUnique: true|false, determines whether unique modifiers are included | ||
-- isDistinct: true|false, if true, the returned list of modifiers is de-duplicated | -- isDistinct: true|false, if true, the returned list of modifiers is de-duplicated | ||
function p._buildAstrologyModifierArray(cons, modValue, includeStandard, includeUnique, isDistinct) | -- asKeyValue: true|false, if true, returns key/value pairs like usual modifier objects | ||
function p._buildAstrologyModifierArray(cons, modValue, includeStandard, includeUnique, isDistinct, asKeyValue) | |||
-- Temporary function to determine if the table already contains a given modifier | -- Temporary function to determine if the table already contains a given modifier | ||
local containsMod = function(modList, modNew) | local containsMod = function(modList, modNew) | ||
Line 734: | Line 735: | ||
end | end | ||
return false | return false | ||
end | |||
local addToArray = function(modArray, modNew) | |||
if not isDistinct or (isDistinct and not containsMod(modArray, modNew)) then | |||
table.insert(modArray, modNew) | |||
end | |||
end | end | ||
local modArray = {} | local modArray = {} | ||
local isSkillMod = {} | |||
-- Standard modifiers | -- Standard modifiers | ||
if includeStandard then | if includeStandard then | ||
Line 745: | 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 | end | ||
addToArray(modArray, {modName, modVal}) | |||
end | end | ||
end | end | ||
Line 767: | 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 | ||
if not modBase.isSkill or (modBase.isSkill and skillArray[j].hasMastery) then | if not modBase.isSkill or (modBase.isSkill and skillArray[j].hasMastery) then | ||
addToArray(modArray, {modName, {skillID, modValue}}) | |||
end | end | ||
end | end | ||
else | |||
addToArray(modArray, {modName, modValue}) | |||
end | end | ||
end | end | ||
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 | ||
Line 804: | Line 827: | ||
result = result..'||'..table.concat(skillIconArray, '<br/>') | result = result..'||'..table.concat(skillIconArray, '<br/>') | ||
local standModsRaw = p._buildAstrologyModifierArray(cons, maxModifier, true, false, false) | local standModsRaw = p._buildAstrologyModifierArray(cons, maxModifier, true, false, false, false) | ||
local standMods = {} | local standMods = {} | ||
--Building the list of Standard modifiers: | --Building the list of Standard modifiers: | ||
Line 813: | Line 836: | ||
--Building the list of all Unique Modifiers | --Building the list of all Unique Modifiers | ||
local uModsRaw = p._buildAstrologyModifierArray(cons, maxModifier, false, true, false) | local uModsRaw = p._buildAstrologyModifierArray(cons, maxModifier, false, true, false, false) | ||
local uMods = {} | local uMods = {} | ||
for j, modifier in ipairs(uModsRaw) do | for j, modifier in ipairs(uModsRaw) do |