--鹰身小天使
local s,id,o=GetID()
function s.initial_effect(c)
	aux.AddCodeList(c,12206212)
	aux.EnableChangeCode(c,76812113,LOCATION_MZONE+LOCATION_GRAVE)
	--tohand
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH)
	e1:SetType(EFFECT_TYPE_IGNITION)
	e1:SetRange(LOCATION_MZONE)
	e1:SetCountLimit(1,id)
	e1:SetTarget(s.thtg)
	e1:SetOperation(s.thop)
	c:RegisterEffect(e1)
	--def up
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_UPDATE_DEFENSE)
	e2:SetRange(LOCATION_MZONE)
	e2:SetTargetRange(LOCATION_MZONE,0)
	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard,0x64))
	e2:SetValue(1000)
	c:RegisterEffect(e2)
end
function s.thtg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)>=3
		and Duel.GetDecktopGroup(tp,3):FilterCount(Card.IsAbleToHand,nil)>0 end
	Duel.SetTargetPlayer(tp)
end
function s.thfilter(c)
	return c:IsSetCard(0x64) and c:IsAbleToHand()
end
function s.thfilter2(c)
	return c:IsSetCard(0x64) and c:IsType(TYPE_TRAP) and c:IsAbleToHand()
end
function s.thop(e,tp,eg,ep,ev,re,r,rp)
	local p=Duel.GetChainInfo(0,CHAININFO_TARGET_PLAYER)
	Duel.ConfirmDecktop(p,3)
	local g=Duel.GetDecktopGroup(p,3)
	local tg=g:Filter(s.thfilter,nil)
	if #tg>0 and Duel.SelectYesNo(p,aux.Stringid(id,0)) then
		Duel.Hint(HINT_SELECTMSG,p,HINTMSG_ATOHAND)
		local sg=tg:Select(p,1,1,nil)
		Duel.SendtoHand(sg,nil,REASON_EFFECT)
		Duel.ConfirmCards(1-p,sg)
		if sg:GetFirst():IsCode(76812113,12206212) and Duel.IsExistingMatchingCard(s.thfilter2,p,LOCATION_DECK+LOCATION_GRAVE,0,1,nil) then
		   if Duel.SelectYesNo(p,aux.Stringid(id,1)) then
			  local cg=Duel.SelectMatchingCard(p,s.thfilter2,p,LOCATION_DECK+LOCATION_GRAVE,0,1,1,nil)
			  Duel.SendtoHand(cg,nil,REASON_EFFECT)
			  Duel.ConfirmCards(1-p,cg)
		   end
		end
	end
	Duel.ShuffleDeck(p)
end