Magia Record English Wiki
No edit summary
(Undo revision 53911 by KitYanagi (talk))
Line 34: Line 34:
 
local counter = 0
 
local counter = 0
 
 
local skills = frame:expandTemplate{ title = 'Template:'.. girl .. ', args = {'Get', "Connect effect 1", "Connect effect 2", "Connect effect 3", "Connect effect 4", "Connect effect 5", "Connect effect 6"}}
+
local skills = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Connect effect 1", "Connect effect 2", "Connect effect 3", "Connect effect 4", "Connect effect 5", "Connect effect 6"}}
 
 
 
--skills can look something like HP Restore¤MP Restore to Nanami Yachiyo¤Attack Up¤¤¤
 
--skills can look something like HP Restore¤MP Restore to Nanami Yachiyo¤Attack Up¤¤¤

Revision as of 18:27, 3 January 2020

Documentation for this module may be created at Module:EffectCounter/doc

local p = {}
 
-- Returns a string as Girl_A_name,Girl_A_effect;Girl_B_name,Girl_B_effect; (...)¤Memoria_A_name,Memoria_A_Effect;(...)
-- The girls and memorias are listed in lexicographical order
-- Only Girls and memoria with the relevant effect are included
 
--[[
 ----------------
 ----- NOTE -----
 -- If the code raises a node limit exceeded error, reduce the amount of frame:expandTemplate calls, girls_effect should be the simple and natural target
About:
 The preprocessor node count measures the complexity of the page (not the volume of data). As the parser is expanding a page, it creates a data structure known as a tree that corresponds to the HTML structure of the page. Each node of the tree that is visited during expansion is counted towards the preprocessor node count. If this count is exceeded, the parser will abort parsing with the error "Node-count limit exceeded" visible in the generated HTML.

The count starts with 1 for plain text. A pair of nowiki tags counts for 3, a header for 2, etc. A link does not contribute to the count. For the expansion of #switch every checked condition adds 2 to the count. In the case of multiple expansions of the same template the content of a template without arguments counts only once, but that of a template with arguments (even if constant) counts multiple times. In contrast to this, the result of an expansion can be used multiple times while counting only once if it is assigned to a template parameter, and that template has multiple uses of this parameter.

Pages exceeding this limit are automatically categorized into Category:Pages where node count is exceeded.
 ---------------
 --]]
 
function p.main(frame)
    local character_list_page = frame.args['CharacterListSource']
    local memoria_list_page = frame.args['MemoriaListSource']
    local effect = frame.args['effect']:lower()
    return p.render(frame, character_list_page, memoria_list_page, effect)
end

function girls_effect(frame, girl, effect, lvl)
    local nskill = ""
    local connect_effects = nil
    local passive_ex_effects = nil
    local skill_se_effects = {}
    local magia_effects = nil
    local counter = 0
    
    local skills = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Connect effect 1",  "Connect effect 2", "Connect effect 3", "Connect effect 4", "Connect effect 5", "Connect effect 6"}}
    
    --skills can look something like HP Restore¤MP Restore to Nanami Yachiyo¤Attack Up¤¤¤
    --(skills .. ¤) concatenates a ¤ character to the end in case none exist
    --gmatch splits up the string according to the regular expression (space)*(any character but ¤)*(space)*(¤)
    for skill in (skills .. "¤"):gmatch("%s*([^¤]*)%s*¤") do
        counter = counter + 1
        if skill ~= "" then --Not all 6 connect effects are filled out. Must check for empty string.
            formated_skill = "Chance to " .. skill .. " on Attack to"
            formated_skill = formated_skill:match(".*Chance to (.-) on Attack.*to.*") 
            formated_skill = (formated_skill .. " ("):match("(.-) %(.*")   --Include connects to unique targets, all on edges, chance skills, and region specific (region given in parantheses) 
            if formated_skill:lower() == effect then
                connect_effects = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Connect " .. counter .. " / " .. lvl}}
                if connect_effects == "" or connect_effects == "{{{ Connect " .. counter .. " / " .. lvl .."\n }}}" then
                    connect_effects = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Connect " .. counter .. " effect / " .. lvl}} .. " / [" .. frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Connect " .. counter .. " chance / " .. lvl}} .. "]"
                end
            end
        end
    end
    
    skill = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', 'EX effect 1'}}
    
    if skill:lower() == effect then
        passive_ex_effects = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', 'EX 1 max'}}
    else
        skill = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', 'EX effect 2'}}
        if skill:lower() == effect then
            passive_ex_effects = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', 'EX 2 max'}}
        end
    end
    
    -- expandTemplate 'Get' will only retrieve 6 per call
    skills = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get',  'Passive 1 effect', 'Passive 2 effect', 'Passive 3 effect', 'Passive 4 effect', 'Passive 5 effect', 'Passive 6 effect'}}
    
    for skill in (skills .. "¤"):gmatch("%s*([^¤]*)%s*¤") do
        if skill ~= "" then
            for subskill in (skill .. "&"):gmatch("%s*(.-)&%s*") do
                target_duration = nil
                if subskill:find("%(") then
                    target_duration = subskill:match(".*(%(.-%))")
                else
                    target_duration = skill:match(".*(%(.-%))")
                end
                subskill = (subskill.. "("):match("(.-)%(.*")  -- Remove target and duration
                if subskill:find("%[") then
                    skill0, value = subskill:match("(.-)%s*%[(.-)]")
                else 
                    skill0, value = subskill, "100%"
                end
                formated_skill = "Chance to " .. skill0 .. " on Attack" .. " to"
                skill0 = (formated_skill):match(".*Chance to (.-)%s- on Attack.*to.*")  --Include connects to unique targets, all on edges, and chance skills
                if skill0:lower() == effect then
                    local unique = true
                    for k,v in pairs(skill_se_effects) do
                        if v == value then unique = false end
                    end
                    if unique then
                        if target_duration then
                            table.insert(skill_se_effects, value .. " " .. target_duration)     
                        else
                            table.insert(skill_se_effects, value)
                        end
                    end
                end
            end
        end
    end
    
    skills = skills .. "¤" .. frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', 'Passive 7 effect', 'Passive 8 effect', 'Passive 9 effect', 'Passive 10 effect', 'Passive 11 effect', 'Passive 12 effect'}}
    
    for skill in (skills .. "¤"):gmatch("%s*([^¤]*)%s*¤") do
        if skill ~= "" then
            for subskill in (skill .. "&"):gmatch("%s*(.-)&%s*") do
                target_duration = nil
                if subskill:find("%(") then
                    target_duration = subskill:match(".*(%(.-%))")
                else
                    target_duration = skill:match(".*(%(.-%))")
                end
                subskill = (subskill.. "("):match("(.-)%(.*")  -- Remove target and duration
                if subskill:find("%[") then
                    skill0, value = subskill:match("(.-)%s*%[(.-)]")
                else 
                    skill0, value = subskill, "100%"
                end
                formated_skill = "Chance to " .. skill0 .. " on Attack" .. " to"
                skill0 = (formated_skill):match(".*Chance to (.-)%s- on Attack.*to.*")  --Include connects to unique targets, all on edges, and chance skills
                if skill0:lower() == effect then
                    local unique = true
                    for k,v in pairs(skill_se_effects) do
                        if v == value then unique = false end
                    end
                    if unique then
                        if target_duration then
                            table.insert(skill_se_effects, value .. " " .. target_duration)     
                        else
                            table.insert(skill_se_effects, value)
                        end
                    end
                end
            end
        end
    end
    
    skills = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', 'Passive 13 effect', 'Active 1 effect'}}
    
    for skill in (skills .. "¤"):gmatch("%s*([^¤]*)%s*¤") do
        if skill ~= "" then
            for subskill in (skill .. "&"):gmatch("%s*(.-)&%s*") do
                target_duration = nil
                if subskill:find("%(") then
                    target_duration = subskill:match(".*(%(.-%))")
                else
                    target_duration = skill:match(".*(%(.-%))")
                end
                subskill = (subskill.. "("):match("(.-)%(.*")  -- Remove target and duration
                if subskill:find("%[") then
                    skill0, value = subskill:match("(.-)%s*%[(.-)]")
                else 
                    skill0, value = subskill, "100%"
                end
                formated_skill = "Chance to " .. skill0 .. " on Attack" .. " to"
                skill0 = (formated_skill):match(".*Chance to (.-)%s- on Attack.*to.*")  --Include connects to unique targets, all on edges, and chance skills
                if skill0:lower() == effect then
                    local unique = true
                    for k,v in pairs(skill_se_effects) do
                        if v == value then unique = false end
                    end
                    if unique then
                        if target_duration then
                            table.insert(skill_se_effects, value .. " " .. target_duration)     
                        else
                            table.insert(skill_se_effects, value)
                        end
                    end
                end
            end
        end
    end
    
    counter = 0
    skills = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Magia effect 1",  "Magia effect 2", "Magia effect 3", "Magia effect 4", "Magia effect 5", "Magia effect 6"}}
    for skill in (skills .. "¤"):gmatch("%s*([^¤]*)%s*¤") do
        counter = counter + 1
        if skill ~= "" then
            formated_skill = "Chance to " .. skill .. " on Attack to"
            formated_skill = formated_skill:match(".*Chance to (.-) on Attack.*to.*") 
            formated_skill = (formated_skill .. " ("):match("(.-) %(.*")   --Include connects to unique targets, all on edges, chance skills, and region specific (region given in parantheses) ls, and region specific (region given in parantheses) 
            if formated_skill:lower() == effect then
                magia_effects = frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Magia " .. counter .. " / " .. lvl}}
                if magia_effects == "" or magia_effects == "{{{ Magia " .. counter .. " / " .. lvl .."\n }}}" then
                        magia_effects =  frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Magia " .. counter .. " effect / " .. lvl}} .. " / [" .. frame:expandTemplate{ title = 'Template:'.. girl .. ' Abilities', args = {'Get', "Magia " .. counter .. " chance / " .. lvl}} .. "]"
                end
            end
        end
    end
    
    
    return connect_effects, passive_ex_effects, skill_se_effects, magia_effects
end
 
function p.render(frame, character_list_page, memoria_list_page, effect)
    local girls = frame:expandTemplate{ title = character_list_page }
    local memos = frame:expandTemplate{ title = memoria_list_page }
    local connects = {}
    local passives_ex = {}
    local skills_se = {}
    local magias = {}
    local memorias = {}
        
    for girl in (girls .. ";"):gmatch("%s*([^;]*)%s*;") do
        min_lvl, max_lvl = frame:expandTemplate{ title = 'Template:'.. girl, args = {'Get', 'base_rarity', 'max_rarity'}}:match("^(.*)¤(.*)$")
        if min_lvl == nil then
            table.insert(connects, girl .. "¬Unknown. Could not get abilities")
            table.insert(passives_ex, girl .. "¬Unknown. Could not get abilities")
            table.insert(skills_se, girl .. "¬Unknown. Could not get abilities")
            table.insert(magias, girl .. "¬Unknown. Could not get abilities")
        else
            effects_nr = max_lvl - min_lvl + 1
    
            
            result, connect_effects, ex_effects, se_effects, magia_effects = pcall(girls_effect, frame, girl, effect, effects_nr)
            
            if result then  -- If pcall returns not error
                if connect_effects then
                    table.insert(connects, girl .. "¬" .. connect_effects)
                end
                if ex_effects then
                    table.insert(passives_ex, girl .. "¬" .. ex_effects) 
                end
                for index = 1, #se_effects do
                    table.insert(skills_se, girl .. "¬" .. se_effects[index])
                end
                if magia_effects then
                    table.insert(magias, girl .. "¬" .. magia_effects) 
                end
            else
                table.insert(connects, girl .. "¬Unknown. Could not get abilities / " .. tostring(result))
                table.insert(passives_ex, girl .. "¬Unknown. Could not get abilities / " .. tostring(result))
                table.insert(skills_se, girl .. "¬Unknown. Could not get abilities / " .. tostring(result))
                table.insert(magias, girl .. "¬Unknown. Could not get abilities / " .. tostring(result))
            end
        end
    end

    for memo in (memos .. ";"):gmatch("%s*([^;]*)%s*;") do
        skills = frame:expandTemplate{ title = 'Template:'.. memo, args = {'Get', 'effect2'}} 
        for subskill in (skills .. "&"):gmatch("%s*(.-)&%s*") do
            target_duration = nil
            if subskill:find("%(") then
                target_duration = subskill:match(".*(%(.-%))")
            else
                target_duration = skills:match(".*(%(.-%))")
            end
            subskill = (subskill.. "("):match("(.-)%(.*")  -- Remove target and duration
            if subskill:find("%[") then
                skill, value = subskill:match("(.-)%s*%[(.-)]")
            else 
                skill, value = subskill, "100%"
            end
            formated_skill = "Chance to " .. skill .. " on Attack" .. " to"
            skill = (formated_skill):match(".*Chance to (.-)%s- on Attack.*to.*")  --Include connects to unique targets, all on edges, and chance skills
            if skill:lower() == effect then
                if target_duration then
                    table.insert(memorias, memo .. "¬" .. value .. " " .. target_duration)
                else
                    table.insert(memorias, memo .. "¬" .. value)
                end
            end
        end
    end

    table.sort(connects)
    table.sort(passives_ex)
    table.sort(skills_se)
    table.sort(magias)
    table.sort(memorias)
    
    output = ""
    if connects[1] then
        output = connects[1]
        for id= 2, #connects do
            output = output .. ";" .. connects[id]
        end
    end
    output = output .. "¤"
    if passives_ex[1] then
        output = output .. passives_ex[1]
        for id= 2, #passives_ex do
            output = output .. ";" .. passives_ex[id]
        end
    end
    output = output .. "¤"
    if skills_se[1] then
        output = output .. skills_se[1]
        for id= 2, #skills_se do
            output = output .. ";" .. skills_se[id]
        end
    end
    output = output .. "¤"
    if magias[1] then
        output = output .. magias[1]
        for id= 2, #magias do
            output = output .. ";" .. magias[id]
        end
    end
    output = output .. "¤"
    if memorias[1] then
        output = output .. memorias[1]
        for id= 2, #memorias do
            output = output .. ";" .. memorias[id]
        end
    end
    
    if output == "¤¤¤¤" then
        return result
    else
        return output
    end
 
end
 
return p