name: Rebirth
card_text: Tribute all Xyz Monsters you control, then target 1 of your banished Xyz Monsters; Special Summon it, then you can attach your "Number" Xyz Monsters that are banished and/or in your GY to it as material, that have a number between "101" and "107" in their name, up to the number of monsters Tributed to activate this effect +1. During the End Phase of the turn you activated this card, each player takes 300 damage for each card in their hand.
lua: 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:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_XYZ) and c:IsFaceup()
  end
  function s.filter(c)
  	return c:IsReleasable() and not c:IsStatus(STATUS_BATTLE_DESTROYED)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return g:GetCount() > 0 and g:FilterCount(s.filter, nil) == g:GetCount() and Duel.GetMZoneCount(tp, g) > 0
  	end
  	e:SetLabel(g:GetCount())
  	Duel.Release(g, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:IsType(TYPE_XYZ) and c:IsFaceup() and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		if e:GetLabel() == 100 then
  			e:SetLabel(0)
  			return Duel.IsExistingTarget(s.spfilter, tp, LOCATION_REMOVED, 0, 1, nil, e, tp)
  		else
  			return false
  		end
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.ovfilter), tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, tc)
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0 and g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local sg = g:Select(tp, 1, e:GetLabel() + 1, nil)
  		Duel.Overlay(tc, sg)
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_END)
  		e1:SetCountLimit(1)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		e1:SetOperation(s.damop)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.ovfilter(c)
  	local no = aux.GetXyzNumber(c)
  	return no and no >= 101 and no <= 107 and c:IsType(TYPE_XYZ) and (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsCanOverlay()
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_CARD, 0, id)
  	Duel.Damage(tp, Duel.GetFieldGroupCount(tp, LOCATION_HAND, 0) * 300, REASON_EFFECT)
  	Duel.Damage(1 - tp, Duel.GetFieldGroupCount(1 - tp, LOCATION_HAND, 0) * 300, REASON_EFFECT)
  end
  
  
source_text: Rebirth
  Tribute all Xyz Monsters you control, then target 1 of your banished Xyz Monsters; Special Summon it, then you can attach your "Number" Xyz Monsters that are banished and/or in your GY to it as material, that have a number between "101" and "107" in their name, up to the number of monsters Tributed to activate this effect +1. During the End Phase of the turn you activated this card, each player takes 300 damage for each card in their hand.
target_text: -- Rebirth
  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:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_XYZ) and c:IsFaceup()
  end
  function s.filter(c)
  	return c:IsReleasable() and not c:IsStatus(STATUS_BATTLE_DESTROYED)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return g:GetCount() > 0 and g:FilterCount(s.filter, nil) == g:GetCount() and Duel.GetMZoneCount(tp, g) > 0
  	end
  	e:SetLabel(g:GetCount())
  	Duel.Release(g, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:IsType(TYPE_XYZ) and c:IsFaceup() and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		if e:GetLabel() == 100 then
  			e:SetLabel(0)
  			return Duel.IsExistingTarget(s.spfilter, tp, LOCATION_REMOVED, 0, 1, nil, e, tp)
  		else
  			return false
  		end
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.ovfilter), tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, tc)
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0 and g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local sg = g:Select(tp, 1, e:GetLabel() + 1, nil)
  		Duel.Overlay(tc, sg)
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_END)
  		e1:SetCountLimit(1)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		e1:SetOperation(s.damop)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.ovfilter(c)
  	local no = aux.GetXyzNumber(c)
  	return no and no >= 101 and no <= 107 and c:IsType(TYPE_XYZ) and (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsCanOverlay()
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_CARD, 0, id)
  	Duel.Damage(tp, Duel.GetFieldGroupCount(tp, LOCATION_HAND, 0) * 300, REASON_EFFECT)
  	Duel.Damage(1 - tp, Duel.GetFieldGroupCount(1 - tp, LOCATION_HAND, 0) * 300, REASON_EFFECT)
  end
  
  