Module:Attacks: Difference between revisions

Implement support for multiple definitions per effect
(Initial creation)
 
(Implement support for multiple definitions per effect)
Line 9: Line 9:
p.effectDefinition = {
p.effectDefinition = {
     ["Burn"] = {
     ["Burn"] = {
         ["type"] = 'DOT',
         {
         ["subtype"] = 'Burn'
            ["type"] = 'DOT',
            ["subtype"] = 'Burn'
         },
        -- Alternative definition specifically for familiars like Dragon
        {
            ["type"] = 'Modifier',
            ["subtype"] = 'Familiar',
            ["modifiers"] = {
                ["include"] = { 'increasedChanceToApplyBurn' }
            }
        }
     },
     },
     ["Poison"] = {
     ["Poison"] = {
Line 99: Line 109:
-- Determines if attack applies the effect defined in effectDefinition
-- Determines if attack applies the effect defined in effectDefinition
function p.attackHasEffect(attack, effectDefn)
function p.attackHasEffect(attack, effectDefn)
     if type(attack) == 'table' and type(effectDefn) == 'table' and type(effectDefn.type) == 'string' then
     if type(attack) == 'table' and type(effectDefn) == 'table' then
         -- Process pre-hit effects
         -- Process pre-hit effects
         for i, effect in ipairs(attack.prehitEffects) do
         for i, effect in ipairs(attack.prehitEffects) do
Line 116: Line 126:
end
end


function p.effectMatchesDefn(effect, effectDefn)
function p.effectMatchesDefn(effect, effectDefnIn)
    -- Some effects (e.g. Burn) have multiple definitions, so handle these correctly
    local effectDefnList = nil
    if effectDefnIn[1] ~= nil and type(effectDefnIn[1]) == 'table' then
        -- Definition is actually multiple definitions
        effectDefnList = effectDefnIn
    else
        -- Definition is singular, wrap it within a table so we can iterate
        effectDefnList = { effectDefnIn }
    end
 
    for i, effectDefn in pairs(effectDefnList) do
        if p.effectMatchesDefnSingle(effect, effectDefn) then
            return true
        end
    end
    return false
end
 
function p.effectMatchesDefnSingle(effect, effectDefn)
     if effectDefn.type ~= effect.type then
     if effectDefn.type ~= effect.type then
         -- Effect's type doesn't match that of the effect definition
         -- Effect's type doesn't match that of the effect definition