name: メタバース
card_text: 1:デッキからフィールド魔法カード1枚を選び、手札に加えるか自分フィールドに発動する。
external_ids: local CARD_ID_0 = 4179255 --妖精竜 エンシェント
  local CARD_ID_1 = 15248873 --ポップルアップ
  
lua: local CARD_ID_0 = 4179255 --妖精竜 エンシェント
  local CARD_ID_1 = 15248873 --ポップルアップ
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, tp)
  	return c:IsType(TYPE_FIELD) and (c:IsAbleToHand() or c:GetActivateEffect():IsActivatable(tp, true, true))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	if not Duel.CheckPhaseActivity() then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	if e:GetLabel() == 1 then
  		Duel.RegisterFlagEffect(tp, CARD_ID_1, RESET_CHAIN, 0, 1)
  	end
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	Duel.ResetFlagEffect(tp, CARD_ID_1)
  	local tc = g:GetFirst()
  	if tc then
  		local te = tc:GetActivateEffect()
  		local b1 = tc:IsAbleToHand()
  		if e:GetLabel() == 1 then
  			Duel.RegisterFlagEffect(tp, CARD_ID_1, RESET_CHAIN, 0, 1)
  		end
  		local b2 = te:IsActivatable(tp, true, true)
  		Duel.ResetFlagEffect(tp, CARD_ID_1)
  		if b1 and (not b2 or Duel.SelectOption(tp, 1190, 1150) == 0) then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, tc)
  		else
  			local fc = Duel.GetFieldCard(tp, LOCATION_FZONE, 0)
  			if fc then
  				Duel.SendtoGrave(fc, REASON_RULE)
  				Duel.BreakEffect()
  			end
  			Duel.MoveToField(tc, tp, tp, LOCATION_FZONE, POS_FACEUP, true)
  			te:UseCountLimit(tp, 1, true)
  			local tep = tc:GetControler()
  			local cost = te:GetCost()
  			if cost then
  				cost(te, tep, eg, ep, ev, re, r, rp, 1)
  			end
  			Duel.RaiseEvent(tc, CARD_ID_0, te, 0, tp, tp, Duel.GetCurrentChain())
  		end
  	end
  end
  
  
source_text: メタバース
  1:デッキからフィールド魔法カード1枚を選び、手札に加えるか自分フィールドに発動する。
target_text: -- メタバース
  local CARD_ID_0 = 4179255 --妖精竜 エンシェント
  local CARD_ID_1 = 15248873 --ポップルアップ
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, tp)
  	return c:IsType(TYPE_FIELD) and (c:IsAbleToHand() or c:GetActivateEffect():IsActivatable(tp, true, true))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	if not Duel.CheckPhaseActivity() then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	if e:GetLabel() == 1 then
  		Duel.RegisterFlagEffect(tp, CARD_ID_1, RESET_CHAIN, 0, 1)
  	end
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	Duel.ResetFlagEffect(tp, CARD_ID_1)
  	local tc = g:GetFirst()
  	if tc then
  		local te = tc:GetActivateEffect()
  		local b1 = tc:IsAbleToHand()
  		if e:GetLabel() == 1 then
  			Duel.RegisterFlagEffect(tp, CARD_ID_1, RESET_CHAIN, 0, 1)
  		end
  		local b2 = te:IsActivatable(tp, true, true)
  		Duel.ResetFlagEffect(tp, CARD_ID_1)
  		if b1 and (not b2 or Duel.SelectOption(tp, 1190, 1150) == 0) then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, tc)
  		else
  			local fc = Duel.GetFieldCard(tp, LOCATION_FZONE, 0)
  			if fc then
  				Duel.SendtoGrave(fc, REASON_RULE)
  				Duel.BreakEffect()
  			end
  			Duel.MoveToField(tc, tp, tp, LOCATION_FZONE, POS_FACEUP, true)
  			te:UseCountLimit(tp, 1, true)
  			local tep = tc:GetControler()
  			local cost = te:GetCost()
  			if cost then
  				cost(te, tep, eg, ep, ev, re, r, rp, 1)
  			end
  			Duel.RaiseEvent(tc, CARD_ID_0, te, 0, tp, tp, Duel.GetCurrentChain())
  		end
  	end
  end
  
  