本模板用于输出功法详细信息


在任意页面输入

{{#invoke:GongFa|mian|太极拳}}

或在太极拳页面输入

{{#invoke:GongFa|mian}}

使用模板:模板:GongFa/基础模板:GongFa/内功模板:GongFa/摧破模板:GongFa/轻灵模板:GongFa/护体模板:GongFa/运功模板:GongFa/发挥控制输出页面格式


local p = {}

local NewLine = '<br/>\n'

function ul(arr)
	if arr==nil then return end
	local s = ''
	local first = true
	for k,v in ipairs(arr) do
		if not first then
			s = s..NewLine
		end
		first = false
		s = s..'·'..v
	end
	return s
end

function p.power2(gf) -- 正逆练特效
	local id1 = gf.data103
	local id2 = gf.data104
	if (not id1) or (not id2) then
		error('特效id错误:'..gf[1]..','..gf[2])
	end
	local power = mw.loadData("Module:GongFa/power")
	local title1 = '<span style="color:#8FBAE7">心法正练</span><br/>'
	local title2 = '<span style="color:#E4504D">心法逆练</span><br/>'
	if id1==id2 then
		local n = math.floor(id1/100)
		if n==3 or n==4 then
			local mod = id1%100
			id1 = 30000 + mod
			id2 = 40000 + mod
			title1 = '<span style="color:#8FBAE7">神剑出鞘</span><br/>'
			title2 = '<span style="color:#E4504D">剑柄碎片</span><br/>'
		end
	end
	local p1 = ul(power[id1])
	local p2 = id1~=id2 and ul(power[id2])
	local result = ''
	if p1 and p2 then
		result = title1..p1..'<br/>'..title2..p2
	elseif p1 then
		result = title1..p1
	elseif p2 then
		result = title2..p2
	end
	return result
end

function findOne(name)
	local query = {
		['_id'] = { ["$regex"] = '^Data:GongFa\.tab' },
		['data0'] = name,
	}
	local result = mw.huiji.db.findOne(query)
	return result
end

p.switch = {  
	[0] = function(gf)  
        return mw.getCurrentFrame():expandTemplate{ title = 'GongFa/内功', args = gf }
    end,  
    [1] = function(gf)  
        return mw.getCurrentFrame():expandTemplate{ title = 'GongFa/摧破', args = gf }
    end,  
    [2] = function(gf)  
        return mw.getCurrentFrame():expandTemplate{ title = 'GongFa/轻灵', args = gf }
    end,  
    [3] = function(gf)  
        return mw.getCurrentFrame():expandTemplate{ title = 'GongFa/护体', args = gf }
    end,  
} 
p.switch[-1] = p.switch[0] -- 吐纳法

function p.mian(frame) --p.mian({'太极拳'})
	local args = frame.args or frame
	local name = args['name'] or args[1] or mw.title.getCurrentTitle().text
	name = mw.ustring.gsub(name, '功法/', '')
	local sp = args['sp'] or args[2]
	local gf = findOne(name)
	if next(gf)==nil then
		error("无此功法:"..name)
	end
	
	local switch = p.switch[gf.data6]
	local power = p.power2(gf)
	
	gf = require('Module:GongFa/value').change(gf, true)
	gf.sp = sp
	
	local runEffect = gf['运功效果']
	
	local result = mw.getCurrentFrame():expandTemplate{ title = 'GongFa/基础', args = gf }
	result = switch and result..switch(gf) or result
	if runEffect then result = result..mw.getCurrentFrame():expandTemplate{ title = 'GongFa/运功'}..runEffect end
	if gf['需求'] then result = result..mw.getCurrentFrame():expandTemplate{ title = 'GongFa/发挥'}..gf['需求'] end
	result = result..'<br/>'..power
	result = '<div style="max-width:500px">'..result..'</div>'
	return result
end --p.mian({'太极拳'})


return p
avatar