--神心流剑豪·厄科
function c66914000.initial_effect(c)
	--activate from hand
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetCode(EFFECT_QP_ACT_IN_NTPHAND)
	e1:SetRange(LOCATION_MZONE)
	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard,0x373))
	e1:SetTargetRange(LOCATION_HAND,0)
	c:RegisterEffect(e1)
	local e2=e1:Clone()
	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
	c:RegisterEffect(e2)   
	--to hand
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(66914000,0))
	e1:SetType(EFFECT_TYPE_QUICK_O)
	e1:SetRange(LOCATION_MZONE)
	e1:SetCountLimit(1,66914000)
	e1:SetCode(EVENT_CHAINING)
	e1:SetCondition(c66914000.condition)
	e1:SetTarget(c66914000.thtg)
	e1:SetOperation(c66914000.thop)
	c:RegisterEffect(e1) 
end
function c66914000.condition(e,tp,eg,ep,ev,re,r,rp)
	local count=0
	for i=1,ev do
		local te,tgp=Duel.GetChainInfo(i,CHAININFO_TRIGGERING_EFFECT,CHAININFO_TRIGGERING_PLAYER)
		if tgp==tp and te:GetHandler():IsSetCard(0x373)  then
			count=count+1
		end
	end
	return count>=1 and Duel.GetCurrentChain()>0
end
function c66914000.thtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
	local count=0
	local chain=Duel.GetCurrentChain()
	for i=1,chain do
		local te,tgp=Duel.GetChainInfo(i,CHAININFO_TRIGGERING_EFFECT,CHAININFO_TRIGGERING_PLAYER)
		if tgp==tp then
			count=count+1
		end
	end
	if chk==0 then return count>0 and (Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)>=count or count<2) and (count<1 or Duel.IsPlayerCanDraw(tp,1)) end
	local cat=0
	if count>=2 then
		cat=cat|CATEGORY_DRAW  
		Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,1)
	end
	if count>=3 then
		cat=cat|CATEGORY_TOHAND
		cat=cat|CATEGORY_SEARCH
	end
	e:SetCategory(cat)
	e:SetLabel(count)
end
function c66914000.filter(c)
	return c:IsSetCard(0x373) and c:IsAbleToHand()
end
function c66914000.thop(e,tp,eg,ep,ev,re,r,rp)
	local count=e:GetLabel()
	if  count>=1 then
		local e1=Effect.CreateEffect(e:GetHandler())
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetCode(EFFECT_UPDATE_ATTACK)
		e1:SetValue(500)
		e1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_DISABLE)
		e:GetHandler():RegisterEffect(e1)
		local e2=e1:Clone()
		e2:SetCode(EFFECT_UPDATE_DEFENSE)
		e:GetHandler():RegisterEffect(e2)
	end
	if count>=2 then
		Duel.BreakEffect()
		Duel.Draw(tp,1,REASON_EFFECT)
	end
	if count>=3 then
		Duel.BreakEffect()
		if Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)==0 then return end
		Duel.ConfirmDecktop(tp,count)
		local dg=Duel.GetDecktopGroup(tp,count)
		local g=dg:Filter(c66914000.filter,nil)
		if g:GetCount()>0 then
			Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
			local sg=g:Select(tp,1,1,nil)
			Duel.SendtoHand(sg,nil,REASON_EFFECT)
			Duel.ConfirmCards(1-tp,sg)
		end
		Duel.ShuffleDeck(tp)
	end
end