name: Dimension
card_text: If this card is Normal or Special Summoned: You can add 1 "Magical Dimension" from your Deck or GY to your hand. If this card is sent from the Monster Zone to the GY: You can draw cards equal to the number of Spellcaster monsters you control, then place cards from your hand on top of your Deck in any order, equal to the number of cards you drew. You can only use each effect of "Dimension Conjurer" once per turn.
external_ids: local CARD_ID_0 = 28553439 --Magical Dimension
  
lua: local CARD_ID_0 = 28553439 --Magical Dimension
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--draw
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DRAW + CATEGORY_TODECK)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.drcon)
  	e3:SetTarget(s.drtg)
  	e3:SetOperation(s.drop)
  	c:RegisterEffect(e3)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_MZONE)
  end
  function s.drfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_SPELLCASTER)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(s.drfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return ct > 0 and Duel.IsPlayerCanDraw(tp, ct)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(ct)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, ct)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 0, tp, ct)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local ct = Duel.GetMatchingGroupCount(s.drfilter, p, LOCATION_MZONE, 0, nil)
  	if ct > 0 and Duel.Draw(p, ct, REASON_EFFECT) == ct then
  		local tg = Duel.GetMatchingGroup(Card.IsAbleToDeck, p, LOCATION_HAND, 0, nil)
  		if tg:GetCount() == 0 then
  			return
  		end
  		Duel.ShuffleHand(p)
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, p, HINTMSG_TODECK)
  		local sg = tg:Select(p, ct, ct, nil)
  		aux.PlaceCardsOnDeckTop(p, sg)
  	end
  end
  
  
source_text: Dimension
  If this card is Normal or Special Summoned: You can add 1 "Magical Dimension" from your Deck or GY to your hand. If this card is sent from the Monster Zone to the GY: You can draw cards equal to the number of Spellcaster monsters you control, then place cards from your hand on top of your Deck in any order, equal to the number of cards you drew. You can only use each effect of "Dimension Conjurer" once per turn.
target_text: -- Dimension
  local CARD_ID_0 = 28553439 --Magical Dimension
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--draw
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DRAW + CATEGORY_TODECK)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.drcon)
  	e3:SetTarget(s.drtg)
  	e3:SetOperation(s.drop)
  	c:RegisterEffect(e3)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_MZONE)
  end
  function s.drfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_SPELLCASTER)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(s.drfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return ct > 0 and Duel.IsPlayerCanDraw(tp, ct)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(ct)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, ct)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 0, tp, ct)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local ct = Duel.GetMatchingGroupCount(s.drfilter, p, LOCATION_MZONE, 0, nil)
  	if ct > 0 and Duel.Draw(p, ct, REASON_EFFECT) == ct then
  		local tg = Duel.GetMatchingGroup(Card.IsAbleToDeck, p, LOCATION_HAND, 0, nil)
  		if tg:GetCount() == 0 then
  			return
  		end
  		Duel.ShuffleHand(p)
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, p, HINTMSG_TODECK)
  		local sg = tg:Select(p, ct, ct, nil)
  		aux.PlaceCardsOnDeckTop(p, sg)
  	end
  end
  
  