name: 異次元隔離マシーン
card_text: 自分と相手のフィールド上からモンスターを1体ずつ選択し、ゲームから除外する。
  このカードが破壊され墓地へ送られた時、除外したモンスターを同じ表示形式で元のフィールド上に戻す。
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--remove
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--return
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.retcon)
  	e2:SetOperation(s.retop)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  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(Card.IsAbleToRemove, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingTarget(Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g1 = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g2 = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	g1:Merge(g2)
  	if e:GetLabelObject() then
  		e:GetLabelObject():DeleteGroup()
  		e:SetLabelObject(nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g1, 2, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if Duel.Remove(tg, 0, REASON_EFFECT + REASON_TEMPORARY) ~= 0 then
  		local g = Duel.GetOperatedGroup()
  		local tc = g:GetFirst()
  		while tc do
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  			tc = g:GetNext()
  		end
  		c:RegisterFlagEffect(id, RESET_EVENT + 0x17a0000, 0, 1)
  		g:KeepAlive()
  		e:SetLabelObject(g)
  	end
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0 and bit.band(r, REASON_DESTROY) ~= 0 and e:GetLabelObject():GetLabelObject() ~= nil
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject():GetLabelObject()
  	local tc = g:GetFirst()
  	while tc do
  		if tc:GetFlagEffect(id) > 0 then
  			Duel.ReturnToField(tc)
  		end
  		tc = g:GetNext()
  	end
  	g:DeleteGroup()
  	e:GetLabelObject():SetLabelObject(nil)
  end
  
  
source_text: 異次元隔離マシーン
  自分と相手のフィールド上からモンスターを1体ずつ選択し、ゲームから除外する。
  このカードが破壊され墓地へ送られた時、除外したモンスターを同じ表示形式で元のフィールド上に戻す。
target_text: -- 異次元隔離マシーン
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--remove
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--return
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.retcon)
  	e2:SetOperation(s.retop)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  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(Card.IsAbleToRemove, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingTarget(Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g1 = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g2 = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	g1:Merge(g2)
  	if e:GetLabelObject() then
  		e:GetLabelObject():DeleteGroup()
  		e:SetLabelObject(nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g1, 2, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if Duel.Remove(tg, 0, REASON_EFFECT + REASON_TEMPORARY) ~= 0 then
  		local g = Duel.GetOperatedGroup()
  		local tc = g:GetFirst()
  		while tc do
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  			tc = g:GetNext()
  		end
  		c:RegisterFlagEffect(id, RESET_EVENT + 0x17a0000, 0, 1)
  		g:KeepAlive()
  		e:SetLabelObject(g)
  	end
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0 and bit.band(r, REASON_DESTROY) ~= 0 and e:GetLabelObject():GetLabelObject() ~= nil
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject():GetLabelObject()
  	local tc = g:GetFirst()
  	while tc do
  		if tc:GetFlagEffect(id) > 0 then
  			Duel.ReturnToField(tc)
  		end
  		tc = g:GetNext()
  	end
  	g:DeleteGroup()
  	e:GetLabelObject():SetLabelObject(nil)
  end
  
  