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

此模块的文档可以在模块:怪物Y/doc创建

local p = {}
local getArgs = require('Module:Arguments').getArgs
local smw = require('Module:Util').smw
local ref = require('Module:Util').ref
local itembox = require('Module:道具Y').item_box_in
local item_tooltip = require('Module:BaseTest').item_tooltip
local monster_list = require('Module:BaseTest').monster_list
local item_link_1X = require('Module:BaseTest').item_link_1X
local frame

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

-- 怪物图鉴页
function p.monster_info_page(pageframe)
    frame = pageframe
    return _monster_info_page(getArgs(pageframe))
end

-- 怪物列表页(按系别)
function p.monster_list_page(pageframe)
    frame = pageframe
    return _monster_list_page(getArgs(pageframe))
end

-- 怪物列表页(指定条件查询)
function p.monster_list_page_query(pageframe)
    frame = pageframe
    return _monster_list_page_query(getArgs(pageframe))
end
-- 怪物列表页(指定名称组 逗号隔开)
function p.monster_list_page_queryByName(pageframe)
    frame = pageframe
    return _monster_list_page_query_Byname(getArgs(pageframe))
end
p['名字'] = p.monster_list_page_queryByName
p['类别'] = p.monster_list_page
p['条件'] = p.monster_list_page_query
p['信息'] = p.monster_info_page
-----------------------------------------------------------------------------
-- 怪物图鉴
-----------------------------------------------------------------------------

function _monster_info_page(args)
    local html = mw.html.create():tag('div')
    html:addClass('row monster-info')
    
    -- 左侧怪物名称和图片
    row_div = html:tag('div'):addClass('col-md-4'):tag('div'):addClass('row')
    if args['转生基础怪物中文名'] ~= ''and args['转生基础怪物中文名'] ~= nil then
        flag_tensei = 1
        tensei_css = 'background: #FFCDCD;'
    else
        flag_tensei = 0
    end

    row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
                      :tag('tr'):tag('th'):cssText(tensei_css)
                      :tag('span'):addClass('monster-name'):wikitext(args['日文名']):done()
                      :tag('br'):done()
                      :tag('span'):addClass('monster-name'):wikitext(args['名称']):done()
                      :tag('br'):done()
                      :tag('span'):addClass('monster-category'):wikitext('[['..args['系别']..']]')
    img_td = row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable'):tag('tr'):tag('td')
    if flag_tensei == 1 then
        div = img_td:tag('div'):cssText('position: relative;')
        div:tag('div'):wikitext('[[File:'..args['名称']..'.jpg|link=|220px]]')
        div:tag('div'):cssText('position: absolute;right: 40px;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('转生')

        row_table = row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
        row_table:tag('tr'):tag('th'):cssText('width: 80px;'):wikitext('转生自'):done():tag('td'):wikitext('[['..args['转生基础怪物中文名']..']]')
        html:wikitext('[[分类:转生]]')
    else
        img_td:wikitext('[[File:'..args['名称']..'.jpg|link=|220px]]')

        result = smw.query({'[[转生自::'..args['名称']..']]', '?名称'}, frame)
        if #result == 1 then
            row_table = row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
            row_table:tag('tr'):tag('th'):cssText('width: 80px;'):wikitext('转生后'):done():tag('td'):wikitext('[['..result[1]['名称']..']]')
        end
    end    

    -- 中间的基础信息
    row_div = html:tag('div'):addClass('col-md-8'):tag('div'):addClass('row')
    row_div_2 = row_div:tag('div'):addClass('col-md-6'):tag('div'):addClass('row')

    row_div_2:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
               :tag('tr'):tag('th'):wikitext('基础信息')

    headers = {'体力','能量','攻击','防御','经验','金币','变弱等级','特训点数','重量'}
    rename_list = {
        ['变弱等级'] = '汗泪等级'
    }
    ref_text_list = {
--        ['变弱等级'] = '当玩家达到「平均等级」对应的级别时,调查怪物会显示怪物比你弱。在变弱之前的几个级别里,玩家会和怪物是同等实力,可以让装备获得汗泪累积。'
    }

    table_div = row_div_2:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
    for _, v in ipairs(headers) do
        if args[v] ~= nil and args[v] ~= '' then
            if rename_list[v] ~= nil then
                v_header = rename_list[v]
            else
                v_header = v
            end
            tr = table_div:tag('tr')
            th = tr:tag('th'):css('width', '50%'):wikitext(v_header)
            if ref_text_list[v] ~= nil then
                th:wikitext(ref(ref_text_list[v], frame))
            end
            -- 值
            value_text = args[v]
            -- 变弱等级修正
            if v == '变弱等级' then
                if tonumber(value_text) < 999 then
                    value_text = '≤'..(tonumber(value_text)-1)..'级'
                else
                    value_text = '待补充'
                end
            end
            -- 经验值修正
            tr:tag('td'):wikitext(value_text):done()
        end
    end

    -- 获得道具
    row_div_2 = row_div:tag('div'):addClass('col-md-6'):tag('div'):addClass('row')
    row_div_2:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
               :tag('tr'):tag('th'):wikitext('获得道具')

    normal_drop = itembox(frame, {args['普通掉落'], 'jt-block'})
    if normal_drop == 'Error:道具信息错误' then
        normal_drop = '&nbsp;'
    end

    rare_drop = itembox(frame, {args['稀有掉落'], 'jt-block'})
    if rare_drop == 'Error:道具信息错误' then
        rare_drop = '&nbsp;'
    end
    row_div_2:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
               :tag('tr'):tag('th'):css('width', '50px'):wikitext('普通'):done()
                         :tag('td'):css('text-align', 'left'):wikitext(normal_drop):done():done()
               :tag('tr'):tag('th'):wikitext('稀有'):done()
                         :tag('td'):css('text-align', 'left'):wikitext(rare_drop)

    -- 主要栖息地
    row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
               :tag('tr'):tag('th'):wikitext('主要栖息地')

    zone_info = smw.query({'[[分类:地区]] [[出现怪物::'..args['名称']..']]', '?出现怪物'}, frame)
    zone_info_text = ''
    if #zone_info > 0 then
        for _, v in ipairs(zone_info) do
            if zone_info_text ~= '' then
                zone_info_text = zone_info_text..'<br>'
            end
            zone_info_text = zone_info_text..'[['..v[1]..']]'
            for _, str in ipairs(mw.text.split(v['出现怪物'], '<MANY>')) do
                kv = mw.text.split(str, '<RCRD>')
                if kv[1] == args['名称'] then
                    if kv[2] ~= '' then
                        zone_info_text = zone_info_text..'('..kv[2]..'只)'
                    end
                    if kv[3] ~= '' then
                        zone_info_text = zone_info_text..'('..kv[3]..')'
                    end
                    break
                end
            end
        end
    end
    
    if args['栖息地'] ~= nil and args['栖息地'] ~= '' then
        if zone_info_text ~= '' then
            zone_info_text = zone_info_text..'<br>'
        end 
        zone_info_text = zone_info_text..args['栖息地']
    end

    if zone_info_text == '' then
        zone_info_text = '未知'
    end

    row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
               :tag('tr'):tag('td'):cssText('text-align:left;word-break: break-all;'):wikitext(zone_info_text)
    

    -- 右侧的额外信息
    row_div = html:tag('div'):addClass('col-md-12'):tag('div'):addClass('row')

    row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
               :tag('tr'):tag('th'):wikitext('耐性')

    headers_list = {{'火', '冰', '雷', '土', '风', '暗', '光','无'},
                    {'睡眠', '混乱', '魅惑', '麻痹', '中毒', '幻觉', '封印'},
                    {'大笑', '摔倒', '束缚', '恐惧', '即死', '击飞', '打断'},
                    {'能量吸收', '耐性降低', '攻击降低', '防御降低', '行动延长', '重量减少'}}

    for num, headers in ipairs(headers_list) do
        tr_div = row_div:tag('div'):addClass('col-xs-6 col-md-3'):tag('table'):addClass('wikitable')
        if num ~= 4 then
            css_text = 'width:50%'
        else
            css_text = ''
        end
        for _, v in ipairs(headers) do
            if args[v] ~= nil and args[v] ~= '' then
                    if num == 1 then
                        class_text = 'element'..tonumber(args[v])
                    else
                        class_text = 'effect'..args[v]
                    end
                tr_div:tag('tr'):tag('th'):cssText(css_text):wikitext(v):done()
                                :tag('td'):addClass(class_text):wikitext(_value_html(num, args[v])):done()
            end
        end
    end


    if args['技能咒文'] ~= nil and args['技能咒文'] ~= '' then 
        row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
                   :tag('tr'):tag('th'):wikitext('技能 / 咒文')

        row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
                   :tag('tr'):tag('td'):wikitext(args['技能咒文'])
    end

    -- 人工说明
    if args['说明'] ~= nil and args['说明'] ~= '' then 
        row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
                   :tag('tr'):tag('th'):wikitext('说明')

        row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
               :tag('tr'):tag('td'):css('text-align', 'left'):wikitext(args['说明'])
    end

    -- 背景小知识
    row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
        :tag('tr'):tag('th'):wikitext('背景小知识')

    row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
       :tag('tr'):tag('td'):css('text-align', 'left'):wikitext(args['背景1']..'<br/>'..args['背景2'])

    -- 备注
    if args['备注'] ~= '' and args['备注'] ~= nil then
    row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
        :tag('tr'):tag('th'):wikitext('补充信息')

    row_div:tag('div'):addClass('col-xs-12'):tag('table'):addClass('wikitable')
       :tag('tr'):tag('td'):css('text-align', 'left'):wikitext(args['备注'])
    end

    -- 存储数据
    _set_monster_info(args)

    -- 添加分类
    html:wikitext('[[分类:怪物]][[分类:'..args['系别']..'怪物]]')

    return tostring(html)
end

function _value_html(num, value)
    if num == 1 then
        list = {
            [7]='极弱',
            [6]='弱',
            [5]='较弱',
            [4]='普通',
            [3]='较强',
            [2]='强',
            [1]='极强',
            [0]='无效',
        }
    else
        list = {
            [7]='极易',
            [6]='易中',
            [5]='较易',
            [4]='普通',
            [3]='弱抗',
            [2]='抵抗',
            [1]='强抗',
            [0]='免疫',
        }
    end

    return list[tonumber(value)]
end

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

-- 怪物列表页(按系别)
function _monster_list_page(args)
mw.log(args[1])
    query = {'[[分类:怪物]] [[系别::'..args[1]..']]', '?名称', '?体力#','?变弱等级#','?攻击#','?防御#','?经验#','?日服经验#','?金币#','?特训点数#','?普通掉落','?稀有掉落', '?掉落道具', '?转生自', 'sort=变弱等级','limit=500'}
    result = smw.query(query, frame)
--    return mw.dumpObject(result)
    return monster_list(result,nil,frame)
end

function _monster_list_page_query(args)
    query = {'[[分类:怪物]] '..args[1], '?名称','?体力#','?变弱等级#','?攻击#','?防御#','?经验#','?日服经验#','?金币#','?特训点数#','?普通掉落','?稀有掉落', '?掉落道具', '?转生自', 'sort=变弱等级','limit=500'}
    result = smw.query(query, frame)
    return monster_list(result,nil,frame)
end

function _monster_list_page_query_Byname(args)
    local _monster_names,_result = mw.text.split(args[1],","),{}
    for i=1, #_monster_names do
        query = {'[[分类:怪物]][[名称::'.._monster_names[i]..']]', '?名称','?体力#','?变弱等级#','?攻击#','?防御#','?经验#','?日服经验#','?日服经验#','?金币#','?特训点数#','?普通掉落','?稀有掉落', '?掉落道具', '?转生自', 'sort=变弱等级','limit=500'}
        result = smw.query(query, frame)
        if(result[1]~=nil and result[1]['名称']==_monster_names[i]) then 
            table.insert(_result, result[1])
        end
    end
    return monster_list(_result,nil,frame)
end
-----------------------------------------------------------------------------
-- 存储怪物数据
-----------------------------------------------------------------------------

function _set_monster_info(args)
    -- 怪物数据并不需要都写入smw
    save_headers = {'名称', '系别', '变弱等级', '体力', '攻击', '防御', '经验', '版本', '日服经验','特训点数', '普通掉落', '稀有掉落', '金币', '重量','火', '冰', '雷', '土', '风', '暗', '光','睡眠', '混乱', '魅惑', '麻痹', '中毒', '幻觉', '封印','大笑', '摔倒', '束缚', '恐惧', '即死', '击飞', '打断'}
    save_args = {}

    for _, header in ipairs(save_headers) do
        save_args[header] = args[header]
    end

    if save_args['变弱等级'] == -1 or save_args['变弱等级'] == '' or save_args['变弱等级'] == nil then
        save_args['变弱等级'] = '999'
    end
    -- 存入smw数据
    smw.set(save_args, frame)
    
    -- 掉落信息单独写
    if args['普通掉落'] ~= '' and args['普通掉落'] ~= nil then
        smw.set({['掉落道具']=args['普通掉落']..';普通'}, frame)
    end
    if args['稀有掉落'] ~= '' and args['稀有掉落'] ~= nil then
        smw.set({['掉落道具']=args['稀有掉落']..';稀有'}, frame)
    end

    -- 转生单独写
    if args['转生基础怪物中文名'] ~= '' and args['转生基础怪物中文名'] ~= nil then
        smw.set({['转生自']=args['转生基础怪物中文名']}, frame)
    end
end
----------怪物分布-----------------
function p.monster_list_at(pageframe)
    frame = pageframe
    return _monster_list_at(getArgs(pageframe))
end
p['分布'] = p.monster_list_at
function _monster_list_at(args)
    local _str,_sep= '',','
    local html = mw.html.create():tag('table'):addClass('wikitable')
    html:tag('tr')
            :tag('th'):wikitext('怪物名'):done()
            :tag('th'):wikitext('数量'):done()
            :tag('th'):wikitext('信息'):done()
            :tag('th'):wikitext('区域'):done()
        :done()
    for _, v in ipairs(args) do
        if v ==',' or  v==',' or v =='~~' or  v=='!!' or v == '|' or v == '@' or v == '#' then
            _sep = v
        elseif string.find(v, '*') == 1 then
            html:tag('tr'):tag('td'):attr('colspan', '4'):wikitext(string.sub(v,2,string.len(v))):done()
        elseif string.find(v, '<td>') == 1 then
            html:tag('tr'):wikitext(v):done()
        else
            local data = mw.text.split(v,_sep)
            if data ~=nil and data[1] ~= nil then
                local _show_data,_show_text,_dl,_bz2 = '','','',''
                _show_data = frame:callParserFunction('#show', {data[1], '?掉落道具#','?变弱等级#','format=array'});
                if _show_data ~= nil and _show_data ~='' then
                    _show_text = mw.text.split(_show_data, '<PROP>')
                    if(_show_text[2] ~= nil and _show_text[2] ~= '') then
                        _bz2 = _show_text[2]..'级'..'(\'\'\'汗泪等级\'\'\')'
                    end
                    if(_show_text[1] ~= nil and _show_text[1] ~= '') then
                        for _a,_b in ipairs(mw.text.split(_show_text[1], '<MANY>')) do
                            if _b ~= nil and _b ~= '' then
                                _dl = mw.text.split(_b, ' ')
                                if(_dl[1] ~=nil and _dl[2] ~=nil ) then
                                    _bz2 = _bz2..'<br>'..item_link_1X(_dl[1],nil,14).._dl[2]
                                end
                            end
                        end
                    end
                end
                if data[2] == nil then
                    data[2] = ""
                end
                if data[3] == nil then
                    data[3] = ""
                end
                smw.set({['出现怪物'] = data[1]..';'..data[2]..';'..data[3]},frame)             
                html:tag('tr')
                        :tag('td'):wikitext('[['..data[1]..']]'):done()
                        :tag('td'):wikitext(data[2]):done()
                        :tag('td'):attr('style','text-align:left;'):wikitext(_bz2):done()
                        :tag('td'):wikitext(data[3]):done()
                    :done()
            end
        end
    end
    html:done()
    --local html = mw.html.create():tag('div'):wikitext(str)
    return tostring(html)   
end
return p