--Toon Page-Flip
--Script by JustFish
function c100268004.initial_effect(c)
	aux.AddCodeList(c,15259703)
	--activate
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1,100268004+EFFECT_COUNT_CODE_OATH)
	e1:SetCondition(c100268004.con)
	e1:SetTarget(c100268004.tg)
	e1:SetOperation(c100268004.op)
	c:RegisterEffect(e1)
end
function c100268004.ffilter(c)
	return c:IsFaceup() and c:IsCode(15259703)
end
function c100268004.con(e)
	return Duel.IsExistingMatchingCard(c100268004.ffilter,e:GetHandlerPlayer(),LOCATION_ONFIELD,0,1,nil)
end
function c100268004.filter(c,e,tp)
	return c:IsType(TYPE_TOON) and c:IsCanBeSpecialSummoned(e,0,tp,true,false,POS_FACEUP)
end
function c100268004.tg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then
		local dg=Duel.GetMatchingGroup(c100268004.filter,tp,LOCATION_DECK,0,nil,e,tp)
		return dg:GetClassCount(Card.GetCode)>=3 and Duel.GetLocationCount(tp,LOCATION_MZONE)>0
	end
	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_DECK)
end
function c100268004.op(e,tp,eg,ep,ev,re,r,rp)
	local g=Duel.GetMatchingGroup(c100268004.filter,tp,LOCATION_DECK,0,nil,e,tp)
	if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 or g:GetClassCount(Card.GetCode)<3 then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_CONFIRM)
	local sg=g:SelectSubGroup(tp,aux.dncheck,false,3,3)
	if #sg>0 then
		Duel.ConfirmCards(1-tp,sg)
		local tc=sg:RandomSelect(1-tp,1):GetFirst()
		Duel.ConfirmCards(tp,tc)
		Duel.SpecialSummon(tc,0,tp,tp,true,false,POS_FACEUP)
		Duel.ShuffleDeck(tp)
	end
end
