name: Time
card_text: When a Spell/Trap Card is activated while you control a "Time Thief" Xyz Monster: Negate the activation, and if you do, attach that card to a "Time Thief" Xyz Monster you control as material. You can only activate 1 "Time Thief Retrograde" per turn.
external_ids: local SETCARD_ID_0 = 0x126 --Time
  
lua: local SETCARD_ID_0 = 0x126 --Time
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_NEGATE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ)
  end
  function s.cfilter2(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ) and not c:IsStatus(STATUS_BATTLE_DESTROYED)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil) and re:IsHasType(EFFECT_TYPE_ACTIVATE) and Duel.IsChainNegatable(ev)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local rc = re:GetHandler()
  	if Duel.NegateActivation(ev) and rc:IsRelateToEffect(re) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  		local g = Duel.SelectMatchingCard(tp, s.cfilter2, tp, LOCATION_MZONE, 0, 1, 1, nil)
  		if g:GetCount() > 0 and not g:GetFirst():IsImmuneToEffect(e) and rc:IsCanOverlay() then
  			rc:CancelToGrave()
  			Duel.Overlay(g:GetFirst(), Group.FromCards(rc))
  		end
  	end
  end
  
  
source_text: Time
  When a Spell/Trap Card is activated while you control a "Time Thief" Xyz Monster: Negate the activation, and if you do, attach that card to a "Time Thief" Xyz Monster you control as material. You can only activate 1 "Time Thief Retrograde" per turn.
target_text: -- Time
  local SETCARD_ID_0 = 0x126 --Time
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_NEGATE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ)
  end
  function s.cfilter2(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ) and not c:IsStatus(STATUS_BATTLE_DESTROYED)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil) and re:IsHasType(EFFECT_TYPE_ACTIVATE) and Duel.IsChainNegatable(ev)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local rc = re:GetHandler()
  	if Duel.NegateActivation(ev) and rc:IsRelateToEffect(re) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  		local g = Duel.SelectMatchingCard(tp, s.cfilter2, tp, LOCATION_MZONE, 0, 1, 1, nil)
  		if g:GetCount() > 0 and not g:GetFirst():IsImmuneToEffect(e) and rc:IsCanOverlay() then
  			rc:CancelToGrave()
  			Duel.Overlay(g:GetFirst(), Group.FromCards(rc))
  		end
  	end
  end
  
  