--复仇死者的对极
function c114514808.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1,114514808) 
	e1:SetTarget(c114514808.target)
	e1:SetOperation(c114514808.activate)
	c:RegisterEffect(e1) 
	--to deck and draw 
	local e2=Effect.CreateEffect(c)
	e2:SetCategory(CATEGORY_TODECK+CATEGORY_DRAW) 
	e2:SetType(EFFECT_TYPE_IGNITION)
	e2:SetProperty(EFFECT_FLAG_CARD_TARGET) 
	e2:SetRange(LOCATION_GRAVE) 
	e2:SetCountLimit(1,214514808) 
	e2:SetCost(aux.bfgcost)  
	e2:SetTarget(c114514808.tddtg)
	e2:SetOperation(c114514808.tddop)
	c:RegisterEffect(e2)
end
function c114514808.thfil(c,sc)
	return c:IsSetCard(0x106) and not c:IsCode(sc:GetCode()) and c:IsAbleToHand()
end
function c114514808.ctfil(c,e,tp)
	return c:IsDiscardable() and c:IsAbleToGraveAsCost() and (c:IsSetCard(0x106) or c:IsRace(RACE_ZOMBIE)) and Duel.IsExistingMatchingCard(c114514808.thfil,tp,LOCATION_DECK,0,1,nil,c)
end
function c114514808.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(c114514808.ctfil,tp,LOCATION_HAND,0,1,nil,e,tp) end 
	local tc=Duel.SelectMatchingCard(tp,c114514808.ctfil,tp,LOCATION_HAND,0,1,1,nil,e,tp):GetFirst() 
	e:SetLabelObject(tc) 
	Duel.SendtoGrave(tc,REASON_COST) 
	Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK)
end
function c114514808.sthfil(c,mc)
	return c:IsType(TYPE_MONSTER) and c:IsType(TYPE_RITUAL) and c:IsAbleToHand() and aux.IsCodeListed(mc,c:GetCode())
end
function c114514808.activate(e,tp,eg,ep,ev,re,r,rp) 
	local c=e:GetHandler() 
	local sc=e:GetLabelObject()  
	if sc==nil then return end 
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
	local tc=Duel.SelectMatchingCard(tp,c114514808.thfil,tp,LOCATION_DECK,0,1,1,nil,sc):GetFirst() 
	if tc then
		Duel.SendtoHand(tc,tp,REASON_EFFECT)
		Duel.ConfirmCards(1-tp,tc) 
		if tc:IsType(TYPE_RITUAL) and tc:IsType(TYPE_SPELL) and Duel.IsExistingMatchingCard(c114514808.sthfil,tp,LOCATION_DECK,0,1,nil,tc) and Duel.SelectYesNo(tp,aux.Stringid(114514808,0)) then 
			local sg=Duel.SelectMatchingCard(tp,c114514808.sthfil,tp,LOCATION_DECK,0,1,1,nil,tc) 
			Duel.SendtoHand(sg,tp,REASON_EFFECT) 
			Duel.ConfirmCards(1-tp,sg)
		end  
	end
end
function c114514808.tdfil(c)
	return not c:IsCode(114514808) and c:IsAbleToDeck() and c:IsType(TYPE_SPELL+TYPE_TRAP) and c:IsSetCard(0x106)
end
function c114514808.tddtg(e,tp,eg,ep,ev,re,r,rp,chk) 
	if chk==0 then return Duel.IsPlayerCanDraw(tp,1) and Duel.IsExistingTarget(c114514808.tdfil,tp,LOCATION_GRAVE+LOCATION_REMOVED,0,5,nil) end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TODECK)
	local g=Duel.SelectTarget(tp,c114514808.tdfil,tp,LOCATION_GRAVE+LOCATION_REMOVED,0,5,5,nil)
	Duel.SetOperationInfo(0,CATEGORY_TODECK,g,5,0,0)
	Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,1)
end
function c114514808.tddop(e,tp,eg,ep,ev,re,r,rp)  
	local c=e:GetHandler()
	local tg=Duel.GetChainInfo(0,CHAININFO_TARGET_CARDS)
	if tg:FilterCount(Card.IsRelateToEffect,nil,e)~=5 then return end
	Duel.SendtoDeck(tg,nil,2,REASON_EFFECT) 
	local g=Duel.GetOperatedGroup()
	if g:IsExists(Card.IsLocation,1,nil,LOCATION_DECK) then Duel.ShuffleDeck(tp) end
	local ct=g:FilterCount(Card.IsLocation,nil,LOCATION_DECK+LOCATION_EXTRA)
	if ct==5 then
		Duel.BreakEffect()
		Duel.Draw(tp,1,REASON_EFFECT)
	end
end