FANDOM


local moves_db = require("Module:MovesDB")
local unknown_move = {
    name = "?????",
    power = 0,
    type = "?????",
    category = "?????",
    accuracy = 0,
    pp = 0
}
 
local type_colors_bg = {
    NORMAL = "A8A878",
    FIGHTING = "C03028",
    FLYING = "A890F0",
    POISON = "A040A0",
    GROUND = "E0C068",
    ROCK = "B8A038",
    BUG = "A8B820",
    GHOST = "705890",
    STEEL = "B8B8D0",
    FIRE = "F08030",
    WATER = "6890F0",
    GRASS = "78C850",
    ELECTRIC = "F8D030",
    PSYCHIC = "F85888",
    ICE = "98D8D8",
    DRAGON = "7038F8",
    DARK = "705848",
    FAIRY = "EE99AC",
 
    PHYSICAL = "C92112",
    SPECIAL = "4F5870",
    STATUS = "8C888C",
 
    ["?????"] = "FFFFFF"
}
 
local type_colors_fg = {
    NORMAL = "FFFFFF",
    FIGHTING = "FFFFFF",
    FLYING = "FFFFFF",
    POISON = "FFFFFF",
    GROUND = "FFFFFF",
    ROCK = "FFFFFF",
    BUG = "FFFFFF",
    GHOST = "FFFFFF",
    STEEL = "FFFFFF",
    FIRE = "FFFFFF",
    WATER = "FFFFFF",
    GRASS = "FFFFFF",
    ELECTRIC = "FFFFFF",
    PSYCHIC = "FFFFFF",
    ICE = "FFFFFF",
    DRAGON = "FFFFFF",
    DARK = "FFFFFF",
    FAIRY = "FFFFFF",
 
    PHYSICAL = "F67A1A",
    SPECIAL = "FFFFFF",
    STATUS = "FFFFFF",
 
    ["?????"] = "000000"
}
 
local module = {}
 
function get_acc_string(acc)
	if acc == 0 then
		return "—"
	else
		return string.format("%d%%", acc)
	end
end
 
function get_move_data(move)
    local data = moves_db.moves[move]
    if data == nil then
        data = unknown_move
        data.name = move
    end
    return data
end
 
function print_move_list(list)
    local text = [[<table class="sortable" style="background: #DDF; border: 5px solid #CCF;"><tr><td>
<table class="sortable" style="background: #FFF; border: 1px solid #DDF; border-collapse: collapse;" border="1" width="100%">
<tr style="background: #DDF">
    <th>#</th>
    <th>Name</th>
    <th>Type</th>
    <th>Category</th>
    <th>Power</th>
    <th>Accuracy</th>
    <th>PP</th>
</tr>
]]
 
    for index, item in ipairs(list) do
        local move = item:gsub("%s+", "")
        local data = get_move_data(move)
        text = text .. string.format([[<tr>
    <td>%d</td>
    <td>%s</td>
    <td style="text-align: center; background: #%s;"><span style="color: #%s;">%s</span></td>
    <td style="text-align: center; background: #%s;"><span style="color: #%s;">%s</span></td>
    <td>%d</td>
    <td>%s</td>
    <td>%d</td>
</tr>
]],
            index,
            data.name,
            type_colors_bg[data.type], type_colors_fg[data.type], data.type,
            type_colors_bg[data.category], type_colors_fg[data.category], data.category,
            data.power,
            get_acc_string(data.accuracy),
            data.pp
        )
    end
 
    text = text .. "</table></td></tr></table>"
 
    return text
end
 
function module:all_moves()
    return print_move_list(moves_db.order)
end
 
function module:list()
    return print_move_list(self.args)
end
 
function module:level_up()
    local text = [[<table class="sortable" style="background: #DDF; border: 5px solid #CCF;"><tr><td>
<table class="sortable" style="background: #FFF; border: 1px solid #DDF; border-collapse: collapse;" border="1" width="100%">
<tr style="background: #DDF">
    <th>Level</th>
    <th>Move</th>
    <th>Type</th>
    <th>Category</th>
    <th>Power</th>
    <th>Accuracy</th>
    <th>PP</th>
</tr>
]]
 
    -- What kind of fucking shoddy lua implementation are they even remotely running?
    -- Regular #self.args doesn't work, so we have to do it this way.
    local keys = {}
    for x, _ in ipairs(self.args) do table.insert(keys, x) end
 
    for i = 1, #keys, 2 do
        local level = self.args[keys[i]]
        local move = self.args[keys[i + 1]]:gsub("%s+", "")
 
        local data = get_move_data(move)
 
        text = text .. string.format([[<tr>
    <td>%s</td>
    <td>%s</td>
    <td style="text-align: center; background:#%s;"><span style="color: #%s;">%s</span></td>
    <td style="text-align: center; background:#%s;"><span style="color: #%s;">%s</span></td>
    <td>%d</td>
    <td>%s</td>
    <td>%d</td>
</tr>
]],
            level,
            data.name,
            type_colors_bg[data.type], type_colors_fg[data.type], data.type,
            type_colors_bg[data.category], type_colors_fg[data.category], data.category,
            data.power,
            get_acc_string(data.accuracy),
            data.pp
        )
    end
 
    text = text .. "</table></td></tr></table>"
 
    return text
end
 
function module:tms()
    local text = [[<table class="sortable" style="background: #DDF; border: 5px solid #CCF;"><tr><td>
<table class="sortable" style="background: #FFF; border: 1px solid #DDF; border-collapse: collapse;" border="1" width="100%">
<tr style="background: #DDF">
    <th>TM</th>
    <th>Move</th>
    <th>Type</th>
    <th>Category</th>
    <th>Power</th>
    <th>Accuracy</th>
    <th>PP</th>
</tr>
]]
 
    for _, item in ipairs(self.args) do
        local move = item:gsub("%s+", "")
        local data = get_move_data(move)
 
        local tm = moves_db.tms[move]
        local tmtext
        if tm then
            tmtext = string.format("TM%02d", tm)
        else
            tmtext = "TM??"
        end
 
        text = text .. string.format([[<tr>
    <td>%s</td>
    <td>%s</td>
    <td style="text-align: center; background:#%s;"><span style="color: #%s;">%s</span></td>
    <td style="text-align: center; background:#%s;"><span style="color: #%s;">%s</span></td>
    <td>%d</td>
    <td>%s</td>
    <td>%d</td>
</tr>
]],
            tmtext,
            data.name,
            type_colors_bg[data.type], type_colors_fg[data.type], data.type,
            type_colors_bg[data.category], type_colors_fg[data.category], data.category,
            data.power,
            get_acc_string(data.accuracy),
            data.pp
        )
    end
 
    text = text .. "</table></td></tr></table>"
 
    return text
end
 
return module