17,105
edits
(Support modifier matching by properties such as skill ID, item ID, etc.) |
(Implement modType criteria for checking if a modifier is deemed to have a positive or negative effect upon the target) |
||
Line 160: | Line 160: | ||
error('Value for criteria ' .. criteriaKey .. ' cannot be nil', 2) | error('Value for criteria ' .. criteriaKey .. ' cannot be nil', 2) | ||
end | end | ||
if criteriaKey == 'valueType' then | if criteriaKey == 'valueType' or criteriaKey == 'modType' then | ||
-- Special | -- Special cases: | ||
-- valueType restricts by sign of modifier value | |||
-- modType restricts by whether the modifier is deemed to be a positive or | |||
-- negative to the target | |||
dataCriteria[criteriaKey] = string.lower(criteriaName) | dataCriteria[criteriaKey] = string.lower(criteriaName) | ||
elseif ScopeKeyMap[criteriaKey] ~= nil then | elseif ScopeKeyMap[criteriaKey] ~= nil then | ||
Line 200: | Line 203: | ||
-- "valueType". This indicates whether the value of the modifier should be positive ('pos') or | -- "valueType". This indicates whether the value of the modifier should be positive ('pos') or | ||
-- negative ('neg') in order for the criteria to be met | -- negative ('neg') in order for the criteria to be met | ||
function p.checkScopeDataMeetsCriteria(scopeData, scopeDefn, dataCriteria) | function p.checkScopeDataMeetsCriteria(modDefn, scopeData, scopeDefn, dataCriteria) | ||
for criteriaKey, criteriaValue in pairs(dataCriteria) do | for criteriaKey, criteriaValue in pairs(dataCriteria) do | ||
if criteriaKey == 'valueType' then | if criteriaKey == 'valueType' then | ||
Line 213: | Line 216: | ||
-- Value criteria not met | -- Value criteria not met | ||
return false | return false | ||
end | |||
elseif criteriaKey == 'modType' then | |||
if criteriaValue ~= nil and scopeData.value ~= nil then | |||
local isInverted = modDefn.inverted | |||
if isInverted == nil then | |||
isInverted = false | |||
end | |||
local isPositive = ((isInverted and scopeData.value < 0) or (not isInverted and scopeData.value > 0)) | |||
if not ( | |||
(criteriaValue == 'pos' and isPositive) | |||
or (criteriaValue == 'neg' and not isPositive) | |||
) then | |||
-- Mod type criteria not met | |||
return false | |||
end | |||
end | end | ||
elseif criteriaValue ~= nil and criteriaKey ~= 'key' then | elseif criteriaValue ~= nil and criteriaKey ~= 'key' then | ||
Line 317: | Line 335: | ||
matchCriteriaMap[modLocalID] = {} | matchCriteriaMap[modLocalID] = {} | ||
end | end | ||
table.insert(matchCriteriaMap[modLocalID], { ["scope"] = scopeDefn, ["alias"] = modAlias, ["props"] = propCriteria }) | table.insert(matchCriteriaMap[modLocalID], { | ||
["mod"] = modDefn, | |||
["scope"] = scopeDefn, | |||
["alias"] = modAlias, | |||
["props"] = propCriteria | |||
}) | |||
end | end | ||
Line 339: | Line 362: | ||
local modScopeDefn = p.convertScopeDataToDefinition(scopeData) | local modScopeDefn = p.convertScopeDataToDefinition(scopeData) | ||
for _, matchDefn in ipairs(modMatchCriteria) do | for _, matchDefn in ipairs(modMatchCriteria) do | ||
local scopeDefn, modAlias, propCriteria = matchDefn.scope, matchDefn.alias, matchDefn.props | local modDefn, scopeDefn, modAlias, propCriteria = matchDefn.mod, matchDefn.scope, matchDefn.alias, matchDefn.props | ||
local matchKey = 'unmatched' | local matchKey = 'unmatched' | ||
-- Check that: | -- Check that: | ||
Line 347: | Line 370: | ||
if ( | if ( | ||
p.doScopeDefinitionsMatch(modScopeDefn, scopeDefn) | p.doScopeDefinitionsMatch(modScopeDefn, scopeDefn) | ||
and p.checkScopeDataMeetsCriteria(scopeData, scopeDefn, modAlias) | and p.checkScopeDataMeetsCriteria(modDefn, scopeData, scopeDefn, modAlias) | ||
and p.checkScopeDataMeetsCriteria(scopeData, scopeDefn, propCriteria) | and p.checkScopeDataMeetsCriteria(modDefn, scopeData, scopeDefn, propCriteria) | ||
) then | ) then | ||
-- Add to matched table | -- Add to matched table |