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

local Util = require('Module:Util')
local Qi = require('Module:GongFa/power/qi')

local function ul(arr)
	if arr==nil then return end
	local t = {}
	for i,v in ipairs(arr) do
		t[i] = '*'..v..'\n'
	end
	return table.concat(t, '')
end

local function JiDao(s) --祭刀
	s = mw.ustring.gsub(s, '.-“(.-祭)”.*', '%1', 1)
	local data = Util.json('Data:祭刀.json').data
	local index = Util.find(data, function(tuple) return tuple.data0==s end)--C_200033C_D
	return s..':'..Util.replaceColor(data[index].data99, true)
end

local function PowerPost(power, text)
	if power==nil then return end
	local t = {}
	for i,v in ipairs(power) do
		t[i] = v
	end
	if text then
		t[1] = t[1]..'\n'..text
	elseif text== false then
		local raw = power.raw
		local list = {}
		local function insert(line)
			table.insert(list, line)
		end
		if string.find(raw._id, '^Data:GongFaFPower') then --内功特效
			local num = {
				{'data1', '功法发挥上限 +20%'},
				{'data2', '功法威力 +10%'},
				{'data61', '膂力 +@'},
				{'data62', '体质 +@'},
				{'data63', '灵敏 +@'},
				{'data64', '根骨 +@'},
				{'data65', '悟性 +@'},
				{'data66', '定力 +@'},
				{'data71', '膂力发挥 +@%'},
				{'data72', '体质发挥 +@%'},
				{'data73', '灵敏发挥 +@%'},
				{'data74', '根骨发挥 +@%'},
				{'data75', '悟性发挥 +@%'},
				{'data76', '定力发挥 +@%'},
				{'data111', '每个[[名誉]]>=75的[[轮回|前世]]提供@%威力'},
				{'data112', '每个[[名誉]]<=-75的[[轮回|前世]]提供@%威力'},
				{'data121', '[[封穴]]影响 -@%'},
				{'data131', '[[破绽]]影响 -@%'},
				{'data141', '[[疗伤#战斗中的疗伤|治疗]]速度及效果 +@%'},
				{'data142', '[[疗伤#战斗中的疗伤|治疗]]速度及效果 -@%'},
				{'data151', '功法威力 +@%'},
				{'data152', '功法威力 +@%'},
				{'data161', '功法威力 +@%'},
				{'data162', '功法威力 +@%'},
				{'data171', '武器发挥上限 +@%'},
				{'data172', '武器使用需求 -@%'},
				{'data181', '每多2点[[真气]],功法威力+@%'},
				{'data182', '每少2点[[真气]],功法威力+@%'},
				{'data191', "每有1'''级'''正面[[特性]],功法威力+@%"},
				{'data192', "每有1'''级'''负面[[特性]],功法威力+@%"},
			}
			local str = {
				{'data3', '功法威力 +@%'},
				{'data4', '功法消耗 -@%'},
				{'data5', '[[功法伤害调整]] -30%'},
				{'data6', '[[功法伤害调整]] +30%'},
				{'data10', '功法发挥上限 +@%'},
				{'data11', '功法使用需求 -@%'},
			}
			for _,v in ipairs(num) do
				local val = raw[v[1]]
				if val~=0 then
					local content = mw.ustring.gsub(v[2], '@', tostring(val), 1)
					insert(content)
				end
			end
			for _,v in ipairs(str) do
				local val = raw[v[1]]
				if val~='0&0' then
					val = mw.text.split(val, '&', true)[2]
					local content = mw.ustring.gsub(v[2], '@', val, 1)
					insert(content)
				end
			end
			do --改变真气效果
				if raw.data101~='0&0' then
					local pair = mw.text.split(raw.data101,'&',true)
					insert(Qi(pair[1],pair[2]))
				end
				if raw.data102~='0&0' then
					local pair = mw.text.split(raw.data102,'&',true)
					for _,v in ipairs(Qi(pair[1],pair[2],true)) do
						insert(v)
					end
				end
			end
		else
			if string.find(raw.data97, '种下若蛊') then
				local reverse = raw.data97~='为敌种下若蛊' --判断逆练
				local name = mw.ustring.match(raw.data99, '(..)若蛊')
				local feature = require('Module:Feature').show
				insert(feature(name..'若蛊', reverse and 1 or 2)..'→'..feature(name..'成蛊'))	
			end
			if raw.data97=="获得祭刀效果" then
				insert(JiDao(raw.data99))
			end
			if Util.between(0,raw.data4,100) then
				insert('触发概率 '..raw.data4..'%')
			end
			if raw.data3==21 then
				insert('[[守御值]] +最大值的10%')
			elseif raw.data3==22 then
				insert('[[守御值]] -最大值的10%')
			end
			for _,typ in ipairs{'通用','功法'} do
				local tuple = require('Module:Json').read(typ..'伤害调整/功法')[raw.id]
				if tuple then
					insert('[['..typ..'伤害调整]] '..tuple[1])
					if tuple[2] then
						insert('触发概率 '..tuple[2])
					end
					if tuple[3] then
						insert('触发条件 '..tuple[3])
					end
				end
			end
		end
		for i,v in ipairs(list) do
			t[1] = t[1]..'\n**'..v
		end
	end
	return ul(t)
end

local function CustomPost(raw, args, key) --自定义后缀
	if args==nil then return end --说明不需要生成后缀
	if args[key]==nil and args.both==nil then return false end --没有自定义输入,但尝试自动生成
	setmetatable(raw, {__index = function() return 0 end})
	local text = ''
	if args[key] and args.both then
		text = args[key]..'\n'..args.both
	else
		text = (args[key] or '')..(args.both or '')
	end
	text = mw.ustring.gsub(text, '{(.-)}', function(s)
		local makeFunc = require('Module:CalcExpr')
		return tostring(makeFunc(s)(raw))
	end)
	return text
end

return function(tuple, args)
	local PowerData = require("Module:GongFa/power/data")
	local id1 = tuple.data103 or 0
	local id2 = tuple.data104 or 0
	local title1 = '<span style="color:#8FBAE7">心法正练</span>\n'
	local title2 = '<span style="color:#E4504D">心法逆练</span>\n'
	if id1==id2 then
		local n = math.floor(id1/100)
		if n==300 or n==400 then
			local mod = id1%100
			id1 = 30000 + mod
			id2 = 40000 + mod
			title1 = '<span style="color:#8FBAE7">神剑出鞘</span>\n'
			title2 = '<span style="color:#E4504D">剑柄碎片</span>\n'
		end
	end
	title1 = '<span style="float:right">id:'..(id1 or 0)..'</span>'..title1
	title2 = '<span style="float:right">id:'..(id2 or 0)..'</span>'..title2
	local p1 = PowerPost(PowerData[id1], CustomPost(tuple, args, '正'))
	local p2 = id1~=id2 and PowerPost(PowerData[id2], CustomPost(tuple, args, '逆')) or nil
	local result = ''
	if p1 and p2 then
		result = title1..p1..'\n'..title2..p2
	elseif p1 then
		result = title1..p1
	elseif p2 then
		result = title2..p2
	end
	return result
end
avatar