name: Afterglow
card_text: Banish this card, and as many "Afterglow" from your hand, Deck, GY, and face-up field as possible, then shuffle 1 of your banished "Afterglow" into the Deck. During your next Draw Phase, reveal the card you draw for your normal draw, and inflict 4000 damage to your opponent if it is "Afterglow". You can only activate 1 "Afterglow" per Duel.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_DUEL + EFFECT_COUNT_CODE_OATH)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.rmfilter(c)
  	return c:IsCode(id) and c:IsAbleToRemove() and (c:IsFaceup() or not c:IsOnField())
  end
  function s.tdfilter(c)
  	return c:IsCode(id) and c:IsAbleToDeck() and c:IsFaceup()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.rmfilter, tp, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE + LOCATION_DECK, 0, nil)
  	g:AddCard(e:GetHandler())
  	if chk == 0 then
  		return g:GetCount() > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, g:GetCount(), tp, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE + LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_REMOVED)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not e:GetHandler():IsRelateToEffect(e) then
  		return
  	end
  	local g = Duel.GetMatchingGroup(s.rmfilter, tp, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE + LOCATION_DECK, 0, nil)
  	if Duel.Remove(g, POS_FACEUP, REASON_EFFECT) > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local tg = Duel.SelectMatchingCard(tp, s.tdfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  		if tg:GetCount() > 0 then
  			Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  		end
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_DRAW)
  	e1:SetCondition(s.damcon)
  	e1:SetOperation(s.damop)
  	e1:SetReset(RESET_PHASE + PHASE_DRAW + RESET_SELF_TURN)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == e:GetOwnerPlayer() and r == REASON_RULE
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local hg = eg:Filter(Card.IsLocation, nil, LOCATION_HAND)
  	if hg:GetCount() == 0 then
  		return
  	end
  	Duel.ConfirmCards(1 - ep, hg)
  	local dg = hg:Filter(Card.IsCode, nil, id)
  	if dg:GetCount() > 0 then
  		Duel.Hint(HINT_CARD, 0, id)
  		Duel.Damage(1 - ep, 4000, REASON_EFFECT)
  	end
  	Duel.ShuffleHand(ep)
  end
  
  
source_text: Afterglow
  Banish this card, and as many "Afterglow" from your hand, Deck, GY, and face-up field as possible, then shuffle 1 of your banished "Afterglow" into the Deck. During your next Draw Phase, reveal the card you draw for your normal draw, and inflict 4000 damage to your opponent if it is "Afterglow". You can only activate 1 "Afterglow" per Duel.
target_text: -- Afterglow
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_DUEL + EFFECT_COUNT_CODE_OATH)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.rmfilter(c)
  	return c:IsCode(id) and c:IsAbleToRemove() and (c:IsFaceup() or not c:IsOnField())
  end
  function s.tdfilter(c)
  	return c:IsCode(id) and c:IsAbleToDeck() and c:IsFaceup()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.rmfilter, tp, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE + LOCATION_DECK, 0, nil)
  	g:AddCard(e:GetHandler())
  	if chk == 0 then
  		return g:GetCount() > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, g:GetCount(), tp, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE + LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_REMOVED)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not e:GetHandler():IsRelateToEffect(e) then
  		return
  	end
  	local g = Duel.GetMatchingGroup(s.rmfilter, tp, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE + LOCATION_DECK, 0, nil)
  	if Duel.Remove(g, POS_FACEUP, REASON_EFFECT) > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local tg = Duel.SelectMatchingCard(tp, s.tdfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  		if tg:GetCount() > 0 then
  			Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  		end
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_DRAW)
  	e1:SetCondition(s.damcon)
  	e1:SetOperation(s.damop)
  	e1:SetReset(RESET_PHASE + PHASE_DRAW + RESET_SELF_TURN)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == e:GetOwnerPlayer() and r == REASON_RULE
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local hg = eg:Filter(Card.IsLocation, nil, LOCATION_HAND)
  	if hg:GetCount() == 0 then
  		return
  	end
  	Duel.ConfirmCards(1 - ep, hg)
  	local dg = hg:Filter(Card.IsCode, nil, id)
  	if dg:GetCount() > 0 then
  		Duel.Hint(HINT_CARD, 0, id)
  		Duel.Damage(1 - ep, 4000, REASON_EFFECT)
  	end
  	Duel.ShuffleHand(ep)
  end
  
  