name: Zexal
card_text: Your opponent cannot activate cards or effects in response to the activation of your cards and effects that target an Xyz Monster you control. During your Draw Phase, before you draw: You can place 1 "Shining Draw" from your Deck on top of your Deck. If an Xyz Monster(s) is Special Summoned to your field (except during the Damage Step): You can target 1 of those monsters; attach 1 Xyz Monster from your Extra Deck or GY to that monster as material. You can only use this effect of "Zexal Field" once per turn.
external_ids: local CARD_ID_0 = 35906693 --Shining Draw
  
lua: local CARD_ID_0 = 35906693 --Shining Draw
  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)
  	--act limit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetOperation(s.chainop)
  	c:RegisterEffect(e2)
  	--material
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.mattg)
  	e3:SetOperation(s.matop)
  	c:RegisterEffect(e3)
  	--deck top
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_TOHAND)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_PREDRAW)
  	e4:SetRange(LOCATION_FZONE)
  	e4:SetCondition(s.tdcon)
  	e4:SetTarget(s.tdtg)
  	e4:SetOperation(s.tdop)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c, tp)
  	return c:IsLocation(LOCATION_MZONE) and c:IsControler(tp) and c:IsFaceup() and c:IsType(TYPE_XYZ)
  end
  function s.chainop(e, tp, eg, ep, ev, re, r, rp)
  	if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then
  		return
  	end
  	local tg = Duel.GetChainInfo(ev, CHAININFO_TARGET_CARDS)
  	if tg and tg:IsExists(s.cfilter, 1, nil, tp) and ep == tp then
  		Duel.SetChainLimit(s.chainlm)
  	end
  end
  function s.chainlm(e, rp, tp)
  	return tp == rp
  end
  function s.tgfilter(c, e, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsType(TYPE_XYZ) and c:IsLocation(LOCATION_MZONE) and c:IsCanBeEffectTarget(e)
  end
  function s.matfilter(c)
  	return c:IsType(TYPE_XYZ) and c:IsCanOverlay()
  end
  function s.mattg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return eg:IsContains(chkc) and s.tgfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return eg:IsExists(s.tgfilter, 1, nil, e, tp) and Duel.IsExistingMatchingCard(s.matfilter, tp, LOCATION_EXTRA + LOCATION_GRAVE, 0, 1, nil)
  	end
  	local g = eg
  	if #eg > 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		g = eg:FilterSelect(tp, s.tgfilter, 1, 1, nil, e, tp)
  	end
  	Duel.SetTargetCard(g)
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and not tc:IsImmuneToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.matfilter), tp, LOCATION_EXTRA + LOCATION_GRAVE, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.Overlay(tc, g)
  		end
  	end
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp == Duel.GetTurnPlayer() and Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 0 and Duel.GetDrawCount(tp) > 0
  end
  function s.tdfilter(c)
  	return c:IsCode(CARD_ID_0)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 1 and Duel.IsExistingMatchingCard(s.tdfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) <= 1 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	local dc = Duel.SelectMatchingCard(tp, s.tdfilter, tp, LOCATION_DECK, 0, 1, 1, nil):GetFirst()
  	if dc then
  		Duel.ShuffleDeck(tp)
  		Duel.MoveSequence(dc, SEQ_DECKTOP)
  		Duel.ConfirmDecktop(tp, 1)
  	end
  end
  
  
source_text: Zexal
  Your opponent cannot activate cards or effects in response to the activation of your cards and effects that target an Xyz Monster you control. During your Draw Phase, before you draw: You can place 1 "Shining Draw" from your Deck on top of your Deck. If an Xyz Monster(s) is Special Summoned to your field (except during the Damage Step): You can target 1 of those monsters; attach 1 Xyz Monster from your Extra Deck or GY to that monster as material. You can only use this effect of "Zexal Field" once per turn.
target_text: -- Zexal
  local CARD_ID_0 = 35906693 --Shining Draw
  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)
  	--act limit
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetOperation(s.chainop)
  	c:RegisterEffect(e2)
  	--material
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.mattg)
  	e3:SetOperation(s.matop)
  	c:RegisterEffect(e3)
  	--deck top
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_TOHAND)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_PREDRAW)
  	e4:SetRange(LOCATION_FZONE)
  	e4:SetCondition(s.tdcon)
  	e4:SetTarget(s.tdtg)
  	e4:SetOperation(s.tdop)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c, tp)
  	return c:IsLocation(LOCATION_MZONE) and c:IsControler(tp) and c:IsFaceup() and c:IsType(TYPE_XYZ)
  end
  function s.chainop(e, tp, eg, ep, ev, re, r, rp)
  	if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then
  		return
  	end
  	local tg = Duel.GetChainInfo(ev, CHAININFO_TARGET_CARDS)
  	if tg and tg:IsExists(s.cfilter, 1, nil, tp) and ep == tp then
  		Duel.SetChainLimit(s.chainlm)
  	end
  end
  function s.chainlm(e, rp, tp)
  	return tp == rp
  end
  function s.tgfilter(c, e, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsType(TYPE_XYZ) and c:IsLocation(LOCATION_MZONE) and c:IsCanBeEffectTarget(e)
  end
  function s.matfilter(c)
  	return c:IsType(TYPE_XYZ) and c:IsCanOverlay()
  end
  function s.mattg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return eg:IsContains(chkc) and s.tgfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return eg:IsExists(s.tgfilter, 1, nil, e, tp) and Duel.IsExistingMatchingCard(s.matfilter, tp, LOCATION_EXTRA + LOCATION_GRAVE, 0, 1, nil)
  	end
  	local g = eg
  	if #eg > 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		g = eg:FilterSelect(tp, s.tgfilter, 1, 1, nil, e, tp)
  	end
  	Duel.SetTargetCard(g)
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and not tc:IsImmuneToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.matfilter), tp, LOCATION_EXTRA + LOCATION_GRAVE, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.Overlay(tc, g)
  		end
  	end
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp == Duel.GetTurnPlayer() and Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 0 and Duel.GetDrawCount(tp) > 0
  end
  function s.tdfilter(c)
  	return c:IsCode(CARD_ID_0)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 1 and Duel.IsExistingMatchingCard(s.tdfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) <= 1 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	local dc = Duel.SelectMatchingCard(tp, s.tdfilter, tp, LOCATION_DECK, 0, 1, 1, nil):GetFirst()
  	if dc then
  		Duel.ShuffleDeck(tp)
  		Duel.MoveSequence(dc, SEQ_DECKTOP)
  		Duel.ConfirmDecktop(tp, 1)
  	end
  end
  
  