--[决斗编年史]规则的超越者
function c66666005.initial_effect(c)
	if c66666005.reg then return end
	c66666005.reg = true
	c66666005.tag = Duel.GetLP(0) > 8000
	c66666005.active = {[0]=false,[1]=false}
	local e1=Effect.GlobalEffect()
	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e1:SetCode(EVENT_ADJUST)
	e1:SetOperation(c66666005.init)
	Duel.RegisterEffect(e1,0)
	local e2=Effect.GlobalEffect()
	e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)
	e2:SetCode(EVENT_PREDRAW)
	e2:SetCondition(c66666005.cfcon)
	e2:SetOperation(c66666005.cfop)
	Duel.RegisterEffect(e2,0)
end
c66666005.tag = true
function c66666005.init(e)
	for tp = 0,1 do
		local g = Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_HAND,0,nil,66666005)
		local i = g:GetCount()
		if i > 0 then
			c66666005.active[tp] = true
			c66666005.active[tp+10] = true
			Duel.Exile(g,REASON_RULE)
			local top = Duel.GetDecktopGroup(tp,i)
			top:ForEach(c66666005.exile)
			Duel.Exile(top,REASON_RULE)
		end
		local g2 = Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_DECK,0,nil,66666005)
		if g2:GetCount() > 0 then
			c66666005.active[tp] = true
			c66666005.active[tp+10] = true
			Duel.Exile(g2,REASON_RULE)
		end
	end
	e:Reset()
end

function c66666005.exile(c)
	local tp = c:GetOwner()
	Duel.SendtoHand(Duel.CreateToken(tp,c:GetOriginalCode()),tp,REASON_RULE)
end
function c66666005.cfcon(e,tp,eg,ep,ev,re,r,rp)
	tp = Duel.GetTurnPlayer()
	return c66666005.active[tp]
end
function c66666005.filter(c,code)
	return c:GetOriginalCode()==code and c:GetOwner() == c:GetControler()
end
function c66666005.cfop(e,tp,eg,ep,ev,re,r,rp)
	tp = Duel.GetTurnPlayer()
	c66666005.active[tp+10] = not c66666005.active[tp+10]
	if c66666005.tag and c66666005.active[tp+10] then return end
	Duel.Hint(HINT_MESSAGE,tp,aux.Stringid(66666005,0))
	Duel.Hint(HINT_MESSAGE,1-tp,aux.Stringid(66666005,0))
	--Draw
	local e2=Effect.GlobalEffect()
	e2:SetType(EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_DRAW_COUNT)
	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e2:SetTargetRange(1,0)
	e2:SetValue(c66666005.DrawCount)
	e2:SetReset(RESET_PHASE+PHASE_END)
	Duel.RegisterEffect(e2,tp)
	--Summon Limit
	local e4=Effect.GlobalEffect()
	e4:SetType(EFFECT_TYPE_FIELD)
	e4:SetCode(EFFECT_SET_SUMMON_COUNT_LIMIT)
	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e4:SetTargetRange(1,0)
	e4:SetValue(100)
	e4:SetReset(RESET_PHASE+PHASE_END)
	Duel.RegisterEffect(e4,tp)
end

function c66666005.DrawCount(e)
	local p=Duel.GetTurnPlayer()
	local ct=Duel.GetFieldGroupCount(p,LOCATION_HAND,0)
	if ct>4 then return 1
	else return 5-ct end
end