Module:Modifiers: Difference between revisions

getMatchCriteriaFromIDs: Fix processing of scopes from modifier IDs
No edit summary
(getMatchCriteriaFromIDs: Fix processing of scopes from modifier IDs)
Line 184: Line 184:
end
end


-- Add all scopes
for _, allowedScope in ipairs(modDefn.allowedScopes) do
for _, allowedScope in ipairs(modDefn.allowedScopes) do
if Shared.tableIsEmpty(allowedScope.scopes) then
table.insert(matchCriteria, {
-- No scope definitions, so add modifier once with an empty scope
["mod"] = modDefn,
table.insert(matchCriteria, {
["scope"] = allowedScope.scopes or {}
["mod"] = modDefn,
})
["scope"] = {}
})
else
-- Add all available scope definitions
for _, scopeDefn in ipairs(allowedScope.scopes) do
table.insert(matchCriteria, {
["mod"] = modDefn,
["scope"] = scopeDefn
})
end
end
end
end
end
end
Line 656: Line 646:


function p.test3()
function p.test3()
local item = GameData.getEntityByID('items', 'melvorD:Aorpheats_Signet_Ring')
local item = GameData.getEntityByID('items', 'melvorF:Miners_Helmet')
local matchCriteria = {
local matchCriteria = {
{
{
Line 664: Line 654:
--}
--}
-- Should no longer match if changed to increased
-- Should no longer match if changed to increased
["alias"] = 'decreasedChanceToDoubleItemsSkill',
["alias"] = 'increasedChanceNoDamageMining',
},
},
{
{
Line 700: Line 690:
return p.getModifierValue(matchedMods.matched)
return p.getModifierValue(matchedMods.matched)
--return p.getMatchingModifiers(purch.contains.modifiers, matchCriteria)
--return p.getMatchingModifiers(purch.contains.modifiers, matchCriteria)
end
 
-- Checks p.getMatchCriteriaFromIDs() and p.getMatchingModifiers()
-- Any entity processed by this should return a table with all modifiers
-- matched and none unmatched. Unmatched modifiers implies an issue with one
-- of the aforementioned functions
function p.test5()
local ent = GameData.getEntityByID('items', 'melvorF:Miners_Helmet')
local entMods = ent.modifiers
if entMods ~= nil then
local modIDs = {}
for modID, modDet in pairs(entMods) do
table.insert(modIDs, modID)
end
local matchCriteria = p.getMatchCriteriaFromIDs(modIDs, nil)
mw.logObject(matchCriteria)
mw.log('=======================================================')
local matchingMods = p.getMatchingModifiers(entMods, matchCriteria)
return matchingMods
end
return nil
end
end


return p
return p