Module:Damage: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 63: Line 63:
     end
     end


     -- Output passives if provided.
     -- Output passives if provided
     local passive1 = 0
     local passives = {0, 0, 0}
     local passive2 = 0
     for i=1, 3 do
 
        if inArgs('passive' .. i) then
    if inArgs('passive1') then
            passives[i] = args['passive' .. i]
        passive1 = args.passive1
            passives[i] = split(frame:preprocess('{{:' .. passives[i] .. '}}{{#arrayprint:' .. passives[i] .. '}}'))
        passive1 = split(frame:preprocess('{{:' .. passive1 .. '}}{{#arrayprint:' .. passive1 .. '}}'))
        end
    end
 
    if inArgs('passive2') then
        passive2 = args.passive2
        passive2 = split(frame:preprocess('{{:' .. passive2 .. '}}{{#arrayprint:' .. passive2 .. '}}'))
     end
     end
      
      
Line 84: Line 79:
         local fvals = {}
         local fvals = {}
         local tvals = {}
         local tvals = {}
         local pvals1 = {}
         local pvals = {
        local pvals2 = {}
            [1]={},
        local pvals12 = {}
            [2]={},
            [3]={},
            [12]={},
            [13]={},
            [23]={},
            [123]={},
        }


         -- Check the specified mode and define the prefixes/suffixes first.
         -- Check the specified mode and define the prefixes/suffixes first.
Line 172: Line 173:
         tableMerge(ftvals, tvals)
         tableMerge(ftvals, tvals)


         if inArgs('passive2') then
         function addPassive(num, loop_table)
 
            local pval_index
             for k, v in spairs(ftvals) do
            if loop_table == nil then
                 local dmg_name = k .. '_passive2'
                pval_index = num
                loop_table = ftvals
            else
                pval_index = tonumber(loop_table .. num)
                loop_table = pvals[loop_table]
            end
             for k, v in spairs(loop_table) do
                 local dmg_name = k .. '_passive' .. num
                 if ispvp then
                 if ispvp then
                     dmg_name = dmg_name:gsub(su, '') .. su
                     dmg_name = dmg_name:gsub(su, '') .. su
                 end
                 end
                 local dmg_formula = v * passive2[p_index]
                 local dmg_formula = v * passives[num][p_index]
                 pvals2[dmg_name] = dmg_formula
                 pvals[pval_index][dmg_name] = dmg_formula
             end
             end
        end


        -- Add passives and combine them.
        if inArgs('passive2') then
            addPassive(2)
            if inArgs('passive3') then addPassive(3, 2) end
         end
         end


         if inArgs('passive1') then
         if inArgs('passive1') then
 
             addPassive(1)
             for k, v in spairs(ftvals) do
                local dmg_name = k .. '_passive1'
                if ispvp then
                    dmg_name = dmg_name:gsub(su, '') .. su
                end
                local dmg_formula = v * passive1[p_index]
                pvals1[dmg_name] = dmg_formula
            end
 
            -- Combine both passives.
             if inArgs('passive2') then
             if inArgs('passive2') then
                 for k, v in spairs(pvals1) do
                 addPassive(2, 1)
                    local dmg_name = k .. '_passive2'
                if inArgs('passive3') then addPassive(3, 12) end
                    if ispvp then
                        dmg_name = dmg_name:gsub(su, '') .. su
                    end
                    pvals12[dmg_name] = v * passive2[p_index]
                end
             end
             end
            if inArgs('passive3') then addPassive(3, 1) end
        end


         end
         if inArgs('passive3') then addPassive(3) end


         -- Merge all tables into one.
         -- Merge all tables into one.
         tableMerge(fvals, tvals)
         tableMerge(fvals, tvals)
         tableMerge(fvals, pvals1)
         for k, v in spairs(pvals) do
        tableMerge(fvals, pvals2)
            tableMerge(fvals, v)
         tableMerge(fvals, pvals12)
         end


         return fvals
         return fvals