Module:TypeEffectivenessGenerator: Difference between revisions
Jump to navigation
Jump to search
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..." |
No edit summary |
||
| Line 2: | Line 2: | ||
local types = { | local types = { | ||
"Normal","Fire","Water","Electric","Grass","Ice","Fighting","Poison", | |||
"Ground","Flying","Psychic","Bug","Rock","Ghost","Dragon","Dark", | |||
"Steel","Fairy" | |||
} | } | ||
local chart = { | local chart = { | ||
Normal = {Rock=0.5, Ghost=0, Steel=0.5}, | Normal = {Rock=0.5, Ghost=0, Steel=0.5}, | ||
| Line 45: | Line 46: | ||
} | } | ||
local function getMultiplier( | local function getMultiplier(atk, def) | ||
if not | |||
if chart[ | if not def or def == "" then | ||
return chart[ | return 1 | ||
end | |||
if chart[atk] and chart[atk][def] then | |||
return chart[atk][def] | |||
end | end | ||
return 1 | return 1 | ||
end | |||
local function trim(s) | |||
if not s then return nil end | |||
return mw.text.trim(s) | |||
end | end | ||
function p.generate(frame) | function p.generate(frame) | ||
local type1 = frame.args.type1 | local type1 = trim(frame.args.type1) | ||
local type2 = frame.args.type2 | local type2 = trim(frame.args.type2) | ||
local results = { | local results = { | ||
["4"] = {}, | ["4"] = {}, | ||
["2"] = {}, | ["2"] = {}, | ||
| Line 65: | Line 80: | ||
["0.25"] = {}, | ["0.25"] = {}, | ||
["0"] = {} | ["0"] = {} | ||
} | } | ||
for _,atk in ipairs(types) do | for _,atk in ipairs(types) do | ||
local m1 = getMultiplier(atk, type1) | local m1 = getMultiplier(atk,type1) | ||
local m2 = getMultiplier(atk, type2) | local m2 = getMultiplier(atk,type2) | ||
local mult = m1 * m2 | local mult = m1 * m2 | ||
if mult == 4 then table.insert(results["4"], atk) | if mult == 4 then | ||
elseif mult == 2 then table.insert(results["2"], atk) | table.insert(results["4"],atk) | ||
elseif mult == 1 then table.insert(results["1"], atk) | |||
elseif mult == 0.5 then table.insert(results["0.5"], atk) | elseif mult == 2 then | ||
elseif mult == 0.25 then table.insert(results["0.25"], atk) | table.insert(results["2"],atk) | ||
elseif mult == 0 then table.insert(results["0"], 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 | end | ||
| Line 88: | Line 116: | ||
return frame:expandTemplate{ | return frame:expandTemplate{ | ||
title = "TypeEffectiveness", | |||
args = { | title="TypeEffectiveness", | ||
Color = type1, | |||
SuperWeaknesses = join(results["4"]), | args={ | ||
Weaknesses = join(results["2"]), | |||
Neutralities = join(results["1"]), | Color=type1, | ||
Resistances = join(results["0.5"]), | SuperWeaknesses=join(results["4"]), | ||
SuperResistances = join(results["0.25"]), | Weaknesses=join(results["2"]), | ||
Immunities = join(results["0"]) | Neutralities=join(results["1"]), | ||
Resistances=join(results["0.5"]), | |||
SuperResistances=join(results["0.25"]), | |||
Immunities=join(results["0"]) | |||
} | } | ||
} | } | ||
end | end | ||
return p | return p | ||
Revision as of 12:36, 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 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 function trim(s)
if not s then return nil end
return mw.text.trim(s)
end
function p.generate(frame)
local type1 = trim(frame.args.type1)
local type2 = trim(frame.args.type2)
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