Npc
来自蒙纳多研究本部
此模块的文档可以在模块:Npc/doc创建
local p = {} local post = require("Module:RequestHelper").post local getArgs = require("Module:Arguments").getArgs local html = require("Module:Html") local compress = html.compress local addlink = html.addlink local function itemName(data) local name = data.itemID.name if data.rankType > 0 then name = name .. data.rankType end return name end function p.template(frame, data) local wikitext = "" local sex = { [0] = {"荷姆斯", "男"}, [1] = {"荷姆斯", "女"}, [2] = {"海恩塔", "男"}, [3] = {"海恩塔", "女"}, [4] = {"机神界人", "男"}, [5] = {"机神界人", "女"}, [6] = {"诺彭", "公"}, [7] = {"诺彭", "母"}, [9] = {"海恩塔", "男"}, [10] = {"海恩塔", "女"} } local npcInfo = html.wikitable( {"特征", "活动时间", "性别", "种族", "年龄", "常去的地方", "礼物"}, { { data.rlt_job, data.range_s .. ":00 ~ " .. data.range_e .. ":00", sex[data.rlt_sex][2], sex[data.rlt_sex][1], data.rlt_age, data.rlt_lnd.name, addlink(itemName(data.present), "物品") } }, {transpose = true, class = "xbtable"} ) local excTalk = html.wikitable( {"交换对话1", "交换对话2", "交换对话3"}, { { data.exc_talk_id.exc_talk1, data.exc_talk_id.exc_talk2, data.exc_talk_id.exc_talk3 } }, {transpose = true, class = "xbtable"} ) local header = { {scope = "kizuna", label = "牵绊"}, {scope = "wpn", label = "武器"}, {scope = "head", label = "头"}, {scope = "body", label = "身"}, {scope = "arm", label = "手"}, {scope = "waist", label = "腰"}, {scope = "legg", label = "腿"}, {scope = "kessyou", label = "宝珠"}, {scope = "collect", label = "收藏品"}, {scope = "materia", label = "素材"} } local rows = {} for i = 1, 5 do local row = { kizuna = "", wpn = "", head = "", body = "", arm = "", waist = "", legg = "", kessyou = "", collect = "", materia = "" } for k, _ in pairs(data["exc_id" .. i]) do row.kizuna = "★" .. i if k ~= "row_id" then local key = mw.ustring.sub(k, 1, -2) local exchangeItemName = itemName(data["exc_id" .. i][k]) local slot = data["exc_id" .. i][k].itemID.uni_flag == 0 and ("[" .. data["exc_id" .. i][k].itemID.jwl_slot .. "]") or "" row[key] = row[key] .. "<div>" .. addlink(exchangeItemName, "物品") .. slot .. "</div>" mw.smw.set({["exchange" .. i] = exchangeItemName .. slot}) end end table.insert(rows, row) end local excItem = html.wikitable(header, rows, {class = "xbtable"}) wikitext = mw.ustring.format( [[ <div class="row"> <div class="medium-6 push-6 columns">%s</div> <div class="medium-6 pull-6 columns">%s</div> </div> %s %s ]], "[[文件:NPC-" .. data.row_id .. ".jpg|none|512px|上传图片]]", npcInfo, excItem, excTalk ) return compress(wikitext) end function p.setSmw(data) mw.smw.set( { id = data.row_id, area = data.rlt_lnd.mapID.name, landmark = data.rlt_lnd.name, present = itemName(data.present), timeRange = data.range_s .. ":00 ~ " .. data.range_e .. ":00" } ) end function p.fetchDataById(id) return post("bdat_common.FLD_npclist", id) end function p.main(frame) local out = "" local args = getArgs(frame) for _, id in ipairs(args) do local data = p.fetchDataById(id) out = out .. html.h2(data.rlt_lnd.mapID.name .. " (" .. data.row_id .. ")") out = out .. p.template(frame, data) p.setSmw(data) end -- mw.log(mw.text.jsonEncode(data, mw.text.JSON_PRETTY)) return out end return p