Module:TypeEffectivenessGenerator: Difference between revisions

From Pokemon Revolution Online Wiki
Jump to navigation Jump to search
Cae (talk | contribs)
Created page with "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..."
 
Cae (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:


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


local chart = {
local chart = {
Normal = {Rock=0.5, Ghost=0, Steel=0.5},
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},
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},
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},
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},
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},
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},
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},
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},
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},
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},
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},
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},
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},
Ghost = {Normal=0, Psychic=2, Ghost=2, Dark=0.5},
Dragon = {Dragon=2, Steel=0.5, Fairy=0},
Dragon = {Dragon=2, Steel=0.5, Fairy=0},
Dark = {Fighting=0.5, Psychic=2, Ghost=2, Dark=0.5, Fairy=0.5},
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},
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}
Fairy = {Fire=0.5, Fighting=2, Poison=0.5, Dragon=2, Dark=2, Steel=0.5}
}
}


local function getMultiplier(attackType, defType)
local function multiplier(atk, def)
     if not defType or defType == "" then return 1 end
     if not def or def == "" then return 1 end
     if chart[attackType] and chart[attackType][defType] then
     if chart[atk] and chart[atk][def] then
         return chart[attackType][defType]
         return chart[atk][def]
     end
     end
     return 1
     return 1
Line 55: Line 39:
function p.generate(frame)
function p.generate(frame)


     local type1 = frame.args.type1
     local type1 = mw.text.trim(frame.args.type1 or "")
     local type2 = frame.args.type2
     local type2 = mw.text.trim(frame.args.type2 or "")


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


     for _,atk in ipairs(types) do
     for _,atk in ipairs(types) do


         local m1 = getMultiplier(atk, type1)
         local m = multiplier(atk,type1) * multiplier(atk,type2)
        local m2 = getMultiplier(atk, type2)


         local mult = m1 * m2
         if m==4 then table.insert(results["4"],atk)
        elseif m==2 then table.insert(results["2"],atk)
        elseif m==1 then table.insert(results["1"],atk)
        elseif m==0.5 then table.insert(results["0.5"],atk)
        elseif m==0.25 then table.insert(results["0.25"],atk)
        elseif m==0 then table.insert(results["0"],atk)
        end


        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
     end


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


     return frame:expandTemplate{
     return frame:expandTemplate{
         title = "TypeEffectiveness",
         title="TypeEffectiveness",
         args = {
         args={
             Color = type1,
             Color=type1,
             SuperWeaknesses = join(results["4"]),
             SuperWeaknesses=join(results["4"]),
             Weaknesses = join(results["2"]),
             Weaknesses=join(results["2"]),
             Neutralities = join(results["1"]),
             Neutralities=join(results["1"]),
             Resistances = join(results["0.5"]),
             Resistances=join(results["0.5"]),
             SuperResistances = join(results["0.25"]),
             SuperResistances=join(results["0.25"]),
             Immunities = join(results["0"])
             Immunities=join(results["0"])
         }
         }
     }
     }
end
end


return p
return p

Latest revision as of 12:45, 7 March 2026

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}
}

local function multiplier(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

function p.generate(frame)

    local type1 = mw.text.trim(frame.args.type1 or "")
    local type2 = mw.text.trim(frame.args.type2 or "")

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

    for _,atk in ipairs(types) do

        local m = multiplier(atk,type1) * multiplier(atk,type2)

        if m==4 then table.insert(results["4"],atk)
        elseif m==2 then table.insert(results["2"],atk)
        elseif m==1 then table.insert(results["1"],atk)
        elseif m==0.5 then table.insert(results["0.5"],atk)
        elseif m==0.25 then table.insert(results["0.25"],atk)
        elseif m==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