Module:TypeEffectivenessGenerator: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 29: | Line 29: | ||
} | } | ||
function | 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 | 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 = { | local results = { | ||
["4"]={},["2"]={},["1"]={},["0.5"]={},["0.25"]={},["0"]={} | |||
["4"] = {}, | |||
} | } | ||
for _,atk in ipairs(types) do | for _,atk in ipairs(types) do | ||
local | 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) | |||
if | 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 | elseif m==0 then table.insert(results["0"],atk) | ||
end | |||
elseif | |||
elseif | |||
elseif | |||
elseif | |||
end | end | ||
local function join(t) | local function join(t) 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"]), | ||
| Line 121: | Line 72: | ||
SuperResistances=join(results["0.25"]), | SuperResistances=join(results["0.25"]), | ||
Immunities=join(results["0"]) | Immunities=join(results["0"]) | ||
} | } | ||
} | } | ||
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