Magia Record English Wiki
Advertisement

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
 
 
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 skill = ""
    local connect_effects = nil
    local magia_effects = nil
    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"}}
    return skills, skill
    
    

   -- return connect_effects, skills
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 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(magias, girl .. "¬Unknown. Could not get abilities")
        else
            effects_nr = max_lvl - min_lvl + 1
            --result, connect_effects, magia_effects = pcall(girls_effect, frame, girl, effect, effects_nr)
            connect_effects, magia_effects = 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 magia_effects then
                   table.insert(magias, girl .. "¬" .. magia_effects) 
                end
            else
                table.insert(connects, girl .. "¬Unknown. Could not get abilities" .. tostring(result))
                table.insert(magias, girl .. "¬Unknown. Could not get abilities" .. tostring(result))
            end
        end
    end



    table.sort(connects)
    table.sort(magias)
    
    output = ""
    if connects[1] then
        output = connects[1]
        for id= 2, #connects do
            output = output .. ";" .. connects[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 .. "¤"

    return output
 
end
 
return p
Advertisement