全站通知:

模块:MonsterList

来自重返未来:1999WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:MonsterList/doc创建

--[[
    生成一组{{敌人图标}}模板。
    用法:{{#invoke:MonsterList|main|str}}
    str传入形式:
	    敌人名称*灵感(int,0-6)#头像id#首领/普通
	    物品二*数量@概率
	    物品三*数量@概率
    ... (回车或逗号分隔)
--]] 

local getArgs = require('Module:Arguments').getArgs
local p = {}

local function itemSplit(str)
    -- 两种写法
    local items = {}
    str = mw.text.trim(str or '', '%s,')
    local line = mw.text.split(str, '[\n,]')
    -- line = name # career # skinId # boss 
    for i, v in ipairs(line) do
        v = mw.text.trim(v)
        local foo = mw.text.split(v, '#')
        local name = foo[1] or ''
        local career = foo[2] or ''
        local skinid = foo[3] or ''
        local tier = foo[4] or ''

        if (name ~= '') then
            table.insert(items, {name, career, skinid, tier})
        end
    end
    return items

end

function p._main(args, frame)
    if args == nil then
        return require('Module:Error').error({
            message = mw.ustring.format('无法识别的参数:%s', frame.args._params_ or '')
        })
    end
    local items = itemSplit(args[1])
    local property = args[2] or ''
    local text = ''
    for i, item in ipairs(items) do
        text = text .. '{{敌人图标|' .. item[1] .. '|' .. item[2] .. '|' .. item[3] .. '|' .. item[4] .. '}}'
    end
    return text
end

function p.main(frame)
    local args = getArgs(frame)
    local text = p._main(args, frame)
    return frame:preprocess(text)
end

return p