name: Xyz
card_text: Declare a Level from 1 to 12, then target 2 face-up monsters on the field, including 1 monster you control; they become the declared Level (until the end of this turn), also, for the rest of this turn after this card resolves, you cannot Special Summon monsters from the Extra Deck, except monsters with the same Type as a targeted monster. You can only activate 1 "Xyz Align" per turn.
lua: 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)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.tgfilter(c, e)
  	return c:IsFaceup() and c:IsLevelAbove(0) and c:IsCanBeEffectTarget(e)
  end
  function s.gcheck(sg, tp)
  	return sg:IsExists(Card.IsControler, 1, nil, tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	local g = Duel.GetMatchingGroup(s.tgfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, e)
  	if chk == 0 then
  		return g:CheckSubGroup(s.gcheck, 2, 2, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 0))
  	local sg = g:SelectSubGroup(tp, s.gcheck, false, 2, 2, tp)
  	Duel.SetTargetCard(sg)
  	local exlv = 0
  	if sg:GetClassCount(Card.GetLevel) == 1 then
  		exlv = sg:GetFirst():GetLevel()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINGMSG_LVRANK)
  	local lv = Duel.AnnounceLevel(tp, 1, 12, exlv)
  	e:SetLabel(lv)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local lv = e:GetLabel()
  	local race = 0
  	local g = Duel.GetTargetsRelateToChain():Filter(Card.IsFaceup, nil)
  	local tc = g:GetFirst()
  	while tc do
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetValue(lv)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		race = race | tc:GetRace()
  		tc = g:GetNext()
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) and race > 0 then
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_FIELD)
  		e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  		e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e2:SetTargetRange(1, 0)
  		e2:SetLabel(race)
  		e2:SetTarget(s.splimit)
  		e2:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.splimit(e, c)
  	return c:IsLocation(LOCATION_EXTRA) and not c:IsRace(e:GetLabel())
  end
  
  
source_text: Xyz
  Declare a Level from 1 to 12, then target 2 face-up monsters on the field, including 1 monster you control; they become the declared Level (until the end of this turn), also, for the rest of this turn after this card resolves, you cannot Special Summon monsters from the Extra Deck, except monsters with the same Type as a targeted monster. You can only activate 1 "Xyz Align" per turn.
target_text: -- Xyz
  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)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.tgfilter(c, e)
  	return c:IsFaceup() and c:IsLevelAbove(0) and c:IsCanBeEffectTarget(e)
  end
  function s.gcheck(sg, tp)
  	return sg:IsExists(Card.IsControler, 1, nil, tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	local g = Duel.GetMatchingGroup(s.tgfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, e)
  	if chk == 0 then
  		return g:CheckSubGroup(s.gcheck, 2, 2, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 0))
  	local sg = g:SelectSubGroup(tp, s.gcheck, false, 2, 2, tp)
  	Duel.SetTargetCard(sg)
  	local exlv = 0
  	if sg:GetClassCount(Card.GetLevel) == 1 then
  		exlv = sg:GetFirst():GetLevel()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINGMSG_LVRANK)
  	local lv = Duel.AnnounceLevel(tp, 1, 12, exlv)
  	e:SetLabel(lv)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local lv = e:GetLabel()
  	local race = 0
  	local g = Duel.GetTargetsRelateToChain():Filter(Card.IsFaceup, nil)
  	local tc = g:GetFirst()
  	while tc do
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetValue(lv)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		race = race | tc:GetRace()
  		tc = g:GetNext()
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) and race > 0 then
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_FIELD)
  		e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  		e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e2:SetTargetRange(1, 0)
  		e2:SetLabel(race)
  		e2:SetTarget(s.splimit)
  		e2:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.splimit(e, c)
  	return c:IsLocation(LOCATION_EXTRA) and not c:IsRace(e:GetLabel())
  end
  
  