name: Brionac,
card_text: 1 Tuner + 1+ non-Tuner monsters
  You can discard any number of cards to the GY, then target the same number of cards your opponent controls; return those cards to the hand. You can only use this effect of "Brionac, Dragon of the Ice Barrier" once per turn.
external_ids: local CARD_ID_0 = 18319762 --Revealer of the Ice Barrier
  local SETCARD_ID_0 = 0x2f --Ice
  
lua: local CARD_ID_0 = 18319762 --Revealer of the Ice Barrier
  local SETCARD_ID_0 = 0x2f --Ice
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.costfilter(c, e, tp)
  	if c:IsLocation(LOCATION_HAND) then
  		return c:IsDiscardable() and c:IsAbleToGraveAsCost()
  	else
  		return e:GetHandler():IsSetCard(SETCARD_ID_0) and c:IsAbleToRemove() and c:IsHasEffect(CARD_ID_0, tp)
  	end
  end
  function s.fselect(g)
  	return g:FilterCount(Card.IsLocation, nil, LOCATION_GRAVE) <= 1
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	local rt = Duel.GetTargetCount(Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, nil)
  	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, nil, e, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISCARD)
  	local cg = g:SelectSubGroup(tp, s.fselect, false, 1, rt)
  	e:SetLabel(cg:GetCount())
  	local tc = cg:Filter(Card.IsLocation, nil, LOCATION_GRAVE):GetFirst()
  	if tc then
  		local te = tc:IsHasEffect(CARD_ID_0, tp)
  		te:UseCountLimit(tp)
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  		cg:RemoveCard(tc)
  	end
  	Duel.SendtoGrave(cg, REASON_COST + REASON_DISCARD)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and chkc:IsAbleToHand()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	local ct = e:GetLabel()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local tg = Duel.SelectTarget(tp, Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, ct, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, tg, ct, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local rg = tg:Filter(Card.IsRelateToEffect, nil, e)
  	if rg:GetCount() > 0 then
  		Duel.SendtoHand(rg, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Brionac,
  1 Tuner + 1+ non-Tuner monsters
  You can discard any number of cards to the GY, then target the same number of cards your opponent controls; return those cards to the hand. You can only use this effect of "Brionac, Dragon of the Ice Barrier" once per turn.
target_text: -- Brionac,
  local CARD_ID_0 = 18319762 --Revealer of the Ice Barrier
  local SETCARD_ID_0 = 0x2f --Ice
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.costfilter(c, e, tp)
  	if c:IsLocation(LOCATION_HAND) then
  		return c:IsDiscardable() and c:IsAbleToGraveAsCost()
  	else
  		return e:GetHandler():IsSetCard(SETCARD_ID_0) and c:IsAbleToRemove() and c:IsHasEffect(CARD_ID_0, tp)
  	end
  end
  function s.fselect(g)
  	return g:FilterCount(Card.IsLocation, nil, LOCATION_GRAVE) <= 1
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	local rt = Duel.GetTargetCount(Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, nil)
  	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, nil, e, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISCARD)
  	local cg = g:SelectSubGroup(tp, s.fselect, false, 1, rt)
  	e:SetLabel(cg:GetCount())
  	local tc = cg:Filter(Card.IsLocation, nil, LOCATION_GRAVE):GetFirst()
  	if tc then
  		local te = tc:IsHasEffect(CARD_ID_0, tp)
  		te:UseCountLimit(tp)
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  		cg:RemoveCard(tc)
  	end
  	Duel.SendtoGrave(cg, REASON_COST + REASON_DISCARD)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and chkc:IsAbleToHand()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	local ct = e:GetLabel()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local tg = Duel.SelectTarget(tp, Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, ct, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, tg, ct, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local rg = tg:Filter(Card.IsRelateToEffect, nil, e)
  	if rg:GetCount() > 0 then
  		Duel.SendtoHand(rg, nil, REASON_EFFECT)
  	end
  end
  
  