name: Salamangreat
card_text: Target 1 "Salamangreat" Link Monster you control; Special Summon 1 "Salamangreat" Link Monster with the same name from your Extra Deck, using that monster you control as the entire material. (This is treated as a Link Summon.) You can only activate 1 "Salamangreat Transcendence" per turn.
external_ids: local SETCARD_ID_0 = 0x119 --Salamangreat
  
lua: local SETCARD_ID_0 = 0x119 --Salamangreat
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c, e, tp)
  	return c:IsFaceup()
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_LINK)
  		and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c)
  		and aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_LMATERIAL)
  end
  function s.filter2(c, e, tp, mc)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_LINK)
  		and c:IsCode(mc:GetCode())
  		and mc:IsCanBeLinkMaterial(c)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_LINK, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.filter1(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter1, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not aux.MustMaterialCheck(tc, tp, EFFECT_MUST_BE_LMATERIAL) then
  		return
  	end
  	if tc:IsFacedown() or not tc:IsRelateToEffect(e) or tc:IsControler(1 - tp) or tc:IsImmuneToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.filter2, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, tc)
  	local sc = g:GetFirst()
  	if sc then
  		sc:SetMaterial(Group.FromCards(tc))
  		Duel.SendtoGrave(tc, REASON_EFFECT + REASON_MATERIAL + REASON_LINK)
  		Duel.BreakEffect()
  		Duel.SpecialSummon(sc, SUMMON_TYPE_LINK, tp, tp, false, false, POS_FACEUP)
  		sc:CompleteProcedure()
  	end
  end
  
  
source_text: Salamangreat
  Target 1 "Salamangreat" Link Monster you control; Special Summon 1 "Salamangreat" Link Monster with the same name from your Extra Deck, using that monster you control as the entire material. (This is treated as a Link Summon.) You can only activate 1 "Salamangreat Transcendence" per turn.
target_text: -- Salamangreat
  local SETCARD_ID_0 = 0x119 --Salamangreat
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c, e, tp)
  	return c:IsFaceup()
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_LINK)
  		and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c)
  		and aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_LMATERIAL)
  end
  function s.filter2(c, e, tp, mc)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_LINK)
  		and c:IsCode(mc:GetCode())
  		and mc:IsCanBeLinkMaterial(c)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_LINK, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.filter1(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter1, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not aux.MustMaterialCheck(tc, tp, EFFECT_MUST_BE_LMATERIAL) then
  		return
  	end
  	if tc:IsFacedown() or not tc:IsRelateToEffect(e) or tc:IsControler(1 - tp) or tc:IsImmuneToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.filter2, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, tc)
  	local sc = g:GetFirst()
  	if sc then
  		sc:SetMaterial(Group.FromCards(tc))
  		Duel.SendtoGrave(tc, REASON_EFFECT + REASON_MATERIAL + REASON_LINK)
  		Duel.BreakEffect()
  		Duel.SpecialSummon(sc, SUMMON_TYPE_LINK, tp, tp, false, false, POS_FACEUP)
  		sc:CompleteProcedure()
  	end
  end
  
  