name: Dream
card_text: If you control a "Dream Mirror" monster: Target 1 each of your banished "Dream Mirror of Joy" and "Dream Mirror of Terror"; shuffle them into the Deck, and if you do, banish 1 card on the field. If a "Dream Mirror" card(s) you control would be destroyed by battle or card effect, you can banish this card from your GY instead. You can only activate 1 "Dream Mirror Fantasy" per turn.
external_ids: local CARD_ID_0 = 74665651 --Dream Mirror of Joy
  local CARD_ID_1 = 1050355 --Dream Mirror of Terror
  local SETCARD_ID_0 = 0x131 --Dream
  
lua: local CARD_ID_0 = 74665651 --Dream Mirror of Joy
  local CARD_ID_1 = 1050355 --Dream Mirror of Terror
  local SETCARD_ID_0 = 0x131 --Dream
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0, CARD_ID_1)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.filter1(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_0) and c:IsAbleToDeck()
  end
  function s.filter2(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_1) and c:IsAbleToDeck()
  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.IsExistingTarget(s.filter1, tp, LOCATION_REMOVED, 0, 1, nil)
  			and Duel.IsExistingTarget(s.filter2, tp, LOCATION_REMOVED, 0, 1, nil)
  			and Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g1 = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g2 = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	g1:Merge(g2)
  	local g3 = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g1, 2, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g3, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local sg = Duel.SelectMatchingCard(tp, Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, aux.ExceptThisCard(e))
  		if sg:GetCount() > 0 then
  			Duel.HintSelection(sg)
  			Duel.Remove(sg, POS_FACEUP, REASON_EFFECT)
  		end
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsOnField() and c:IsControler(tp) and c:IsReason(REASON_EFFECT + REASON_BATTLE) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  
source_text: Dream
  If you control a "Dream Mirror" monster: Target 1 each of your banished "Dream Mirror of Joy" and "Dream Mirror of Terror"; shuffle them into the Deck, and if you do, banish 1 card on the field. If a "Dream Mirror" card(s) you control would be destroyed by battle or card effect, you can banish this card from your GY instead. You can only activate 1 "Dream Mirror Fantasy" per turn.
target_text: -- Dream
  local CARD_ID_0 = 74665651 --Dream Mirror of Joy
  local CARD_ID_1 = 1050355 --Dream Mirror of Terror
  local SETCARD_ID_0 = 0x131 --Dream
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0, CARD_ID_1)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.filter1(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_0) and c:IsAbleToDeck()
  end
  function s.filter2(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_1) and c:IsAbleToDeck()
  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.IsExistingTarget(s.filter1, tp, LOCATION_REMOVED, 0, 1, nil)
  			and Duel.IsExistingTarget(s.filter2, tp, LOCATION_REMOVED, 0, 1, nil)
  			and Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g1 = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g2 = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	g1:Merge(g2)
  	local g3 = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g1, 2, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g3, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local sg = Duel.SelectMatchingCard(tp, Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, aux.ExceptThisCard(e))
  		if sg:GetCount() > 0 then
  			Duel.HintSelection(sg)
  			Duel.Remove(sg, POS_FACEUP, REASON_EFFECT)
  		end
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsOnField() and c:IsControler(tp) and c:IsReason(REASON_EFFECT + REASON_BATTLE) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  