name: Vendread
card_text: Discard 1 card, then target 1 "Vendread" monster and 1 Ritual Spell in your GY; Special Summon that monster in Defense Position, and if you do, add that Ritual Spell to your hand. You can banish this card from your GY, then target 5 of your banished Zombie monsters; shuffle them into your Deck, then draw 1 card. You can only use each effect of "Vendread Revolution" once per turn.
external_ids: local SETCARD_ID_0 = 0x106 --Vendread
  
lua: local SETCARD_ID_0 = 0x106 --Vendread
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.thfilter(c)
  	return c:GetType() == TYPE_SPELL + TYPE_RITUAL and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  			and Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	e:SetLabelObject(g1:GetFirst())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g2 = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g1, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g2, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc1, tc2 = Duel.GetFirstTarget()
  	if tc1 ~= e:GetLabelObject() then
  		tc1, tc2 = tc2, tc1
  	end
  	if tc1:IsRelateToEffect(e) and Duel.SpecialSummon(tc1, 0, tp, tp, false, false, POS_FACEUP_DEFENSE) ~= 0 and tc2:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc2, nil, REASON_EFFECT)
  	end
  end
  function s.drfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_ZOMBIE) and c:IsAbleToDeck()
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.drfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1) and Duel.IsExistingTarget(s.drfilter, tp, LOCATION_REMOVED, 0, 5, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.drfilter, tp, 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 s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	if not tg or tg:FilterCount(Card.IsRelateToEffect, nil, e) <= 0 then
  		return
  	end
  	Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, 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 > 0 then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  
  
source_text: Vendread
  Discard 1 card, then target 1 "Vendread" monster and 1 Ritual Spell in your GY; Special Summon that monster in Defense Position, and if you do, add that Ritual Spell to your hand. You can banish this card from your GY, then target 5 of your banished Zombie monsters; shuffle them into your Deck, then draw 1 card. You can only use each effect of "Vendread Revolution" once per turn.
target_text: -- Vendread
  local SETCARD_ID_0 = 0x106 --Vendread
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.thfilter(c)
  	return c:GetType() == TYPE_SPELL + TYPE_RITUAL and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  			and Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	e:SetLabelObject(g1:GetFirst())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g2 = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g1, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g2, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc1, tc2 = Duel.GetFirstTarget()
  	if tc1 ~= e:GetLabelObject() then
  		tc1, tc2 = tc2, tc1
  	end
  	if tc1:IsRelateToEffect(e) and Duel.SpecialSummon(tc1, 0, tp, tp, false, false, POS_FACEUP_DEFENSE) ~= 0 and tc2:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc2, nil, REASON_EFFECT)
  	end
  end
  function s.drfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_ZOMBIE) and c:IsAbleToDeck()
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.drfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1) and Duel.IsExistingTarget(s.drfilter, tp, LOCATION_REMOVED, 0, 5, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.drfilter, tp, 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 s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	if not tg or tg:FilterCount(Card.IsRelateToEffect, nil, e) <= 0 then
  		return
  	end
  	Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, 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 > 0 then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  
  