name: Odd-Eyes
card_text: This card can be used to Ritual Summon any Dragon Ritual Monster from your hand or GY. You must also Tribute Pendulum Monsters from your hand or field whose total Levels equal or exceed the Level of the Ritual Monster you Ritual Summon. If your opponent controls 2 or more monsters and you control no monsters, you can also send "Odd-Eyes" monsters from your Extra Deck to the GY. You can only activate 1 "Odd-Eyes Advent" per turn.
external_ids: local SETCARD_ID_0 = 0x99 --Odd-Eyes
  
lua: local SETCARD_ID_0 = 0x99 --Odd-Eyes
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	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.operation)
  	c:RegisterEffect(e1)
  end
  function s.exfilter0(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevelAbove(1) and c:IsAbleToGrave()
  end
  function s.filter(c, e, tp)
  	return c:IsRace(RACE_DRAGON)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mg = Duel.GetRitualMaterial(tp):Filter(Card.IsType, nil, TYPE_PENDULUM)
  		local sg = nil
  		if Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 1 then
  			sg = Duel.GetMatchingGroup(s.exfilter0, tp, LOCATION_EXTRA, 0, nil)
  		end
  		return Duel.IsExistingMatchingCard(aux.RitualUltimateFilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil, s.filter, e, tp, mg, sg, Card.GetLevel, "Greater")
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	::cancel::
  	local mg = Duel.GetRitualMaterial(tp):Filter(Card.IsType, nil, TYPE_PENDULUM)
  	local sg = nil
  	if Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 1 then
  		sg = Duel.GetMatchingGroup(s.exfilter0, tp, LOCATION_EXTRA, 0, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tg = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(aux.RitualUltimateFilter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil, s.filter, e, tp, mg, sg, Card.GetLevel, "Greater")
  	local tc = tg:GetFirst()
  	if tc then
  		mg = mg:Filter(Card.IsCanBeRitualMaterial, tc, tc)
  		if sg then
  			mg:Merge(sg)
  		end
  		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 mat2 = mat:Filter(Card.IsLocation, nil, LOCATION_EXTRA)
  		mat:Sub(mat2)
  		Duel.ReleaseRitualMaterial(mat)
  		Duel.SendtoGrave(mat2, REASON_EFFECT + REASON_MATERIAL + REASON_RITUAL)
  		Duel.BreakEffect()
  		Duel.SpecialSummon(tc, SUMMON_TYPE_RITUAL, tp, tp, false, true, POS_FACEUP)
  		tc:CompleteProcedure()
  	end
  end
  
  
source_text: Odd-Eyes
  This card can be used to Ritual Summon any Dragon Ritual Monster from your hand or GY. You must also Tribute Pendulum Monsters from your hand or field whose total Levels equal or exceed the Level of the Ritual Monster you Ritual Summon. If your opponent controls 2 or more monsters and you control no monsters, you can also send "Odd-Eyes" monsters from your Extra Deck to the GY. You can only activate 1 "Odd-Eyes Advent" per turn.
target_text: -- Odd-Eyes
  local SETCARD_ID_0 = 0x99 --Odd-Eyes
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	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.operation)
  	c:RegisterEffect(e1)
  end
  function s.exfilter0(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevelAbove(1) and c:IsAbleToGrave()
  end
  function s.filter(c, e, tp)
  	return c:IsRace(RACE_DRAGON)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mg = Duel.GetRitualMaterial(tp):Filter(Card.IsType, nil, TYPE_PENDULUM)
  		local sg = nil
  		if Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 1 then
  			sg = Duel.GetMatchingGroup(s.exfilter0, tp, LOCATION_EXTRA, 0, nil)
  		end
  		return Duel.IsExistingMatchingCard(aux.RitualUltimateFilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil, s.filter, e, tp, mg, sg, Card.GetLevel, "Greater")
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	::cancel::
  	local mg = Duel.GetRitualMaterial(tp):Filter(Card.IsType, nil, TYPE_PENDULUM)
  	local sg = nil
  	if Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 1 then
  		sg = Duel.GetMatchingGroup(s.exfilter0, tp, LOCATION_EXTRA, 0, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tg = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(aux.RitualUltimateFilter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil, s.filter, e, tp, mg, sg, Card.GetLevel, "Greater")
  	local tc = tg:GetFirst()
  	if tc then
  		mg = mg:Filter(Card.IsCanBeRitualMaterial, tc, tc)
  		if sg then
  			mg:Merge(sg)
  		end
  		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 mat2 = mat:Filter(Card.IsLocation, nil, LOCATION_EXTRA)
  		mat:Sub(mat2)
  		Duel.ReleaseRitualMaterial(mat)
  		Duel.SendtoGrave(mat2, REASON_EFFECT + REASON_MATERIAL + REASON_RITUAL)
  		Duel.BreakEffect()
  		Duel.SpecialSummon(tc, SUMMON_TYPE_RITUAL, tp, tp, false, true, POS_FACEUP)
  		tc:CompleteProcedure()
  	end
  end
  
  