name: Link
card_text: Target 1 Link Monster you control in the Extra Monster Zone; move that monster you control to your Main Monster Zone it points to, then, you can send cards from the top of your Deck to the GY equal to its Link Rating. You can only activate 1 "Link Back" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--move
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.seqtg)
  	e1:SetOperation(s.seqop)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, tp)
  	if not (c:IsFaceup() and c:IsType(TYPE_LINK) and c:GetSequence() >= 5) then
  		return false
  	end
  	local zone = bit.band(c:GetLinkedZone(), 0x1f)
  	return Duel.GetLocationCount(tp, LOCATION_MZONE, PLAYER_NONE, 0, zone) > 0
  end
  function s.seqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  end
  function s.seqop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not (tc:IsRelateToEffect(e) and tc:IsControler(tp)) then
  		return
  	end
  	local zone = bit.band(tc:GetLinkedZone(tp), 0x1f)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE, PLAYER_NONE, 0, zone) > 0 then
  		local flag = bit.bxor(zone, 0xff)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOZONE)
  		local s = Duel.SelectDisableField(tp, 1, LOCATION_MZONE, 0, flag)
  		local nseq = 0
  		if s == 1 then
  			nseq = 0
  		elseif s == 2 then
  			nseq = 1
  		elseif s == 4 then
  			nseq = 2
  		elseif s == 8 then
  			nseq = 3
  		else
  			nseq = 4
  		end
  		Duel.MoveSequence(tc, nseq)
  		local ct = tc:GetLink()
  		if Duel.IsPlayerCanDiscardDeck(tp, ct) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.DiscardDeck(tp, ct, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Link
  Target 1 Link Monster you control in the Extra Monster Zone; move that monster you control to your Main Monster Zone it points to, then, you can send cards from the top of your Deck to the GY equal to its Link Rating. You can only activate 1 "Link Back" per turn.
target_text: -- Link
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--move
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.seqtg)
  	e1:SetOperation(s.seqop)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, tp)
  	if not (c:IsFaceup() and c:IsType(TYPE_LINK) and c:GetSequence() >= 5) then
  		return false
  	end
  	local zone = bit.band(c:GetLinkedZone(), 0x1f)
  	return Duel.GetLocationCount(tp, LOCATION_MZONE, PLAYER_NONE, 0, zone) > 0
  end
  function s.seqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  end
  function s.seqop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not (tc:IsRelateToEffect(e) and tc:IsControler(tp)) then
  		return
  	end
  	local zone = bit.band(tc:GetLinkedZone(tp), 0x1f)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE, PLAYER_NONE, 0, zone) > 0 then
  		local flag = bit.bxor(zone, 0xff)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOZONE)
  		local s = Duel.SelectDisableField(tp, 1, LOCATION_MZONE, 0, flag)
  		local nseq = 0
  		if s == 1 then
  			nseq = 0
  		elseif s == 2 then
  			nseq = 1
  		elseif s == 4 then
  			nseq = 2
  		elseif s == 8 then
  			nseq = 3
  		else
  			nseq = 4
  		end
  		Duel.MoveSequence(tc, nseq)
  		local ct = tc:GetLink()
  		if Duel.IsPlayerCanDiscardDeck(tp, ct) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.DiscardDeck(tp, ct, REASON_EFFECT)
  		end
  	end
  end
  
  