name: Zoodiac
card_text: If a "Zoodiac" Xyz Monster you control would detach its Xyz Material(s) to activate an effect, you can detach Xyz Material(s) from another Xyz Monster(s) you control instead. You can only use this effect of "Zoodiac Gathering" once per turn. You can banish this card from your Graveyard, then target 2 "Zoodiac" Xyz Monsters you control; attach 1 of those monsters to the other monster as Xyz Material.
external_ids: local SETCARD_ID_0 = 0xf1 --Zoodiac
  
lua: local SETCARD_ID_0 = 0xf1 --Zoodiac
  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)
  	--remove overlay replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_OVERLAY_REMOVE_REPLACE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.rcon)
  	e2:SetOperation(s.rop)
  	c:RegisterEffect(e2)
  	--attach
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.xyztg)
  	e3:SetOperation(s.xyzop)
  	c:RegisterEffect(e3)
  end
  function s.rfilter(c, oc, tp)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and c:CheckRemoveOverlayCard(tp, oc, REASON_COST)
  end
  function s.rcon(e, tp, eg, ep, ev, re, r, rp)
  	local rc = re:GetHandler()
  	return bit.band(r, REASON_COST) ~= 0
  		and re:IsActivated()
  		and re:IsActiveType(TYPE_XYZ)
  		and ep == e:GetOwnerPlayer()
  		and rc:IsSetCard(SETCARD_ID_0)
  		and Duel.IsExistingMatchingCard(s.rfilter, tp, LOCATION_MZONE, 0, 1, rc, ev, tp)
  end
  function s.rop(e, tp, eg, ep, ev, re, r, rp)
  	local min = ev & 0xffff
  	local max = (ev >> 16) & 0xffff
  	local rc = re:GetHandler()
  	local tg = Duel.SelectMatchingCard(tp, s.rfilter, tp, LOCATION_MZONE, 0, 1, 1, rc, min, tp)
  	return tg:GetFirst():RemoveOverlayCard(tp, min, max, REASON_EFFECT)
  end
  function s.xyzfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.xyztg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.xyzfilter, tp, LOCATION_MZONE, 0, 2, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	Duel.SelectTarget(tp, s.xyzfilter, tp, LOCATION_MZONE, 0, 2, 2, nil)
  end
  function s.xyzop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() ~= 2 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  	local xc = g:Select(tp, 1, 1, nil):GetFirst()
  	g:RemoveCard(xc)
  	local tc = g:GetFirst()
  	if not tc:IsImmuneToEffect(e) then
  		local og = xc:GetOverlayGroup()
  		if og:GetCount() > 0 then
  			Duel.SendtoGrave(og, REASON_RULE)
  		end
  		Duel.Overlay(tc, Group.FromCards(xc))
  	end
  end
  
  
source_text: Zoodiac
  If a "Zoodiac" Xyz Monster you control would detach its Xyz Material(s) to activate an effect, you can detach Xyz Material(s) from another Xyz Monster(s) you control instead. You can only use this effect of "Zoodiac Gathering" once per turn. You can banish this card from your Graveyard, then target 2 "Zoodiac" Xyz Monsters you control; attach 1 of those monsters to the other monster as Xyz Material.
target_text: -- Zoodiac
  local SETCARD_ID_0 = 0xf1 --Zoodiac
  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)
  	--remove overlay replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_OVERLAY_REMOVE_REPLACE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.rcon)
  	e2:SetOperation(s.rop)
  	c:RegisterEffect(e2)
  	--attach
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.xyztg)
  	e3:SetOperation(s.xyzop)
  	c:RegisterEffect(e3)
  end
  function s.rfilter(c, oc, tp)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and c:CheckRemoveOverlayCard(tp, oc, REASON_COST)
  end
  function s.rcon(e, tp, eg, ep, ev, re, r, rp)
  	local rc = re:GetHandler()
  	return bit.band(r, REASON_COST) ~= 0
  		and re:IsActivated()
  		and re:IsActiveType(TYPE_XYZ)
  		and ep == e:GetOwnerPlayer()
  		and rc:IsSetCard(SETCARD_ID_0)
  		and Duel.IsExistingMatchingCard(s.rfilter, tp, LOCATION_MZONE, 0, 1, rc, ev, tp)
  end
  function s.rop(e, tp, eg, ep, ev, re, r, rp)
  	local min = ev & 0xffff
  	local max = (ev >> 16) & 0xffff
  	local rc = re:GetHandler()
  	local tg = Duel.SelectMatchingCard(tp, s.rfilter, tp, LOCATION_MZONE, 0, 1, 1, rc, min, tp)
  	return tg:GetFirst():RemoveOverlayCard(tp, min, max, REASON_EFFECT)
  end
  function s.xyzfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.xyztg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.xyzfilter, tp, LOCATION_MZONE, 0, 2, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	Duel.SelectTarget(tp, s.xyzfilter, tp, LOCATION_MZONE, 0, 2, 2, nil)
  end
  function s.xyzop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() ~= 2 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  	local xc = g:Select(tp, 1, 1, nil):GetFirst()
  	g:RemoveCard(xc)
  	local tc = g:GetFirst()
  	if not tc:IsImmuneToEffect(e) then
  		local og = xc:GetOverlayGroup()
  		if og:GetCount() > 0 then
  			Duel.SendtoGrave(og, REASON_RULE)
  		end
  		Duel.Overlay(tc, Group.FromCards(xc))
  	end
  end
  
  