name: Sonic
card_text: This card is used to Ritual Summon "Transonic Bird". You must also Tribute monsters from your hand or field whose total Levels equal 4 or more. The Level of the monster Special Summoned by this effect becomes the total Levels of monsters used for its Ritual Summon. You can banish this card from your GY, then target 1 Ritual Monster you control; send 1 Ritual Monster with the same Type or Attribute from your Deck to the GY. You can only use this effect of "Sonic Tracker" once per turn.
external_ids: local CARD_ID_0 = 34072799 --Transonic Bird
  
lua: local CARD_ID_0 = 34072799 --Transonic Bird
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to grave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOGRAVE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCost(aux.bfgcost)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tgtg)
  	e2:SetOperation(s.tgop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsCode(CARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mg = Duel.GetRitualMaterial(tp)
  		return Duel.IsExistingMatchingCard(aux.RitualUltimateFilter, tp, LOCATION_HAND, 0, 1, nil, s.filter, e, tp, mg, nil, Card.GetLevel, "Greater")
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	::cancel::
  	local mg = Duel.GetRitualMaterial(tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tg = Duel.SelectMatchingCard(tp, aux.RitualUltimateFilter, tp, LOCATION_HAND, 0, 1, 1, nil, s.filter, e, tp, mg, nil, Card.GetLevel, "Greater")
  	local tc = tg:GetFirst()
  	if tc then
  		mg = mg:Filter(Card.IsCanBeRitualMaterial, tc, tc)
  		if tc.mat_filter then
  			mg = mg:Filter(tc.mat_filter, tc, tp)
  		else
  			mg:RemoveCard(tc)
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
  		aux.GCheckAdditional = aux.RitualCheckAdditional(tc, tc:GetLevel(), "Greater")
  		local mat = mg:SelectSubGroup(tp, aux.RitualCheck, true, 1, tc:GetLevel(), tp, tc, tc:GetLevel(), "Greater")
  		aux.GCheckAdditional = nil
  		if not mat then
  			goto cancel
  		end
  		tc:SetMaterial(mat)
  		local lv = mat:GetSum(Card.GetLevel)
  		Duel.ReleaseRitualMaterial(mat)
  		Duel.BreakEffect()
  		if Duel.SpecialSummonStep(tc, SUMMON_TYPE_RITUAL, tp, tp, false, true, POS_FACEUP) then
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  			e1:SetRange(LOCATION_MZONE)
  			e1:SetCode(EFFECT_CHANGE_LEVEL)
  			e1:SetValue(lv)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			tc:CompleteProcedure()
  		end
  		Duel.SpecialSummonComplete()
  	end
  end
  function s.checkfilter(c, tp)
  	local att = c:GetAttribute()
  	local race = c:GetRace()
  	return c:IsFaceup() and bit.band(c:GetType(), 0x81) == 0x81 and Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil, att, race)
  end
  function s.tgfilter(c, att, race)
  	return bit.band(c:GetType(), 0x81) == 0x81 and (c:IsAttribute(att) or c:IsRace(race)) and c:IsAbleToGrave()
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.checkfilter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.checkfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.checkfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local att = tc:GetAttribute()
  		local race = tc:GetRace()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil, att, race)
  		if g:GetCount() > 0 then
  			Duel.SendtoGrave(g, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Sonic
  This card is used to Ritual Summon "Transonic Bird". You must also Tribute monsters from your hand or field whose total Levels equal 4 or more. The Level of the monster Special Summoned by this effect becomes the total Levels of monsters used for its Ritual Summon. You can banish this card from your GY, then target 1 Ritual Monster you control; send 1 Ritual Monster with the same Type or Attribute from your Deck to the GY. You can only use this effect of "Sonic Tracker" once per turn.
target_text: -- Sonic
  local CARD_ID_0 = 34072799 --Transonic Bird
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to grave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOGRAVE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCost(aux.bfgcost)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tgtg)
  	e2:SetOperation(s.tgop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsCode(CARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mg = Duel.GetRitualMaterial(tp)
  		return Duel.IsExistingMatchingCard(aux.RitualUltimateFilter, tp, LOCATION_HAND, 0, 1, nil, s.filter, e, tp, mg, nil, Card.GetLevel, "Greater")
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	::cancel::
  	local mg = Duel.GetRitualMaterial(tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tg = Duel.SelectMatchingCard(tp, aux.RitualUltimateFilter, tp, LOCATION_HAND, 0, 1, 1, nil, s.filter, e, tp, mg, nil, Card.GetLevel, "Greater")
  	local tc = tg:GetFirst()
  	if tc then
  		mg = mg:Filter(Card.IsCanBeRitualMaterial, tc, tc)
  		if tc.mat_filter then
  			mg = mg:Filter(tc.mat_filter, tc, tp)
  		else
  			mg:RemoveCard(tc)
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
  		aux.GCheckAdditional = aux.RitualCheckAdditional(tc, tc:GetLevel(), "Greater")
  		local mat = mg:SelectSubGroup(tp, aux.RitualCheck, true, 1, tc:GetLevel(), tp, tc, tc:GetLevel(), "Greater")
  		aux.GCheckAdditional = nil
  		if not mat then
  			goto cancel
  		end
  		tc:SetMaterial(mat)
  		local lv = mat:GetSum(Card.GetLevel)
  		Duel.ReleaseRitualMaterial(mat)
  		Duel.BreakEffect()
  		if Duel.SpecialSummonStep(tc, SUMMON_TYPE_RITUAL, tp, tp, false, true, POS_FACEUP) then
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  			e1:SetRange(LOCATION_MZONE)
  			e1:SetCode(EFFECT_CHANGE_LEVEL)
  			e1:SetValue(lv)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			tc:CompleteProcedure()
  		end
  		Duel.SpecialSummonComplete()
  	end
  end
  function s.checkfilter(c, tp)
  	local att = c:GetAttribute()
  	local race = c:GetRace()
  	return c:IsFaceup() and bit.band(c:GetType(), 0x81) == 0x81 and Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil, att, race)
  end
  function s.tgfilter(c, att, race)
  	return bit.band(c:GetType(), 0x81) == 0x81 and (c:IsAttribute(att) or c:IsRace(race)) and c:IsAbleToGrave()
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.checkfilter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.checkfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.checkfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local att = tc:GetAttribute()
  		local race = tc:GetRace()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil, att, race)
  		if g:GetCount() > 0 then
  			Duel.SendtoGrave(g, REASON_EFFECT)
  		end
  	end
  end
  
  