来自魔法纪录中文Wiki
跳转至: 导航 搜索

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

--local getArgs = require('Module:Arguments').getArgs
local p = {}
math.randomseed(os.time())

function p.test( frame )
	local a=1
	local b=2
	--return string.format("a=%d,b=%d",a,b)
	args = {10,10,10,10,10,10,10}
	local output2 = p.draw10( args[1], args[2], args[3], args[4], args[5], args[6], args[7] )
	return output2 --string.format("%d,%d,%d", output2[1], output2[2], output2[3])
end

function p.runsplit( frame )
	local o = p.split( frame.args[1], frame.args[2], tonumber(frame.args[3]))
	return o
end

function p.split( s, p, pos )
	local t = mw.text.split(s,p)
	return t[pos]
end

function p.rundraw1( frame )
	--local args = getArgs(frame)
	local output2 = p.draw1( frame.args[1], frame.args[2], frame.args[3], frame.args[4], frame.args[5], frame.args[6], frame.args[7] )
	return string.format("%d,%d,%d", output2[1], output2[2], output2[3])
end

function p.rundraw10( frame )
	--local args = getArgs(frame)
	return p.draw10( frame.args[1], frame.args[2], frame.args[3], frame.args[4], frame.args[5], frame.args[6], frame.args[7] )
end

function p.draw1( drew, puella4, puella3, puella2, memoria4, memoria3, memoria2 )
	if( drew==99 ) then
		return {math.random( puella4 ), 1, 0}
	end
	local r = math.random()
	--local cata = 6 --1~3 for puella4~2, 4~6 for memoria4~2
	if( r<0.01 ) then
		--cata = 1
		return {math.random( puella4 ), 1, 0}
	elseif( r<0.05 ) then
		--cata = 2
		return {math.random( puella3 ), 2, drew+1}
	elseif( r<0.305 ) then
		--cata = 3
		return {math.random( puella2 ), 3, drew+1}
	elseif( r< 0.345 ) then
		--cata = 4
		return {math.random( memoria4 ), 4, drew+1}
	elseif( r<0.465 ) then
		--cata = 5
		return {math.random( memoria3 ), 5, drew+1}
	else
		--cata = 6
		return {math.random( memoria2 ), 6, drew+1}
	end
end

function p.draw1_1( drew, puella4, puella3, puella2, memoria4, memoria3, memoria2 )
	if( drew==99 ) then
		return {math.random( puella4 ), 1, 0}
	end
	local r = math.random()
	--local cata = 6 --1~3 for puella4~2, 4~6 for memoria4~2
	if( r<0.01 ) then
		--cata = 1
		return {math.random( puella4 ), 1, 0}
	elseif( r<0.15 ) then
		--cata = 2
		return {math.random( puella3 ), 2, drew+1}
	else
		--cata = 3
		return {math.random( puella2 ), 3, drew+1}
	end
end

function p.draw1_2( drew, puella4, puella3, puella2, memoria4, memoria3, memoria2 )
	if( drew==99 ) then
		return {math.random( puella4 ), 1, 0}
	end
	local r = math.random()
	--local cata = 6 --1~3 for puella4~2, 4~6 for memoria4~2
	if( r<0.02 ) then
		--cata = 1
		return {math.random( puella4 ), 1, 0}
	elseif( r<0.22 ) then
		--cata = 2
		return {math.random( puella3 ), 2, drew+1}
	elseif( r< 0.4 ) then
		--cata = 4
		return {math.random( memoria4 ), 4, drew+1}
	else
		--cata = 5
		return {math.random( memoria3 ), 5, drew+1}
	end
end

function p.draw10( drew, puella4, puella3, puella2, memoria4, memoria3, memoria2 )
	local output1 = ""
	local outputtemp = {}
	for i=1,8 do
		outputtemp = p.draw1( drew, puella4, puella3, puella2, memoria4, memoria3, memoria2 )
		drew = outputtemp[3]
		if( i==1 ) then
			output1 = string.format("%d,%d",outputtemp[1],outputtemp[2])
		else
			output1 = string.format("%s,%d,%d",output1,outputtemp[1],outputtemp[2])
		end
	end
	outputtemp = p.draw1_1( drew, puella4, puella3, puella2, memoria4, memoria3, memoria2 )
	drew = outputtemp[3]
	output1 = string.format("%s,%d,%d",output1,outputtemp[1],outputtemp[2])
	outputtemp = p.draw1_2( drew, puella4, puella3, puella2, memoria4, memoria3, memoria2 )
	drew = outputtemp[3]
	output1 = string.format("%s,%d,%d,%d",output1,outputtemp[1],outputtemp[2],drew)
	return output1
end

return p