name: Seventh
card_text: Take 1 card from your Deck (either a "Barian's" Spell/Trap, a "Rank-Up-Magic" Quick-Play Spell, or a "Seventh" Spell/Trap except "Seventh Ascension"), and either add it to your hand or place it on top of your Deck. If your opponent controls a monster Special Summoned from the Extra Deck: You can banish this card from your GY and send 1 "Rank-Up-Magic" Spell from your hand to the GY; this effect becomes that Spell's effect when that card is activated. You can only use each effect of "Seventh Ascension" once per turn.
external_ids: local SETCARD_ID_0 = 0x176 --Barian's
  local SETCARD_ID_1 = 0x95 --Rank-Up-Magic
  local SETCARD_ID_2 = 0x175 --Seventh
  
lua: local SETCARD_ID_0 = 0x176 --Barian's
  local SETCARD_ID_1 = 0x95 --Rank-Up-Magic
  local SETCARD_ID_2 = 0x175 --Seventh
  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_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--copy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.cpcon)
  	e2:SetCost(s.cpcost)
  	e2:SetTarget(s.cptg)
  	e2:SetOperation(s.cpop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return (not c:IsCode(id) and c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_SPELL + TYPE_TRAP))
  		or (c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_SPELL + TYPE_TRAP))
  		or (c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_QUICKPLAY))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		if tc:IsAbleToHand() and Duel.SelectOption(tp, 1190, aux.Stringid(id, 2)) == 0 then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, tc)
  		else
  			Duel.ShuffleDeck(tp)
  			Duel.MoveSequence(tc, SEQ_DECKTOP)
  			Duel.ConfirmDecktop(tp, 1)
  		end
  	end
  end
  function s.cfilter(c)
  	return c:IsSummonLocation(LOCATION_EXTRA)
  end
  function s.cpcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, 0, LOCATION_MZONE, 1, nil)
  end
  function s.cpcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return true
  	end
  end
  function s.cpfilter(c)
  	return c:GetType() & TYPE_SPELL == TYPE_SPELL and c:IsSetCard(SETCARD_ID_2) and c:IsAbleToGraveAsCost() and c:CheckActivateEffect(true, true, false) ~= nil
  end
  function s.cptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return c:IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(s.cpfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	e:SetLabel(0)
  	Duel.Remove(c, POS_FACEUP, REASON_COST)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cpfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(true, true, true)
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetProperty(te:GetProperty())
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  end
  function s.cpop(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  
  
source_text: Seventh
  Take 1 card from your Deck (either a "Barian's" Spell/Trap, a "Rank-Up-Magic" Quick-Play Spell, or a "Seventh" Spell/Trap except "Seventh Ascension"), and either add it to your hand or place it on top of your Deck. If your opponent controls a monster Special Summoned from the Extra Deck: You can banish this card from your GY and send 1 "Rank-Up-Magic" Spell from your hand to the GY; this effect becomes that Spell's effect when that card is activated. You can only use each effect of "Seventh Ascension" once per turn.
target_text: -- Seventh
  local SETCARD_ID_0 = 0x176 --Barian's
  local SETCARD_ID_1 = 0x95 --Rank-Up-Magic
  local SETCARD_ID_2 = 0x175 --Seventh
  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_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--copy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.cpcon)
  	e2:SetCost(s.cpcost)
  	e2:SetTarget(s.cptg)
  	e2:SetOperation(s.cpop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return (not c:IsCode(id) and c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_SPELL + TYPE_TRAP))
  		or (c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_SPELL + TYPE_TRAP))
  		or (c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_QUICKPLAY))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		if tc:IsAbleToHand() and Duel.SelectOption(tp, 1190, aux.Stringid(id, 2)) == 0 then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, tc)
  		else
  			Duel.ShuffleDeck(tp)
  			Duel.MoveSequence(tc, SEQ_DECKTOP)
  			Duel.ConfirmDecktop(tp, 1)
  		end
  	end
  end
  function s.cfilter(c)
  	return c:IsSummonLocation(LOCATION_EXTRA)
  end
  function s.cpcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, 0, LOCATION_MZONE, 1, nil)
  end
  function s.cpcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(100)
  	if chk == 0 then
  		return true
  	end
  end
  function s.cpfilter(c)
  	return c:GetType() & TYPE_SPELL == TYPE_SPELL and c:IsSetCard(SETCARD_ID_2) and c:IsAbleToGraveAsCost() and c:CheckActivateEffect(true, true, false) ~= nil
  end
  function s.cptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		if e:GetLabel() ~= 100 then
  			return false
  		end
  		e:SetLabel(0)
  		return c:IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(s.cpfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	e:SetLabel(0)
  	Duel.Remove(c, POS_FACEUP, REASON_COST)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cpfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(true, true, true)
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetProperty(te:GetProperty())
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  end
  function s.cpop(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  
  