name: Rainbow
card_text: If there are 2 or more different Monster Types among the Level 10 or higher monsters on the field: Shuffle all cards except this one from both players' hands, fields, and GYs into the Deck, then each player draws 5 cards. You can banish this card from your GY; add 1 "Crystal Beast" monster and 1 Field Spell from your Deck to your hand. You can only apply each effect of "Rainbow Bridge of Salvation" once per Duel.
external_ids: local SETCARD_ID_0 = 0x1034 --Crystal
  
lua: local SETCARD_ID_0 = 0x1034 --Crystal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetCondition(s.thcon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLevelAbove(10)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	return Duel.GetFlagEffect(tp, id) == 0 and g:GetClassCount(Card.GetRace) >= 2
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(aux.NOT(Card.IsStatus), tp, 0x1e, 0x1e, nil, STATUS_BATTLE_DESTROYED)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0x1e)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFlagEffect(tp, id) ~= 0 then
  		return
  	end
  	Duel.RegisterFlagEffect(tp, id, 0, 0, 0)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(aux.NOT(Card.IsStatus), tp, 0x1e, 0x1e, aux.ExceptThisCard(e), STATUS_BATTLE_DESTROYED)
  	if aux.NecroValleyNegateCheck(g) then
  		return
  	end
  	if Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) == 0 then
  		return
  	end
  	local tg = Duel.GetOperatedGroup():Filter(Card.IsLocation, nil, LOCATION_DECK)
  	if tg:IsExists(Card.IsControler, 1, nil, tp) then
  		Duel.ShuffleDeck(tp)
  	end
  	if tg:IsExists(Card.IsControler, 1, nil, 1 - tp) then
  		Duel.ShuffleDeck(1 - tp)
  	end
  	Duel.BreakEffect()
  	Duel.Draw(tp, 5, REASON_EFFECT)
  	Duel.Draw(1 - tp, 5, REASON_EFFECT)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id + 1) == 0
  end
  function s.thfilter1(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thfilter2(c)
  	return c:IsType(TYPE_FIELD) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter1, tp, LOCATION_DECK, 0, 1, nil) and Duel.IsExistingMatchingCard(s.thfilter2, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 2, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFlagEffect(tp, id + 1) ~= 0 then
  		return
  	end
  	Duel.RegisterFlagEffect(tp, id + 1, 0, 0, 0)
  	local g1 = Duel.GetMatchingGroup(s.thfilter1, tp, LOCATION_DECK, 0, nil)
  	local g2 = Duel.GetMatchingGroup(s.thfilter2, tp, LOCATION_DECK, 0, nil)
  	if g1:GetCount() > 0 and g2:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg1 = g1:Select(tp, 1, 1, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg2 = g2:Select(tp, 1, 1, nil)
  		sg1:Merge(sg2)
  		Duel.SendtoHand(sg1, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg1)
  	end
  end
  
  
source_text: Rainbow
  If there are 2 or more different Monster Types among the Level 10 or higher monsters on the field: Shuffle all cards except this one from both players' hands, fields, and GYs into the Deck, then each player draws 5 cards. You can banish this card from your GY; add 1 "Crystal Beast" monster and 1 Field Spell from your Deck to your hand. You can only apply each effect of "Rainbow Bridge of Salvation" once per Duel.
target_text: -- Rainbow
  local SETCARD_ID_0 = 0x1034 --Crystal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetCondition(s.thcon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLevelAbove(10)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	return Duel.GetFlagEffect(tp, id) == 0 and g:GetClassCount(Card.GetRace) >= 2
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(aux.NOT(Card.IsStatus), tp, 0x1e, 0x1e, nil, STATUS_BATTLE_DESTROYED)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0x1e)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFlagEffect(tp, id) ~= 0 then
  		return
  	end
  	Duel.RegisterFlagEffect(tp, id, 0, 0, 0)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(aux.NOT(Card.IsStatus), tp, 0x1e, 0x1e, aux.ExceptThisCard(e), STATUS_BATTLE_DESTROYED)
  	if aux.NecroValleyNegateCheck(g) then
  		return
  	end
  	if Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) == 0 then
  		return
  	end
  	local tg = Duel.GetOperatedGroup():Filter(Card.IsLocation, nil, LOCATION_DECK)
  	if tg:IsExists(Card.IsControler, 1, nil, tp) then
  		Duel.ShuffleDeck(tp)
  	end
  	if tg:IsExists(Card.IsControler, 1, nil, 1 - tp) then
  		Duel.ShuffleDeck(1 - tp)
  	end
  	Duel.BreakEffect()
  	Duel.Draw(tp, 5, REASON_EFFECT)
  	Duel.Draw(1 - tp, 5, REASON_EFFECT)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id + 1) == 0
  end
  function s.thfilter1(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thfilter2(c)
  	return c:IsType(TYPE_FIELD) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter1, tp, LOCATION_DECK, 0, 1, nil) and Duel.IsExistingMatchingCard(s.thfilter2, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 2, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFlagEffect(tp, id + 1) ~= 0 then
  		return
  	end
  	Duel.RegisterFlagEffect(tp, id + 1, 0, 0, 0)
  	local g1 = Duel.GetMatchingGroup(s.thfilter1, tp, LOCATION_DECK, 0, nil)
  	local g2 = Duel.GetMatchingGroup(s.thfilter2, tp, LOCATION_DECK, 0, nil)
  	if g1:GetCount() > 0 and g2:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg1 = g1:Select(tp, 1, 1, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg2 = g2:Select(tp, 1, 1, nil)
  		sg1:Merge(sg2)
  		Duel.SendtoHand(sg1, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg1)
  	end
  end
  
  