Module:竞技场比武列表

来自植物大战僵尸百科
跳转到导航 跳转到搜索
{{🛈}}模組文檔[建立]此文档尚未建立。
local joust, _joust = {}, {}
local joustdata = mw.loadData("Module:PvZ2joust")
local levelsdata = mw.loadData("Module:PvZ2joust/levels")
local icondata = mw.loadData("Module:标")
local lawnstrings = mw.loadData("Module:PvZ2lawnstrings")
local getArgs = require('Dev:Arguments').getArgs
local type2icon = require('Module:PvZ2events').type2icon
local types2icon = require('Module:PvZ2events').types2icon
local time
local datetodate = require("Module:日期段").datetodate

function _joust.event_name(level)
    local name = "比武!"
    if level.boosterama then name = "提升!" end
    if level.zomboss then name = "与朋友大战僵王!" end
    local plant = level.level_plant
    if type(icondata[plant]) == "table" then
        plant = icondata[plant].args[1] or plant
    end
    return plant .. name
end

function _joust.preset(level)
    local wikitext = ''
    for k, plant in ipairs(level.preset_plant) do
        if type(plant) == "table" then
            if tostring(plant.plant_level) ~= '-1' then wikitext = wikitext .. plant.plant_level .. '级' end
            wikitext = wikitext .. type2icon(plant.plant_type)
        end
    end
    return wikitext
end

function _joust.zombies(level)
    local wikitext = ''
    if level.zomboss then
        wikitext = wikitext .. type2icon(level.zomboss) .. '召唤:' .. types2icon(level.zomboss_spawn) .. '<hr />'
    end
    wikitext = wikitext .. types2icon(level.zombies or level.raw_zombies)
    if level.zombies_spawn or level.raw_zombies_spawn then
        wikitext = wikitext .. '<hr />召唤:' ..
            types2icon(level.zombies_spawn or level.raw_zombies_spawn)
    end
    return wikitext
end

function _joust.duration(duration)
    local min = math.modf(duration / 60)
    local sec = duration % 60
    return min .. ':' .. string.format("%02d", sec)
end

function _joust.family(level)
    local wikitext = ''
    for k, resistance in ipairs(level.resistances) do
        local mint, buffz_bruisez = 'enlightenmint', '1' -- 防止出錯?
        if type(icondata[resistance.family_type]) == "table" then
            mint = icondata[resistance.family_type].args[1] or resistance.family_type
        end
        if resistance.damage > 1 then buffz_bruisez = '+' end
        if resistance.damage < 1 then buffz_bruisez = '-' end
        if resistance.damage == 0 then buffz_bruisez = '0' end
        local args = { mint, buffz_bruisez, resistance.damage }
        if resistance.condition ~= resistance.damage then table.insert(args, resistance.condition) end
        wikitext = wikitext .. mw.getCurrentFrame():expandTemplate { title = "家族", args = args }
    end
    return wikitext
end

function _joust.tablerow(start_date, tournament, previous_level, next_level)
    previous_level = previous_level or ''
    local level = levelsdata[tournament.level]
    if level.boost_only then
        if previous_level .. 'BOOST' == tournament.level then
            local wikitext = '|-\n' ..
                '! ' .. _joust.event_name(level) .. '\n' ..
                '| ' .. datetodate(start_date, tournament.end_date) .. '\n'
            return wikitext
        else
            level = levelsdata[string.gsub(tournament.level, 'BOOST', '')]
        end
    end
    local rowspan = '| '
    if next_level == tournament.level .. 'BOOST' and levelsdata[next_level].boost_only then
        rowspan = '| rowspan="2" | '
    end
    local wikitext = '|-\n' ..
        '! ' .. _joust.event_name(level) .. '\n' ..
        rowspan .. _joust.preset(level) .. '\n' ..
        rowspan .. types2icon(level.exclude_plant ~= { "" } and level.exclude_plant or '无') .. '\n' ..
        rowspan .. _joust.duration(level.duration) .. '\n' ..
        rowspan .. _joust.zombies(level) .. '\n' ..
        rowspan .. level.sun .. '点阳光<br />' .. level.plant_food .. '份植物养料' .. '\n' ..
        rowspan .. _joust.family(level) .. '\n' ..
        '| ' .. datetodate(start_date, tournament.end_date) .. '\n'
    return wikitext
end

function _joust.table(season_start_date, season, args)
    local wikitext = '{| class="fandom-table joust-table mw-collapsible mw-collapsed"\n'
    local season_name = lawnstrings[season.season_name] or season.season_name
    wikitext = wikitext .. '|+ ' .. season_name .. '\n' ..
        '! class="event-name" | 比武名\n' ..
        '! class="preset" | 预选植物\n' ..
        '! class="exclude" | 排除植物\n' ..
        '! class="duration" | 时长\n' ..
        '! class="zombies" | 僵尸\n' ..
        '! class="starting" | 初始资源\n' ..
        '! class="family" | 家族\n' ..
        '! class="time" | 时间\n'
    local i = season_start_date
    local i_previous, i_next
    while season.tournaments[i] do
        i_next = season.tournaments[i].end_date
        if time(args[1], i, args[2]) then
            local previous_level = i_previous and joustdata[season_start_date].tournaments[i_previous].level
            local next_level
            if i_next and joustdata[season_start_date].tournaments[i_next] then
                next_level = i_next and joustdata[season_start_date].tournaments[i_next].level
            end
            wikitext = wikitext .. _joust.tablerow(i, joustdata[season_start_date].tournaments[i], previous_level, next_level)
            i_previous = i
        end
        i = season.tournaments[i].end_date
    end
    wikitext = wikitext .. '|}\n'
    return wikitext
end

function _joust.tables(args)
    if args[2] then
        time = require('Module:PvZ2events').period
    else
        time = require('Module:PvZ2events').time
    end
    local wikitext = ""
    local i = 1660582800 -- 活動開始時間,初始爲現有資料中的初次
    while joustdata[i] do
        local condition = true
        if args[1] == "future" then
            condition = time(args[1], i + 2419200)
        else
            condition = time(args[1], i, args[2])
        end
        if condition then
            wikitext = wikitext .. _joust.table(i, joustdata[i], args)
        end
        i = joustdata[i].season_end_date
    end
    return wikitext
end

function joust.main(frame)
    local args = getArgs(frame)
    local wikitext = _joust.tables(args)
    return wikitext
end

return joust