Module:TypeEffectivenessGenerator

From Pokemon Revolution Online Wiki
Revision as of 12:40, 7 March 2026 by Cae (talk | contribs)
Jump to navigation Jump to search

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

local p = {}

local types = {
"Normal","Fire","Water","Electric","Grass","Ice","Fighting","Poison",
"Ground","Flying","Psychic","Bug","Rock","Ghost","Dragon","Dark",
"Steel","Fairy"
}

local chart = {

Normal = {Rock=0.5, Ghost=0, Steel=0.5},
Fire = {Fire=0.5, Water=0.5, Grass=2, Ice=2, Bug=2, Rock=0.5, Dragon=0.5, Steel=2},
Water = {Fire=2, Water=0.5, Grass=0.5, Ground=2, Rock=2, Dragon=0.5},
Electric = {Water=2, Electric=0.5, Grass=0.5, Ground=0, Flying=2, Dragon=0.5},
Grass = {Fire=0.5, Water=2, Grass=0.5, Poison=0.5, Ground=2, Flying=0.5, Bug=0.5, Rock=2, Dragon=0.5, Steel=0.5},
Ice = {Fire=0.5, Water=0.5, Grass=2, Ground=2, Flying=2, Dragon=2, Steel=0.5},
Fighting = {Normal=2, Ice=2, Poison=0.5, Flying=0.5, Psychic=0.5, Bug=0.5, Rock=2, Ghost=0, Dark=2, Steel=2, Fairy=0.5},
Poison = {Grass=2, Poison=0.5, Ground=0.5, Rock=0.5, Ghost=0.5, Steel=0, Fairy=2},
Ground = {Fire=2, Electric=2, Grass=0.5, Poison=2, Flying=0, Bug=0.5, Rock=2, Steel=2},
Flying = {Electric=0.5, Grass=2, Fighting=2, Bug=2, Rock=0.5, Steel=0.5},
Psychic = {Fighting=2, Poison=2, Psychic=0.5, Dark=0, Steel=0.5},
Bug = {Fire=0.5, Grass=2, Fighting=0.5, Poison=0.5, Flying=0.5, Psychic=2, Ghost=0.5, Dark=2, Steel=0.5, Fairy=0.5},
Rock = {Fire=2, Ice=2, Fighting=0.5, Ground=0.5, Flying=2, Bug=2, Steel=0.5},
Ghost = {Normal=0, Psychic=2, Ghost=2, Dark=0.5},
Dragon = {Dragon=2, Steel=0.5, Fairy=0},
Dark = {Fighting=0.5, Psychic=2, Ghost=2, Dark=0.5, Fairy=0.5},
Steel = {Fire=0.5, Water=0.5, Electric=0.5, Ice=2, Rock=2, Fairy=2, Steel=0.5},
Fairy = {Fire=0.5, Fighting=2, Poison=0.5, Dragon=2, Dark=2, Steel=0.5}
}

function p.pokemon(frame)

    local name = frame.args[1] or mw.title.getCurrentTitle().text

    local csv = mw.title.new("Data:PokemonRawList.csv"):getContent()

    local type1
    local type2

    for line in csv:gmatch("[^\r\n]+") do

        local fields = {}
        for value in line:gmatch("([^,]+)") do
            table.insert(fields,value)
        end

        if fields[1] == name then
            type1 = fields[3]
            type2 = fields[4]
            break
        end
    end

    local function getMultiplier(atk,def)

        if not def or def == "" then
            return 1
        end

        if chart[atk] and chart[atk][def] then
            return chart[atk][def]
        end

        return 1
    end

    local results = {

        ["4"] = {},
        ["2"] = {},
        ["1"] = {},
        ["0.5"] = {},
        ["0.25"] = {},
        ["0"] = {}

    }

    for _,atk in ipairs(types) do

        local m1 = getMultiplier(atk,type1)
        local m2 = getMultiplier(atk,type2)

        local mult = m1 * m2

        if mult == 4 then
            table.insert(results["4"],atk)

        elseif mult == 2 then
            table.insert(results["2"],atk)

        elseif mult == 1 then
            table.insert(results["1"],atk)

        elseif mult == 0.5 then
            table.insert(results["0.5"],atk)

        elseif mult == 0.25 then
            table.insert(results["0.25"],atk)

        elseif mult == 0 then
            table.insert(results["0"],atk)

        end
    end

    local function join(t)
        return table.concat(t,", ")
    end

    return frame:expandTemplate{

        title="TypeEffectiveness",

        args={

            Color=type1,
            SuperWeaknesses=join(results["4"]),
            Weaknesses=join(results["2"]),
            Neutralities=join(results["1"]),
            Resistances=join(results["0.5"]),
            SuperResistances=join(results["0.25"]),
            Immunities=join(results["0"])

        }

    }

end

return p