name: Realm
card_text: Activate 1 of these effects;
  ● Special Summon 1 monster with 1500 ATK/2100 DEF from your GY.
  ● Shuffle into the Deck, 1 of your "Visas Starfrost" and 4 of your monsters with 1500 ATK/2100 DEF, that are banished, in your GY, and/or face-up on your field, and if you do, Special Summon 1 "Visas" Synchro Monster from your Extra Deck. (This is treated as a Synchro Summon.)
  You can only activate 1 "Realm Resonance" per turn.
external_ids: local CARD_ID_0 = 56099748 --Visas Starfrost
  local SETCARD_ID_0 = 0x198 --Visas
  
lua: local CARD_ID_0 = 56099748 --Visas Starfrost
  local SETCARD_ID_0 = 0x198 --Visas
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.spfilter(c, e, tp)
  	return c:IsAttack(1500) and c:IsDefense(2100) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.tdfilter1(c)
  	return c:IsCode(CARD_ID_0)
  end
  function s.tdfilter2(c)
  	return c:IsAttack(1500) and c:IsDefense(2100)
  end
  function s.tdcheck(g, e, tp)
  	if not Duel.IsExistingMatchingCard(s.synfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, g) then
  		return false
  	end
  	local g1 = g:Filter(s.tdfilter1, nil)
  	if #g1 == 1 and g:FilterCount(s.tdfilter2, g1) == 4 then
  		return true
  	end
  	return g:CheckSubGroupEach({ s.tdfilter1, s.tdfilter2, s.tdfilter2, s.tdfilter2, s.tdfilter2 })
  end
  function s.gcheck(g)
  	return #g == 1 or g:IsExists(s.tdfilter1, 1, nil)
  end
  function s.synfilter(c, e, tp, g)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_SYNCHRO, tp, false, false) and (g == nil or Duel.GetLocationCountFromEx(tp, tp, g, c) > 0)
  end
  function s.tdfilter(c)
  	return (s.tdfilter1(c) or s.tdfilter2(c)) and c:IsFaceupEx() and c:IsAbleToDeck()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	if chk == 0 and b1 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_MZONE + LOCATION_GRAVE + LOCATION_REMOVED, 0, nil)
  	aux.GCheckAdditional = s.gcheck
  	local b2 = Duel.IsExistingMatchingCard(s.synfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, nil) and g:CheckSubGroup(s.tdcheck, 5, 5, e, tp)
  	aux.GCheckAdditional = nil
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	e:SetLabel(op)
  	if op == 0 then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  	else
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TODECK)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  		Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 5, tp, LOCATION_MZONE + LOCATION_GRAVE + LOCATION_REMOVED)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	else
  		local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.tdfilter), tp, LOCATION_MZONE + LOCATION_GRAVE + LOCATION_REMOVED, 0, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local sg = g:SelectSubGroup(tp, s.tdcheck, false, 5, 5, e, tp)
  		if sg then
  			Duel.HintSelection(sg)
  			if Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 then
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local tg = Duel.SelectMatchingCard(tp, s.synfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, nil)
  				local tc = tg:GetFirst()
  				if tc then
  					Duel.SpecialSummon(tc, SUMMON_TYPE_SYNCHRO, tp, tp, false, false, POS_FACEUP)
  					tc:CompleteProcedure()
  				end
  			end
  		end
  	end
  end
  
  
source_text: Realm
  Activate 1 of these effects;
  ● Special Summon 1 monster with 1500 ATK/2100 DEF from your GY.
  ● Shuffle into the Deck, 1 of your "Visas Starfrost" and 4 of your monsters with 1500 ATK/2100 DEF, that are banished, in your GY, and/or face-up on your field, and if you do, Special Summon 1 "Visas" Synchro Monster from your Extra Deck. (This is treated as a Synchro Summon.)
  You can only activate 1 "Realm Resonance" per turn.
target_text: -- Realm
  local CARD_ID_0 = 56099748 --Visas Starfrost
  local SETCARD_ID_0 = 0x198 --Visas
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.spfilter(c, e, tp)
  	return c:IsAttack(1500) and c:IsDefense(2100) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.tdfilter1(c)
  	return c:IsCode(CARD_ID_0)
  end
  function s.tdfilter2(c)
  	return c:IsAttack(1500) and c:IsDefense(2100)
  end
  function s.tdcheck(g, e, tp)
  	if not Duel.IsExistingMatchingCard(s.synfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, g) then
  		return false
  	end
  	local g1 = g:Filter(s.tdfilter1, nil)
  	if #g1 == 1 and g:FilterCount(s.tdfilter2, g1) == 4 then
  		return true
  	end
  	return g:CheckSubGroupEach({ s.tdfilter1, s.tdfilter2, s.tdfilter2, s.tdfilter2, s.tdfilter2 })
  end
  function s.gcheck(g)
  	return #g == 1 or g:IsExists(s.tdfilter1, 1, nil)
  end
  function s.synfilter(c, e, tp, g)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_SYNCHRO, tp, false, false) and (g == nil or Duel.GetLocationCountFromEx(tp, tp, g, c) > 0)
  end
  function s.tdfilter(c)
  	return (s.tdfilter1(c) or s.tdfilter2(c)) and c:IsFaceupEx() and c:IsAbleToDeck()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	if chk == 0 and b1 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_MZONE + LOCATION_GRAVE + LOCATION_REMOVED, 0, nil)
  	aux.GCheckAdditional = s.gcheck
  	local b2 = Duel.IsExistingMatchingCard(s.synfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, nil) and g:CheckSubGroup(s.tdcheck, 5, 5, e, tp)
  	aux.GCheckAdditional = nil
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	e:SetLabel(op)
  	if op == 0 then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  	else
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TODECK)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  		Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 5, tp, LOCATION_MZONE + LOCATION_GRAVE + LOCATION_REMOVED)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	else
  		local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.tdfilter), tp, LOCATION_MZONE + LOCATION_GRAVE + LOCATION_REMOVED, 0, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local sg = g:SelectSubGroup(tp, s.tdcheck, false, 5, 5, e, tp)
  		if sg then
  			Duel.HintSelection(sg)
  			if Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 then
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local tg = Duel.SelectMatchingCard(tp, s.synfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, nil)
  				local tc = tg:GetFirst()
  				if tc then
  					Duel.SpecialSummon(tc, SUMMON_TYPE_SYNCHRO, tp, tp, false, false, POS_FACEUP)
  					tc:CompleteProcedure()
  				end
  			end
  		end
  	end
  end
  
  