name: Galactikuriboh
card_text: (This card is always treated as a "Galaxy" card.)
  When an opponent's monster declares an attack: You can discard this card; Special Summon 1 "Galaxy-Eyes Photon Dragon" from your hand or Deck, then change the attack target to it, then you can attach this card from the GY to 1 Xyz Monster on the field as material. If a "Photon" or "Galaxy" monster(s) you control would be destroyed by battle or an opponent's card effect, you can banish this card from your GY instead.
external_ids: local CARD_ID_0 = 93717133 --Galaxy-Eyes Photon Dragon
  local SETCARD_ID_0 = 0x55 --Photon
  
lua: local CARD_ID_0 = 93717133 --Galaxy-Eyes Photon Dragon
  local SETCARD_ID_0 = 0x55 --Photon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp)
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetTargetCard(e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.mfilter(c)
  	return c:IsType(TYPE_XYZ) and c:IsFaceup()
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tc = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp):GetFirst()
  	if tc and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0 and tc:IsLocation(LOCATION_MZONE) then
  		local a = Duel.GetAttacker()
  		if a:IsAttackable() and not a:IsImmuneToEffect(e) then
  			Duel.BreakEffect()
  			local mg = Duel.GetMatchingGroup(s.mfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  			if
  				Duel.ChangeAttackTarget(tc)
  				and mg:GetCount() > 0
  				and c:IsRelateToChain()
  				and c:IsLocation(LOCATION_GRAVE)
  				and aux.NecroValleyFilter()(c)
  				and c:IsCanOverlay()
  				and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  			then
  				Duel.BreakEffect()
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  				local sc = mg:Select(tp, 1, 1, nil):GetFirst()
  				if not sc:IsImmuneToEffect(e) then
  					Duel.Overlay(sc, Group.FromCards(c))
  				end
  			end
  		end
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsControler(tp)
  		and c:IsSetCard(SETCARD_ID_0, 0x7b)
  		and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp))
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  
source_text: Galactikuriboh
  (This card is always treated as a "Galaxy" card.)
  When an opponent's monster declares an attack: You can discard this card; Special Summon 1 "Galaxy-Eyes Photon Dragon" from your hand or Deck, then change the attack target to it, then you can attach this card from the GY to 1 Xyz Monster on the field as material. If a "Photon" or "Galaxy" monster(s) you control would be destroyed by battle or an opponent's card effect, you can banish this card from your GY instead.
target_text: -- Galactikuriboh
  local CARD_ID_0 = 93717133 --Galaxy-Eyes Photon Dragon
  local SETCARD_ID_0 = 0x55 --Photon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp)
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetTargetCard(e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.mfilter(c)
  	return c:IsType(TYPE_XYZ) and c:IsFaceup()
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tc = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp):GetFirst()
  	if tc and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0 and tc:IsLocation(LOCATION_MZONE) then
  		local a = Duel.GetAttacker()
  		if a:IsAttackable() and not a:IsImmuneToEffect(e) then
  			Duel.BreakEffect()
  			local mg = Duel.GetMatchingGroup(s.mfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  			if
  				Duel.ChangeAttackTarget(tc)
  				and mg:GetCount() > 0
  				and c:IsRelateToChain()
  				and c:IsLocation(LOCATION_GRAVE)
  				and aux.NecroValleyFilter()(c)
  				and c:IsCanOverlay()
  				and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  			then
  				Duel.BreakEffect()
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  				local sc = mg:Select(tp, 1, 1, nil):GetFirst()
  				if not sc:IsImmuneToEffect(e) then
  					Duel.Overlay(sc, Group.FromCards(c))
  				end
  			end
  		end
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsControler(tp)
  		and c:IsSetCard(SETCARD_ID_0, 0x7b)
  		and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp))
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  