来自碧蓝航线海事局

此模块的文档可以在模块:彩蛋台词/doc创建

Text = mw.text

local p = {}

ZhNum = {
	[1] = '一',
	[2] = '两',
	[3] = '三',
	[4] = '四',
	[5] = '五',
	[6] = '六',
	[7] = '七',
	[8] = '八'
}

--------------------------------------------------
--	公开函数
--------------------------------------------------
p.Parse = function(frame)
	local arg = parseArgument(frame)
	local n = #arg
	if n < 1 then return '' end
	
	local couple_type = arg[n]
	arg[n] = nil
	
	if couple_type == 0 then
		-- CoupleShip
		--10112,10113,10114,2,0
		return parseShipCouple(unpack(arg))
	elseif couple_type == 1 then
		--CoupleType
		--3-2-1
		return parseTypeCouple(unpack(arg))
	elseif couple_type == 3 then
		--CoupleNation
		--2-5-3
		return parseNationCouple(unpack(arg))
	elseif couple_type == 4 then
		--CoupleIllustro
		--4,3,4
		return parseIllustroCouple(unpack(arg))
	end
	return [[<small>'''(???)'''</small>]]
end
p['解析']=p.Parse

p.CoupleShip = function(frame)
	local arg = parseArgument(frame)
	if not arg[2] then 
		return parseShipCouple(arg[1] or '???', 1)
	end
	if arg[#arg] > 8 then
		table.insert(arg,1)
	end
	return parseShipCouple(unpack(arg))
end
p.CoupleType = function(frame)
	local arg = parseArgument(frame)
	return parseTypeCouple(arg[1] or '???', arg[2] or 1)
end
p.CoupleNation = function(frame)
	local arg = parseArgument(frame)
	return parseNationCouple(arg[1] or '???', arg[2] or 1)
end
p.CoupleIllustro = function(frame)
	local arg = parseArgument(frame)
	return parseIllustroCouple(arg[1] or '???', arg[2] or 1)
end

--------------------------------------------------
--	主要过程
--------------------------------------------------
--特定舰船触发的彩蛋
function parseShipCouple(...)
	local n = #arg		--10112,10113,10114,2
	local span_num = arg[n]	--需要span_num艘船触发
	local ship_num = n - 1		--有ship_num艘船满足条件
	
	if ship_num < 1 then return '' end
	
	local title = ''	--编队中包含xxx、xxx或xxx中任意一艘
	local text = ''		--(xx, xx, xx)
	if ship_num == 1 then
		title = ('编队中包含%s'):format(shipIdToName(arg[1]))
		text = '(' .. spanLink(shipIdToName(arg[1]), title) ..')'
	else
		title = '编队中包含'
		local ship_list = {}
		--连接船名
		for i = 1, ship_num do
			--分隔符
			if i > 1 then
				title = title..'、'
			end
			
			local ship = shipIdToName(arg[i])
			title = title..ship
			ship_list[i] = ship
		end
		title = title ..'中任意'..ZhNum[span_num]..'艘舰船'
		
		text = '('
		for i = 1, ship_num do
			--分隔符
			if i > 1 then
				text = text .. ','
			end
			text = text .. spanLink(ship_list[i], title)
		end
		text = text .. ')'
	end
	return spanText(title, text)
end

--舰船类型触发的彩蛋
function parseTypeCouple(shipType, spanNum)
	--3-2-1
	local ship_type = typeIdToName(shipType)
	local title = ('编队中包含%d艘类型为%s的舰船'):format(spanNum, ship_type)
	local text = '('..spanLink(ship_type, title, ship_type..spanNum..'艘')..')'
	
	return spanText(title, text)
end

--特定阵营触发的彩蛋
function parseNationCouple(nationId, spanNum)
	--2-5-3
	local nation = nationIdToName(nationId)
	local title = ('编队中包含%d艘属于%s的舰船'):format(spanNum, nation)
	local text = '('..spanLink('阵营',title, nation..spanNum..'艘')..')'
	
	return spanText(title, text)
end

--特定画师触发的彩蛋
function parseIllustroCouple(illustroId, spanNum)
	--4,3,4
	local name = illustroIdToName(illustroId)
	local fleet = getFleetNickname(illustroId)
	return spanText(
		('编队中包含%d艘画师为%s的舰船'):format(spanNum, name),
			('('..fleet..')'):format(spanNum)
		)
end

--------------------------------------------------
--	工具函数
--------------------------------------------------
function shipIdToName(id)
	mSHD = require('模块:舰娘数据')
	
	return type(id) == 'string' and id
		or mSHD.ShipIdToName(id, '未知')
end

function typeIdToName(id)
	mSHD = require('模块:舰娘数据')
	
	return type(id) == 'string' and id
		or mSHD.TypeIdToName(id, '未知')
end

function nationIdToName(id)
	mSHD = require('模块:舰娘数据')
	
	return type(id) == 'string' and id
		or mSHD.NationIdToName(id, '未知')
end

function illustroIdToName(id)
	if type(id) == 'string' then return id end
	
	mILL = require('模块:画师数据')
	local data = mILL.GetIllustratorData(id)
	if not data then return '未知' end
	return data.name or data.pen_name
end

function getFleetNickname(id)
	if type(id) == 'string' then return id
	elseif id == 10 then return '猴子军团%d只' 
	elseif id == 8  then return '八才战队%d艘'
	elseif id == 4  then return '番茄大队%d只'
	elseif id == 1  then return '枫之军团%d艘'
	elseif id == 7  then return '阿鸡分队%d只'
	end
	
	mILL = require('模块:画师数据')
	local data = mILL.GetIllustratorData(id)
	if not data then return '未知舰队%d艘' end
	
	return (data.pen_name or data.name) .. '舰队%d艘'
end

function spanText(title, text)
	return ('<span style="font-weight:bold;font-size:smaller;color:#555555;" title="%s">%s</span>')
			:format(tostring(title), tostring(text))
end

function spanLink(link, title, text)
	return ('<a href="%s" style="color:#555555;">%s</a>')
			:format(tostring(mw.uri.fullUrl(link)) ,tostring(text or link))

	-- return ('[[%s|<span style="color:#555555;" title="%s">%s</span>]]')
			-- :format(tostring(link), tostring(title), tostring(text or link))
end

function parseArgument(frame)
	local arg = {}
	for k, v in pairs(frame.args) do
		arg[k] = tonumber(v) or Text.trim(v)
	end
	return arg
end

return p