Seventh
Target 1 "Number" Xyz Monster you control that has a number between "101" and "107" in its name, or 1 Xyz Monster you control that has any such monsters as material, then activate 1 of these effects;
● Negate the effects of 1 monster your opponent controls with ATK less than or equal to the targeted monster's ATK, until the end of this turn.
● Detach all materials from the targeted monster, then you can Special Summon 1 "Number" Xyz Monster from your GY.
You can only use this effect of "Seventh Eternity" once per turn.
local SETCARD_ID_0 = 0x48 --Number

local SETCARD_ID_0 = 0x48 --Number
local s, id, o = GetID()
function s.initial_effect(c)
	--activate
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e1)
	--choose
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_FREE_CHAIN)
	e2:SetRange(LOCATION_SZONE)
	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
	e2:SetCountLimit(1, id)
	e2:SetTarget(s.target)
	e2:SetOperation(s.operation)
	c:RegisterEffect(e2)
end
function s.filter(c)
	local no = aux.GetXyzNumber(c)
	return no and no >= 101 and no <= 107 and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ)
end
function s.cfilter(c)
	if not c:IsType(TYPE_XYZ) then
		return false
	end
	if s.filter(c) then
		return true
	end
	local g = c:GetOverlayGroup()
	return g:IsExists(s.filter, 1, nil)
end
function s.disfilter(c, atk)
	return aux.NegateMonsterFilter(c) and c:IsAttackBelow(atk)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.cfilter(chkc)
	end
	if chk == 0 then
		return Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
	local g = Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
	local tc = g:GetFirst()
	local s = 0
	local b1 = Duel.IsExistingMatchingCard(s.disfilter, tp, 0, LOCATION_MZONE, 1, nil, tc:GetAttack())
	local b2 = tc:GetOverlayGroup():GetCount() > 0
	if b1 and not b2 then
		s = Duel.SelectOption(tp, aux.Stringid(id, 0))
	end
	if not b1 and b2 then
		s = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
	end
	if b1 and b2 then
		s = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
	end
	e:SetLabel(s)
	if s == 0 then
		e:SetCategory(0)
	else
		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
	end
end
function s.operation(e, tp, eg, ep, ev, re, r, rp)
	local s = e:GetLabel()
	local tc = Duel.GetFirstTarget()
	if s == 0 then
		if not tc:IsRelateToEffect(e) or tc:IsFacedown() then
			return
		end
		local sg = Duel.GetMatchingGroup(s.disfilter, tp, 0, LOCATION_MZONE, nil, tc:GetAttack())
		if sg:GetCount() > 0 then
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISABLE)
			local sc = sg:Select(tp, 1, 1, nil):GetFirst()
			if sc and not sc:IsImmuneToEffect(e) then
				Duel.NegateRelatedChain(sc, RESET_TURN_SET)
				local e1 = Effect.CreateEffect(e:GetHandler())
				e1:SetType(EFFECT_TYPE_SINGLE)
				e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
				e1:SetCode(EFFECT_DISABLE)
				e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
				sc:RegisterEffect(e1)
				local e2 = Effect.CreateEffect(e:GetHandler())
				e2:SetType(EFFECT_TYPE_SINGLE)
				e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
				e2:SetCode(EFFECT_DISABLE_EFFECT)
				e2:SetValue(RESET_TURN_SET)
				e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
				sc:RegisterEffect(e2)
			end
		end
	end
	if s == 1 then
		if tc:IsRelateToEffect(e) and not tc:IsImmuneToEffect(e) then
			local og = tc:GetOverlayGroup()
			if
				og:GetCount() > 0
				and Duel.SendtoGrave(og, REASON_EFFECT) > 0
				and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
				and Duel.IsExistingMatchingCard(aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
				and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
			then
				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
				local ng = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
				if ng:GetCount() > 0 then
					Duel.BreakEffect()
					Duel.SpecialSummon(ng, 0, tp, tp, false, false, POS_FACEUP)
				end
			end
		end
	end
end
function s.spfilter(c, e, tp)
	return c:IsType(TYPE_XYZ) and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end


Seventh
Target 1 "Number" Xyz Monster you control that has a number between "101" and "107" in its name, or 1 Xyz Monster you control that has any such monsters as material, then activate 1 of these effects;
● Negate the effects of 1 monster your opponent controls with ATK less than or equal to the targeted monster's ATK, until the end of this turn.
● Detach all materials from the targeted monster, then you can Special Summon 1 "Number" Xyz Monster from your GY.
You can only use this effect of "Seventh Eternity" once per turn.
-- Seventh
local SETCARD_ID_0 = 0x48 --Number
local s, id, o = GetID()
function s.initial_effect(c)
	--activate
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e1)
	--choose
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_FREE_CHAIN)
	e2:SetRange(LOCATION_SZONE)
	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
	e2:SetCountLimit(1, id)
	e2:SetTarget(s.target)
	e2:SetOperation(s.operation)
	c:RegisterEffect(e2)
end
function s.filter(c)
	local no = aux.GetXyzNumber(c)
	return no and no >= 101 and no <= 107 and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ)
end
function s.cfilter(c)
	if not c:IsType(TYPE_XYZ) then
		return false
	end
	if s.filter(c) then
		return true
	end
	local g = c:GetOverlayGroup()
	return g:IsExists(s.filter, 1, nil)
end
function s.disfilter(c, atk)
	return aux.NegateMonsterFilter(c) and c:IsAttackBelow(atk)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.cfilter(chkc)
	end
	if chk == 0 then
		return Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
	local g = Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
	local tc = g:GetFirst()
	local s = 0
	local b1 = Duel.IsExistingMatchingCard(s.disfilter, tp, 0, LOCATION_MZONE, 1, nil, tc:GetAttack())
	local b2 = tc:GetOverlayGroup():GetCount() > 0
	if b1 and not b2 then
		s = Duel.SelectOption(tp, aux.Stringid(id, 0))
	end
	if not b1 and b2 then
		s = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
	end
	if b1 and b2 then
		s = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
	end
	e:SetLabel(s)
	if s == 0 then
		e:SetCategory(0)
	else
		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
	end
end
function s.operation(e, tp, eg, ep, ev, re, r, rp)
	local s = e:GetLabel()
	local tc = Duel.GetFirstTarget()
	if s == 0 then
		if not tc:IsRelateToEffect(e) or tc:IsFacedown() then
			return
		end
		local sg = Duel.GetMatchingGroup(s.disfilter, tp, 0, LOCATION_MZONE, nil, tc:GetAttack())
		if sg:GetCount() > 0 then
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISABLE)
			local sc = sg:Select(tp, 1, 1, nil):GetFirst()
			if sc and not sc:IsImmuneToEffect(e) then
				Duel.NegateRelatedChain(sc, RESET_TURN_SET)
				local e1 = Effect.CreateEffect(e:GetHandler())
				e1:SetType(EFFECT_TYPE_SINGLE)
				e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
				e1:SetCode(EFFECT_DISABLE)
				e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
				sc:RegisterEffect(e1)
				local e2 = Effect.CreateEffect(e:GetHandler())
				e2:SetType(EFFECT_TYPE_SINGLE)
				e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
				e2:SetCode(EFFECT_DISABLE_EFFECT)
				e2:SetValue(RESET_TURN_SET)
				e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
				sc:RegisterEffect(e2)
			end
		end
	end
	if s == 1 then
		if tc:IsRelateToEffect(e) and not tc:IsImmuneToEffect(e) then
			local og = tc:GetOverlayGroup()
			if
				og:GetCount() > 0
				and Duel.SendtoGrave(og, REASON_EFFECT) > 0
				and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
				and Duel.IsExistingMatchingCard(aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
				and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
			then
				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
				local ng = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
				if ng:GetCount() > 0 then
					Duel.BreakEffect()
					Duel.SpecialSummon(ng, 0, tp, tp, false, false, POS_FACEUP)
				end
			end
		end
	end
end
function s.spfilter(c, e, tp)
	return c:IsType(TYPE_XYZ) and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end

