FANDOM


local lists = require("Module:Lists")
 
local wikitable = [===[{| class="sortable article-table" style="width: 200px; text-align:center; white-space: nowrap;"
! scope="col" |[[%s]]
! scope="col" |[[%s]]
|-
%s
|}]===]
 
local duotable = [===[{| class="sortable article-table" style="width: 500px; text-align:center; white-space: nowrap;"
|+ %s - %s
! scope="col" |[[%s]]
! scope="col" |[[%s]]
! scope="col" |[[%s]]
! scope="col" |%s
|-
%s
|}]===]
 
local fulltable = [===[{| class="article-table" style="width: 500px; text-align:center; white-space: nowrap;"
! scope="row" | -------
%s
|-
%s
|}]===]
 
local function header(first_title, second_title)
    return string.format(table_header, first_title, second_title)
end
 
local function get_index(headers, value)
    for i, header in ipairs(headers) do
        if header == value then
            return i    
        end
    end
    return nil
end
 
local function get_row(records, col_headers, row_headers, row_header)
    local i = get_index(row_headers, row_header)
    local row = records[i]
    local ret = {}
    local position = 0
    for j, col_header in ipairs(col_headers) do
        local value = row[j]
        if value then
            position = position + 1
            ret[position] = {col_header, value}
        end
    end
    return ret
end
 
local function get_col(records, col_headers, row_headers, col_header)
    local j = get_index(col_headers, col_header)
    local ret = {}
    local position = 0
 
    for i, row_header in ipairs(row_headers) do
        local value = records[i][j]
        if value then
            position = position + 1
            ret[position] = {row_header, value}
        end
    end
    return ret
end
 
local function get_skills(records, col_headers, row_headers, skill)
    local ret = {}
    local position = 0
    for j, col_header in ipairs(col_headers) do
        for i, row_header in ipairs(row_headers) do
            local value = records[i][j]
            if value == skill then
                position = position + 1
                ret[position] = {col_header, row_header}
            end
        end
    end
    return ret
end
 
local function get_skills_faster(records, header_size, row_size, skill)
    local ret = {}
    local position = 0
    for i = 1, row_size do
        local row = records[i]
        for j = 1, header_size do
            local value = row[j]
            if value == skill then
                position = position + 1
                ret[position] = {j, i}
            end
        end
    end
    return ret
end
 
local function intersect(table1, table2, records, a, b, c)
    local size1 = #table1
    local size2 = #table2
    local ret = {}
    local position = 0
    for i = 1, size1 do
        for j = 1, size2 do
            if table1[i][2] == table2[j][1] then
                position = position + 1
                ret[position] = {[a]=table1[i][1], [b]=table1[i][2], [c]=table2[j][2], ["s"]=records[table1[i][1]][table2[j][2]]}
            end
        end
    end
    return ret
end
 
local function concatenate_tables(source, object)
    local insert_position = #source
    local object_size = #object
    for i = 1, object_size do
        source[insert_position+i] = object[i]
    end
end
 
local function remove_dups(data)
    local hashes = {}
    local size = #data
    local position = 0
    local ret = {}
    for i = 1, size do
        local value = data[i]
        local hash = 10000*value.p + 100*value.a + value.w
        if (not hashes[hash]) then
            hashes[hash] = true
            position = position + 1
            ret[position] = value
        end
    end
    return ret
end
 
local function sort_quads(lhs, rhs)
    if lhs.w ~= rhs.w then
        return lhs.w < rhs.w
    end
    if lhs.a ~= rhs.a then
        return lhs.a < rhs.a
    end
    if lhs.p ~= rhs.p then
        return lhs.p < rhs.p
    end
    return false
end
 
local function get_duos_2(recordsWeaponArmor, recordsArmorPet, recordsPetWeapon, wantedSkill_1, wantedSkill_2)
    local wa1 = get_skills_faster(recordsWeaponArmor, #lists.weapons, #lists.armor, wantedSkill_1)
    local wa2 = get_skills_faster(recordsWeaponArmor, #lists.weapons, #lists.armor, wantedSkill_2)
    local ap1 = get_skills_faster(recordsArmorPet, #lists.armor, #lists.pets, wantedSkill_1)
    local ap2 = get_skills_faster(recordsArmorPet, #lists.armor, #lists.pets, wantedSkill_2)
    local pw1 = get_skills_faster(recordsPetWeapon, #lists.pets, #lists.weapons, wantedSkill_1)
    local pw2 = get_skills_faster(recordsPetWeapon, #lists.pets, #lists.weapons, wantedSkill_2)
 
    ret = {}
    concatenate_tables(ret, intersect(wa1, ap2, recordsPetWeapon, "w", "a", "p"))
    concatenate_tables(ret, intersect(wa2, ap1, recordsPetWeapon, "w", "a", "p"))
    concatenate_tables(ret, intersect(ap1, pw2, recordsWeaponArmor, "a", "p", "w"))
    concatenate_tables(ret, intersect(ap2, pw1, recordsWeaponArmor, "a", "p", "w"))
    concatenate_tables(ret, intersect(pw1, wa2, recordsArmorPet, "p", "w", "a"))
    concatenate_tables(ret, intersect(pw2, wa1, recordsArmorPet, "p", "w", "a"))
    ret = remove_dups(ret)
    table.sort(ret, sort_quads)
    return ret;
end
 
local function render_pairs(first_title, second_title, first_renderer, second_renderer, my_pairs)
    for i, my_pair in ipairs(my_pairs) do
        my_pairs[i] = string.format("|%s||%s", first_renderer.getLink(my_pair[1]), second_renderer.getLink(my_pair[2]))
    end
    return string.format(wikitable, first_title, second_title, table.concat(my_pairs, "\n|-\n"))
end
 
local function render_skill_pairs(first_title, second_title, first_renderer, second_renderer, my_pairs)
    for i, my_pair in ipairs(my_pairs) do
        my_pairs[i] = string.format("|%s||%s", first_renderer.getLink(my_pair[1]), second_renderer.getLink(my_pair[2]))
    end
    return string.format(wikitable, first_title, second_title, table.concat(my_pairs, "\n|-\n"))
end
 
local function render_duo_quads(first_title, second_title, third_title, fourth_title, wantedSkill_1, wantedSkill_2, renderer, my_quads)
    for i, my_quad in ipairs(my_quads) do
        my_quads[i] = string.format("|%s||%s||%s||%s",
            renderer.Weapon.getLink(lists.weapons[my_quad.w]),
            renderer.Armor.getLink(lists.armor[my_quad.a]),
            renderer.Pet.getLink(lists.pets[my_quad.p]),
            my_quad.s and renderer.Skill.getLink(my_quad.s) or " - ")
    end
    return string.format(duotable, renderer.Skill.getLink(wantedSkill_1), renderer.Skill.getLink(wantedSkill_2), first_title, second_title, third_title, fourth_title, table.concat(my_quads, "\n|-\n"))
end
 
local function render_row(records, first_title, second_title, first_renderer, second_renderer, col_headers, row_headers, row_header)
    local my_pairs = get_row(records, col_headers, row_headers, row_header)
    return render_pairs(first_title, second_title, first_renderer, second_renderer, my_pairs)
end
 
local function render_col(records, first_title, second_title, first_renderer, second_renderer, col_headers, row_headers, col_header)
    local my_pairs = get_col(records, col_headers, row_headers, col_header)
    return render_pairs(first_title, second_title, first_renderer, second_renderer, my_pairs)
end
 
local function render_skills(records, first_title, second_title, first_renderer, second_renderer, col_headers, row_headers, skill)
    local my_pairs = get_skills(records, col_headers, row_headers, skill)
    return render_skill_pairs(first_title, second_title, first_renderer, second_renderer, my_pairs)
end
 
local function render_duos(
        recordsWeaponArmor, recordsArmorPet, recordsPetWeapon,
        first_title, second_title, third_title, fourth_title,
        renderer,
        wantedSkill_1, wantedSkill_2)
    local my_quads = get_duos_2(recordsWeaponArmor, recordsArmorPet, recordsPetWeapon, wantedSkill_1, wantedSkill_2)
    return render_duo_quads(first_title, second_title, third_title, fourth_title, wantedSkill_1, wantedSkill_2, renderer, my_quads)
end
 
local function render_table(records, first_renderer, second_renderer, col_headers, row_headers)
    local skillRenderer = require("Module:Renderer").Skill
    local tables = {}
    local jlow = 1
    local ncols = #col_headers
    while (jlow <= ncols) do
        local my_lines = {}
        local jhigh = math.min(jlow + 7, ncols)
        local titles = {}
        for j = jlow, jhigh do
            table.insert(titles, '! scope="col" |' .. first_renderer.getLink(col_headers[j]))
        end
        for i, row_header in ipairs(row_headers) do
            local row = records[i]
            local skills = {}
            for j = jlow, jhigh do
                local skill = records[i][j]
                table.insert(skills, skill and skillRenderer.getLink(skill) or "-")
            end
            skills = string.format('! scope="row" | %s\n| %s', second_renderer.getLink(row_headers[i]), table.concat(skills, " || "))
            table.insert(my_lines, skills)
        end
        my_lines = string.format(fulltable,
            table.concat(titles, "\n"), table.concat(my_lines, "\n|-\n"))
        table.insert(tables, my_lines)
        jlow = jlow + 8
    end
    return table.concat(tables, "\n")
end
 
local p = {}
 
p.WeaponArmor = function(weapon)
    return render_col(require("Module:WeaponArmorSkills"), "Armor", "Skills",
        require("Module:Renderer").Armor, require("Module:Renderer").Skill,
        lists.weapons, lists.armor, weapon.args[1])
end
 
p.WeaponPet = function(weapon)
    return render_row(require("Module:PetWeaponSkills"), "Pets", "Skills",
        require("Module:Renderer").Pet, require("Module:Renderer").Skill,
        lists.pets, lists.weapons, weapon.args[1])
end
 
p.ArmorWeapon = function(armor)
    return render_row(require("Module:WeaponArmorSkills"), "Weapons", "Skills",
        require("Module:Renderer").Weapon, require("Module:Renderer").Skill,
        lists.weapons, lists.armor, armor.args[1])
end
 
p.ArmorPet = function(armor)
    return render_col(require("Module:ArmorPetSkills"), "Pets", "Skills",
        require("Module:Renderer").Pet, require("Module:Renderer").Skill,
        lists.armor, lists.pets, armor.args[1])
end
 
p.PetWeapon = function(pet)
    return render_col(require("Module:PetWeaponSkills"), "Weapons", "Skills",
        require("Module:Renderer").Weapon, require("Module:Renderer").Skill,
        lists.pets, lists.weapons, pet.args[1])
end
 
p.PetArmor = function(pet)
    return render_row(require("Module:ArmorPetSkills"), "Armor", "Skills",
        require("Module:Renderer").Armor, require("Module:Renderer").Skill,
        lists.armor, lists.pets, pet.args[1])
end
 
 
p.SkillWeaponArmor = function(skill)
    return render_skills(require("Module:WeaponArmorSkills"), "Weapons", "Armor",
        require("Module:Renderer").Weapon, require("Module:Renderer").Armor,
        lists.weapons, lists.armor, skill.args[1])
end
p.SkillArmorPet = function(skill)
    return render_skills(require("Module:ArmorPetSkills"), "Armor", "Pets",
        require("Module:Renderer").Armor, require("Module:Renderer").Pet,
        lists.armor, lists.pets, skill.args[1])
end
p.SkillPetWeapon = function(skill)
    return render_skills(require("Module:PetWeaponSkills"), "Pets", "Weapons",
        require("Module:Renderer").Pet, require("Module:Renderer").Weapon,
        lists.pets, lists.weapons, skill.args[1])
end
 
p.DuoSkill = function(skill)
    return render_duos(
        require("Module:WeaponArmorSkills"), require("Module:ArmorPetSkills"), require("Module:PetWeaponSkills"), 
        "Weapons", "Armor", "Pets", "Extra Skill",
        require("Module:Renderer"),
        skill.args[1], skill.args[2])
end
 
p.WeaponArmorTable = function()
    return render_table(require("Module:WeaponArmorSkills"),
        require("Module:Renderer").Weapon, require("Module:Renderer").Armor,
        lists.weapons, lists.armor)
end
 
p.ArmorPetTable = function()
    return render_table(require("Module:ArmorPetSkills"),
        require("Module:Renderer").Armor, require("Module:Renderer").Pet,
        lists.armor, lists.pets)
end
 
p.PetWeaponTable = function()
    return render_table(require("Module:PetWeaponSkills"),
        require("Module:Renderer").Pet, require("Module:Renderer").Weapon,
        lists.pets, lists.weapons)
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.