name: Rainbow
card_text: (This card is always treated as an "Ultimate Crystal" card.)
  Cannot be Normal Summoned/Set. Must be Special Summoned (from your hand) by having 7 "Crystal Beast" cards with different names on your field and/or GY. This card cannot activate the following effects the turn it is Special Summoned. (Quick Effect): You can send all "Crystal Beast" monsters you control to the GY; this card gains 1000 ATK for each monster sent to the GY. You can banish all "Crystal Beast" monsters from your GY; shuffle all cards on the field into the Deck.
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)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	c:RegisterEffect(e1)
  	--cannot special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e2)
  	--atkup
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_ATKCHANGE)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetHintTiming(TIMING_DAMAGE_STEP)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.atcon)
  	e3:SetCost(s.atcost)
  	e3:SetOperation(s.atop)
  	c:RegisterEffect(e3)
  	--todeck
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_TODECK)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCondition(s.tdcon)
  	e4:SetCost(s.tdcost)
  	e4:SetTarget(s.tdtg)
  	e4:SetOperation(s.tdop)
  	c:RegisterEffect(e4)
  	--
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e5:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e5:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.spfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and (not c:IsOnField() or c:IsFaceup())
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	if Duel.GetLocationCount(c:GetControler(), LOCATION_MZONE) <= 0 then
  		return false
  	end
  	local g = Duel.GetMatchingGroup(s.spfilter, c:GetControler(), LOCATION_ONFIELD + LOCATION_GRAVE, 0, nil)
  	return g:GetClassCount(Card.GetCode) == 7
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD - RESET_TOFIELD - RESET_TURN_SET + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	return aux.dscon(e, tp, eg, ep, ev, re, r, rp) and e:GetHandler():GetFlagEffect(id) == 0
  end
  function s.afilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGraveAsCost()
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.afilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.afilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetLabel(g:GetCount())
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(e:GetLabel() * 1000)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e1)
  	end
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) == 0
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.tdcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_GRAVE, 0, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  end
  
  
source_text: Rainbow
  (This card is always treated as an "Ultimate Crystal" card.)
  Cannot be Normal Summoned/Set. Must be Special Summoned (from your hand) by having 7 "Crystal Beast" cards with different names on your field and/or GY. This card cannot activate the following effects the turn it is Special Summoned. (Quick Effect): You can send all "Crystal Beast" monsters you control to the GY; this card gains 1000 ATK for each monster sent to the GY. You can banish all "Crystal Beast" monsters from your GY; shuffle all cards on the field into the Deck.
target_text: -- Rainbow
  local SETCARD_ID_0 = 0x1034 --Crystal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	c:RegisterEffect(e1)
  	--cannot special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e2)
  	--atkup
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_ATKCHANGE)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetHintTiming(TIMING_DAMAGE_STEP)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.atcon)
  	e3:SetCost(s.atcost)
  	e3:SetOperation(s.atop)
  	c:RegisterEffect(e3)
  	--todeck
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_TODECK)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCondition(s.tdcon)
  	e4:SetCost(s.tdcost)
  	e4:SetTarget(s.tdtg)
  	e4:SetOperation(s.tdop)
  	c:RegisterEffect(e4)
  	--
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e5:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e5:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.spfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and (not c:IsOnField() or c:IsFaceup())
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	if Duel.GetLocationCount(c:GetControler(), LOCATION_MZONE) <= 0 then
  		return false
  	end
  	local g = Duel.GetMatchingGroup(s.spfilter, c:GetControler(), LOCATION_ONFIELD + LOCATION_GRAVE, 0, nil)
  	return g:GetClassCount(Card.GetCode) == 7
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD - RESET_TOFIELD - RESET_TURN_SET + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	return aux.dscon(e, tp, eg, ep, ev, re, r, rp) and e:GetHandler():GetFlagEffect(id) == 0
  end
  function s.afilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGraveAsCost()
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.afilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.afilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetLabel(g:GetCount())
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(e:GetLabel() * 1000)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e1)
  	end
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) == 0
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.tdcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_GRAVE, 0, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  end
  
  