name: Wheel
card_text: When this card is Special Summoned by the effect of a Spellcaster-Type monster: You can target any number of your banished "Spellbook" Spell Cards; shuffle them into the Deck, and if you do, return your other banished "Spellbook" Spell Cards to your Graveyard. You can only use the effect of "Wheel of Prophecy" once per turn.
external_ids: local SETCARD_ID_0 = 0x106e --Spellbook
  
lua: local SETCARD_ID_0 = 0x106e --Spellbook
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.retcon)
  	e1:SetTarget(s.rettg)
  	e1:SetOperation(s.retop)
  	c:RegisterEffect(e1)
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	local typ, race = e:GetHandler():GetSpecialSummonInfo(SUMMON_INFO_TYPE, SUMMON_INFO_RACE)
  	return typ & TYPE_MONSTER ~= 0 and race & RACE_SPELLCASTER ~= 0
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL) and c:IsAbleToDeck()
  end
  function s.rettg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_REMOVED, 0, 1, 99, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.filter2(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL)
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() > 0 then
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  	local g2 = Duel.GetMatchingGroup(s.filter2, tp, LOCATION_REMOVED, 0, nil)
  	if g2:GetCount() > 0 then
  		Duel.SendtoGrave(g2, REASON_EFFECT + REASON_RETURN)
  	end
  end
  
  
source_text: Wheel
  When this card is Special Summoned by the effect of a Spellcaster-Type monster: You can target any number of your banished "Spellbook" Spell Cards; shuffle them into the Deck, and if you do, return your other banished "Spellbook" Spell Cards to your Graveyard. You can only use the effect of "Wheel of Prophecy" once per turn.
target_text: -- Wheel
  local SETCARD_ID_0 = 0x106e --Spellbook
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.retcon)
  	e1:SetTarget(s.rettg)
  	e1:SetOperation(s.retop)
  	c:RegisterEffect(e1)
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	local typ, race = e:GetHandler():GetSpecialSummonInfo(SUMMON_INFO_TYPE, SUMMON_INFO_RACE)
  	return typ & TYPE_MONSTER ~= 0 and race & RACE_SPELLCASTER ~= 0
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL) and c:IsAbleToDeck()
  end
  function s.rettg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_REMOVED, 0, 1, 99, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.filter2(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL)
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() > 0 then
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  	local g2 = Duel.GetMatchingGroup(s.filter2, tp, LOCATION_REMOVED, 0, nil)
  	if g2:GetCount() > 0 then
  		Duel.SendtoGrave(g2, REASON_EFFECT + REASON_RETURN)
  	end
  end
  
  