name: Endless
card_text: Send 1 "Therion" card from your Deck to the GY. If this card is in your GY: You can target 1 "Therion" card in your GY; if both are still in your GY, add either that card or this card to your hand, and if you do, place the other on the bottom of your Deck. You can only use 1 "Endless Engine Argyro System" effect per turn, and only once that turn.
external_ids: local SETCARD_ID_0 = 0x179 --Therion
  
lua: local SETCARD_ID_0 = 0x179 --Therion
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tg)
  	e2:SetOperation(s.op)
  	c:RegisterEffect(e2)
  end
  function s.tgfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGrave()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoGrave(g, REASON_EFFECT)
  	end
  end
  function s.filter(c, b1, b2)
  	return c:IsSetCard(SETCARD_ID_0) and ((b1 and c:IsAbleToHand()) or (b2 and c:IsAbleToDeck()))
  end
  function s.tg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	local b1, b2 = c:IsAbleToDeck(), c:IsAbleToHand()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, b1, b2)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, b1, b2)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, b1, b2)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.op(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		local g = Group.FromCards(tc, c)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local tg = g:FilterSelect(tp, Card.IsAbleToHand, 1, 1, nil)
  		g:Sub(tg)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tg:GetFirst())
  		Duel.SendtoDeck(g, nil, SEQ_DECKBOTTOM, REASON_EFFECT)
  	end
  end
  
  
source_text: Endless
  Send 1 "Therion" card from your Deck to the GY. If this card is in your GY: You can target 1 "Therion" card in your GY; if both are still in your GY, add either that card or this card to your hand, and if you do, place the other on the bottom of your Deck. You can only use 1 "Endless Engine Argyro System" effect per turn, and only once that turn.
target_text: -- Endless
  local SETCARD_ID_0 = 0x179 --Therion
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tg)
  	e2:SetOperation(s.op)
  	c:RegisterEffect(e2)
  end
  function s.tgfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGrave()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoGrave(g, REASON_EFFECT)
  	end
  end
  function s.filter(c, b1, b2)
  	return c:IsSetCard(SETCARD_ID_0) and ((b1 and c:IsAbleToHand()) or (b2 and c:IsAbleToDeck()))
  end
  function s.tg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	local b1, b2 = c:IsAbleToDeck(), c:IsAbleToHand()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, b1, b2)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, b1, b2)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, b1, b2)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.op(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) then
  		local g = Group.FromCards(tc, c)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local tg = g:FilterSelect(tp, Card.IsAbleToHand, 1, 1, nil)
  		g:Sub(tg)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tg:GetFirst())
  		Duel.SendtoDeck(g, nil, SEQ_DECKBOTTOM, REASON_EFFECT)
  	end
  end
  
  