name: Witchcrafter
card_text: You can target 1 of your Spellcaster monsters that is banished or in your GY; shuffle it into the Deck, and if you do, add 1 "Witchcrafter" Spell from your Deck to your hand. If this card is in your GY, except the turn it was sent there: You can banish this card, then target any number of your banished "Witchcrafter" Spells with different names; add them to your hand. You can only use each effect of "Witchcrafter Patronus" once per turn.
external_ids: local SETCARD_ID_0 = 0x128 --Witchcrafter
  
lua: local SETCARD_ID_0 = 0x128 --Witchcrafter
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.srtg)
  	e2:SetOperation(s.srop)
  	c:RegisterEffect(e2)
  	--to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetHintTiming(0, TIMING_END_PHASE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(aux.exccon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.tdfilter(c)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsRace(RACE_SPELLCASTER) and c:IsAbleToDeck()
  end
  function s.srfilter(c)
  	return c:IsType(TYPE_SPELL) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.srtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and chkc:IsControler(tp) and s.tdfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil) and Duel.IsExistingMatchingCard(s.srfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.srop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoDeck(tc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_DECK + LOCATION_EXTRA) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.srfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_REMOVED, 0, nil):Filter(Card.IsCanBeEffectTarget, nil, e)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local tg = g:SelectSubGroup(tp, aux.dncheck, false, 1, g:GetCount())
  	Duel.SetTargetCard(tg)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, tg, tg:GetCount(), 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 then
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Witchcrafter
  You can target 1 of your Spellcaster monsters that is banished or in your GY; shuffle it into the Deck, and if you do, add 1 "Witchcrafter" Spell from your Deck to your hand. If this card is in your GY, except the turn it was sent there: You can banish this card, then target any number of your banished "Witchcrafter" Spells with different names; add them to your hand. You can only use each effect of "Witchcrafter Patronus" once per turn.
target_text: -- Witchcrafter
  local SETCARD_ID_0 = 0x128 --Witchcrafter
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.srtg)
  	e2:SetOperation(s.srop)
  	c:RegisterEffect(e2)
  	--to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetHintTiming(0, TIMING_END_PHASE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(aux.exccon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.tdfilter(c)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsRace(RACE_SPELLCASTER) and c:IsAbleToDeck()
  end
  function s.srfilter(c)
  	return c:IsType(TYPE_SPELL) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.srtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and chkc:IsControler(tp) and s.tdfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil) and Duel.IsExistingMatchingCard(s.srfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.srop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoDeck(tc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_DECK + LOCATION_EXTRA) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.srfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_REMOVED, 0, nil):Filter(Card.IsCanBeEffectTarget, nil, e)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local tg = g:SelectSubGroup(tp, aux.dncheck, false, 1, g:GetCount())
  	Duel.SetTargetCard(tg)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, tg, tg:GetCount(), 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 then
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  	end
  end
  
  