来自勇者斗恶龙X WIKI_DQX日服PC中文版图鉴 DQX攻略大全

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

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

-----------------------------------------------------------------------------
-- 入口函数
-----------------------------------------------------------------------------

function base.item_link(pageframe)
    frame = pageframe
    args = getArgs(pageframe)
    if args[2] == '32' then
        return base.item_link_32(args[1], args['class'])
    elseif args[2] == '48' then
        return base.item_link_48(args[1], args['class'], args[3])
    elseif args[2] == '16' then
        return base.item_link_1X(args[1], args['class'], 16)
    elseif args[2] == '14' then
        return base.item_link_1X(args[1], args['class'], 14)
    else
        return base.item_link_1X(args[1], args['class'], 14)
    end
end

function base.test(pageframe)
    return ' test'
end

-----------------------------------------------------------------------------
-- 颜色表
-----------------------------------------------------------------------------

function base.color(key)
    local color_list = {
        ['武器锻造'] = 'red',
        ['防具锻造'] = 'blue',
        ['道具锻造'] = 'green',
        ['裁缝'] = 'red',
        ['木工'] = 'red',
        ['壶炼金'] = 'red',
        ['油灯炼金'] = 'red',
    }
    if color_list[key] then
        return color_list[key]
    else
        return ''
    end
end

-----------------------------------------------------------------------------
-- 道具浮层生成
-----------------------------------------------------------------------------

function base.item_tooltip(obj_html, item_name, class)
    local html = mw.html.create():tag('div'):addClass('joyme-tt')
    html:attr('data-type', 'item'):attr('data-name', item_name)

    if class then
        html:addClass(class)
    end

    html:wikitext(obj_html)

    return tostring(html)
end

-----------------------------------------------------------------------------
-- 道具图标+文字生成(供内部调用)
-----------------------------------------------------------------------------

function base.item_link_1X(item_name, class, size)
    local html
    if item_name ~= nil and item_name ~= '' then
        html = mw.html.create():tag('div')
               div = html:tag('div'):addClass('item-icon-inline item-icon-line'..size)
               div:tag('div'):addClass('item-icon-inline-box icon-img'):wikitext('[[File:icon-'..item_name..'.png|link='..item_name..'|'..(size+2)..'px]]')
               div:tag('span'):addClass('item-icon-name'):wikitext('[['..item_name..']]')

        html = base.item_tooltip(tostring(html), item_name, class)
    else
        html = ' '
    end

    return html
end

function base.item_link_32(item_name, class)
    local html
    if item_name ~= nil and item_name ~= '' then
        html = mw.html.create():tag('table')
               tr = html:addClass('item-box'):tag('tr')
               tr:tag('td'):tag('div'):addClass('item-icon icon-img'):cssText('line-height: 32px;height: 38px;width: 38px;'):wikitext('[[File:icon-'..item_name..'.png|32px|link='..item_name..']]')
               tr:tag('td'):cssText('padding-left:5px;font-size: 13px;line-height: 16px;')
                :tag('div'):addClass('item-name'):wikitext('[['..item_name..']]'):done()
        html = base.item_tooltip(tostring(html), item_name, class)
    else
        html = ' '
    end

    return html
end

function base.item_link_48(item_name, class, extra_info)
    local html
    local extra_info = extra_info or ''
    if item_name ~= nil and item_name ~= '' then
        html = mw.html.create():tag('table')
               tr = html:addClass('item-box'):tag('tr')
               tr:tag('td'):tag('div'):addClass('item-icon icon-img'):wikitext('[[File:icon-'..item_name..'.png|link='..item_name..']]')
               td = tr:tag('td'):css('padding-left', '5px')
               td:tag('div'):addClass('item-name'):wikitext('[['..item_name..']]'):done()
        if extra_info ~= '' then
               td:tag('div'):addClass('item-extra-info'):wikitext(extra_info):done()
        end
        
        html = base.item_tooltip(tostring(html), item_name, class)
    else
        html = ' '
    end

    return html
end

-----------------------------------------------------------------------------
-- 怪物列表生成
-----------------------------------------------------------------------------


-- 生成列表
function base.monster_list(args, mode)
    -- 模式
    --  item_info_page: 道具信息页

    mode = mode or ''

    local html = mw.html.create():tag('div')
    html:addClass('row monster-list')

    for i=1, #args do
        col = html:tag('div'):addClass('col-xs-6 col-md-3')
        col:wikitext(_monster_list_oneM(args[i], mode))
--        col:wikitext(mw.dumpObject(args[i]))
    end

    return tostring(html)
end



-- 生成列表
function _monster_list_oneM(arg, mode)
--    if arg then
--        return mw.dumpObject(arg)
--    end

    local html_table = mw.html.create():tag('table')
    html_table:addClass('wikitable monster-list'):css('font-size', '14px')
    if arg['转生自'] ~= '' and arg['转生自'] ~= nil then
        title_css = 'font-size:16px;background: #FFCDCD;'
    else
        title_css = 'font-size:16px;'
    end

    html_table:tag('tr'):tag('th'):attr('colspan', '4'):cssText(title_css):wikitext('[['..arg[1]..'|'..arg['名称']..']]')
    img_td = html_table:tag('tr'):tag('td'):attr('colspan', '4'):addClass('monster-img')
  
    if arg['转生自'] ~= '' and arg['转生自'] ~= nil then
        div = img_td:tag('div'):cssText('position: relative;')
        div:tag('div'):wikitext('[[File:'..arg[1]..'.jpg|link='..arg[1]..']]')
        div:tag('div'):cssText('position: absolute;right: 8px;top: 10px;color: #ffffff;background: #cc0000;font-size: 9pt;width: 35px;height: 35px;line-height: 35px;border-radius: 50%;box-shadow: 0 0 2px #000;'):wikitext('转生')
    else
        img_td:wikitext('[[File:'..arg[1]..'.jpg|x165px|link='..arg[1]..']]')
    end

    -- 汗泪等级
    level_text = '无限制'
    if arg['变弱等级'] ~= '' and arg['变弱等级'] ~= nil then
        if tonumber(arg['变弱等级']) < 999 then
            level_text = '≤'..(tonumber(arg['变弱等级'])-1)..'级'
        end
    end
    html_table:tag('tr'):tag('th'):attr('colspan', '2'):cssText('width:50%;'):wikitext('汗泪等级'):done()
                        :tag('td'):attr('colspan', '2'):cssText('width:50%;'):wikitext(level_text)

    if mode ~= 'item_info_page' then
        -- 经验和特训
        if arg['特训'] == nil or tonumber(arg['特训']) == 0 or arg['特训'] == '' then
            arg['特训'] = '无'
        end
        arg['经验'] = fix_number(arg['经验'])
        if tonumber(arg['经验']) == -1 then
            arg['经验'] = '?'
        end
        html_table:tag('tr'):tag('th'):css('width', '25%'):wikitext('经验'):done()
                            :tag('td'):css('width', '25%'):wikitext(arg['经验']):done()
                            :tag('th'):css('width', '25%'):wikitext('特训'):done()
                            :tag('td'):css('width', '25%'):wikitext(arg['特训']):done()
        -- HP和金币
        html_table:tag('tr'):tag('th'):wikitext('体力'):done()
                            :tag('td'):wikitext(fix_number(arg['体力'])):done()
                            :tag('th'):wikitext('金币'):done()
                            :tag('td'):wikitext(fix_number(arg['金币'])):done()
        -- 攻击和防御
        html_table:tag('tr'):tag('th'):wikitext('攻击'):done()
                            :tag('td'):wikitext(fix_number(arg['攻击力'])):done()
                            :tag('th'):wikitext('防御'):done()
                            :tag('td'):wikitext(fix_number(arg['防御力'])):done()
    end
    
    -- 掉落
    local drop_item = {['普通']='', ['稀有']=''}
    for _, str in ipairs(mw.text.split(arg['掉落道具'], '<MANY>')) do
        if str ~= nil and str ~= '' then
            local ditem = mw.text.split(str, '<RCRD>')
            drop_item[ditem[2]] = ditem[1]
        end
    end

    for _, v in ipairs({'普通', '稀有'}) do
        -- 出于未知原因,有时会取不到数据。很奇怪
        -- item_name = arg[v..'掉落']
        item_name = drop_item[v]
        if item_name ~= nil and item_name ~= '' then
            il_html = mw.html.create():tag('table')
                 tr = il_html:addClass('item-box'):tag('tr')
                 tr:tag('td'):tag('div'):addClass('item-icon icon-img'):cssText('line-height: 32px;height: 38px;width: 38px;'):wikitext('[[File:icon-'..item_name..'.png|32px|link='..item_name..']]')
                 tr:tag('td'):cssText('padding-left:5px;font-size: 13px;line-height: 16px;')
                   :tag('div'):addClass('item-name'):wikitext('[['..item_name..']]'):done()
            il_html = base.item_tooltip(tostring(il_html), item_name, 'jt-block')
        else
            il_html = '&nbsp;'
        end

        html_table:tag('tr'):tag('th'):cssText('height:48px;width:25%;'):wikitext(v):done()
                            :tag('td'):cssText('text-align:left;width:75%;'):attr('colspan', '3'):wikitext(il_html):done()
    end
    return tostring(html_table)
end

function fix_number(num_str)
    num = tonumber(num_str)
    if num == nil then
        return ''
    end
    if num > 9999 then
        num_str = math.floor(num/1000)..'K'
    else
        num_str = tostring(num)
    end
    return num_str
end

return base