name: Galaxy-Eyes
card_text: If you control a "Galaxy-Eyes" monster: You can Special Summon this card from your hand in Defense Position. If this card is detached from an Xyz Monster to activate that monster's effect: You can take 1 "Galaxy-Eyes Photon Dragon" from your hand or Deck, and either Special Summon it, or attach it to an Xyz Monster you control as material, then if you activated this effect during the Battle Phase, double the ATK of all "Number" Xyz Monsters you control. You can only use each effect of "Galaxy-Eyes Afterglow Dragon" once per turn.
external_ids: local CARD_ID_0 = 93717133 --Galaxy-Eyes Photon Dragon
  local SETCARD_ID_0 = 0x107b --Galaxy-Eyes
  local SETCARD_ID_1 = 0x48 --Number
  
lua: local CARD_ID_0 = 93717133 --Galaxy-Eyes Photon Dragon
  local SETCARD_ID_0 = 0x107b --Galaxy-Eyes
  local SETCARD_ID_1 = 0x48 --Number
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon1)
  	e1:SetTarget(s.sptg1)
  	e1:SetOperation(s.spop1)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_MOVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon2)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1)
  end
  function s.spcon1(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop1(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_COST) and re:IsActivated() and re:IsActiveType(TYPE_XYZ) and c:IsPreviousLocation(LOCATION_OVERLAY)
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_0)
  		and (
  			Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  			or (Duel.IsExistingMatchingCard(s.matfilter, tp, LOCATION_MZONE, 0, 1, nil) and c:IsCanOverlay())
  		)
  end
  function s.matfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	local bpchk = 0
  	if Duel.GetCurrentPhase() >= PHASE_BATTLE_START and Duel.GetCurrentPhase() < PHASE_BATTLE then
  		bpchk = 1
  	end
  	e:SetLabel(bpchk)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_XYZ)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	local res = 0
  	if tc then
  		if
  			Duel.IsExistingMatchingCard(s.matfilter, tp, LOCATION_MZONE, 0, 1, nil)
  			and tc:IsCanOverlay()
  			and (not tc:IsCanBeSpecialSummoned(e, 0, tp, false, false) or Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 or Duel.SelectOption(tp, 1152, aux.Stringid(id, 2)) == 1)
  		then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  			local sg = Duel.SelectMatchingCard(tp, s.matfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  			Duel.Overlay(sg:GetFirst(), Group.FromCards(tc))
  			res = 1
  		else
  			res = Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  		end
  		if res ~= 0 and e:GetLabel() == 1 then
  			local tg = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, 0, nil)
  			local tc = tg:GetFirst()
  			while tc do
  				local e1 = Effect.CreateEffect(e:GetHandler())
  				e1:SetType(EFFECT_TYPE_SINGLE)
  				e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  				e1:SetValue(tc:GetAttack() * 2)
  				e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  				tc:RegisterEffect(e1)
  				tc = tg:GetNext()
  			end
  		end
  	end
  end
  
  
source_text: Galaxy-Eyes
  If you control a "Galaxy-Eyes" monster: You can Special Summon this card from your hand in Defense Position. If this card is detached from an Xyz Monster to activate that monster's effect: You can take 1 "Galaxy-Eyes Photon Dragon" from your hand or Deck, and either Special Summon it, or attach it to an Xyz Monster you control as material, then if you activated this effect during the Battle Phase, double the ATK of all "Number" Xyz Monsters you control. You can only use each effect of "Galaxy-Eyes Afterglow Dragon" once per turn.
target_text: -- Galaxy-Eyes
  local CARD_ID_0 = 93717133 --Galaxy-Eyes Photon Dragon
  local SETCARD_ID_0 = 0x107b --Galaxy-Eyes
  local SETCARD_ID_1 = 0x48 --Number
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon1)
  	e1:SetTarget(s.sptg1)
  	e1:SetOperation(s.spop1)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_MOVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon2)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1)
  end
  function s.spcon1(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.sptg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop1(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  	end
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_COST) and re:IsActivated() and re:IsActiveType(TYPE_XYZ) and c:IsPreviousLocation(LOCATION_OVERLAY)
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_0)
  		and (
  			Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  			or (Duel.IsExistingMatchingCard(s.matfilter, tp, LOCATION_MZONE, 0, 1, nil) and c:IsCanOverlay())
  		)
  end
  function s.matfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ)
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	local bpchk = 0
  	if Duel.GetCurrentPhase() >= PHASE_BATTLE_START and Duel.GetCurrentPhase() < PHASE_BATTLE then
  		bpchk = 1
  	end
  	e:SetLabel(bpchk)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_XYZ)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	local res = 0
  	if tc then
  		if
  			Duel.IsExistingMatchingCard(s.matfilter, tp, LOCATION_MZONE, 0, 1, nil)
  			and tc:IsCanOverlay()
  			and (not tc:IsCanBeSpecialSummoned(e, 0, tp, false, false) or Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 or Duel.SelectOption(tp, 1152, aux.Stringid(id, 2)) == 1)
  		then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  			local sg = Duel.SelectMatchingCard(tp, s.matfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  			Duel.Overlay(sg:GetFirst(), Group.FromCards(tc))
  			res = 1
  		else
  			res = Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  		end
  		if res ~= 0 and e:GetLabel() == 1 then
  			local tg = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, 0, nil)
  			local tc = tg:GetFirst()
  			while tc do
  				local e1 = Effect.CreateEffect(e:GetHandler())
  				e1:SetType(EFFECT_TYPE_SINGLE)
  				e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  				e1:SetValue(tc:GetAttack() * 2)
  				e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  				tc:RegisterEffect(e1)
  				tc = tg:GetNext()
  			end
  		end
  	end
  end
  
  