name: Noble
card_text: Equip only to a "Noble Knight" monster. It cannot be targeted by an opponent's card effects. During your turn, except the turn this card was sent to the Graveyard: You can banish this card from your Graveyard, then target 1 "Noble Knight" Xyz Monster you control; Special Summon from your Extra Deck, 1 "Noble Knight" Xyz Monster with a different name, by using that target as the Xyz Material. (This Special Summon is treated as an Xyz Summon. Xyz Materials attached to it also become Xyz Materials on the Summoned monster.) You can only use this effect of "Noble Arms - Excaliburn" once per turn.
external_ids: local SETCARD_ID_0 = 0x107a --Noble
  
lua: local SETCARD_ID_0 = 0x107a --Noble
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--Untargetable
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_EQUIP)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetValue(aux.tgoval)
  	c:RegisterEffect(e3)
  	--Equip limit
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_EQUIP_LIMIT)
  	e4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e4:SetValue(s.eqlimit)
  	c:RegisterEffect(e4)
  end
  function s.eqlimit(e, c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, c, tc)
  	end
  end
  function s.filter1(c, e, tp)
  	return c:IsFaceup()
  		and c:IsType(TYPE_XYZ)
  		and c:IsSetCard(SETCARD_ID_0)
  		and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c, c:GetCode())
  		and aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_XMATERIAL)
  end
  function s.filter2(c, e, tp, mc, code)
  	return c:IsType(TYPE_XYZ)
  		and c:IsSetCard(SETCARD_ID_0)
  		and not c:IsCode(code)
  		and mc:IsCanBeXyzMaterial(c)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_XYZ, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.sptg(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)
  	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.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not aux.MustMaterialCheck(tc, tp, EFFECT_MUST_BE_XMATERIAL) 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, tc:GetCode())
  	local sc = g:GetFirst()
  	if sc then
  		local mg = tc:GetOverlayGroup()
  		if mg:GetCount() ~= 0 then
  			Duel.Overlay(sc, mg)
  		end
  		sc:SetMaterial(Group.FromCards(tc))
  		Duel.Overlay(sc, Group.FromCards(tc))
  		Duel.SpecialSummon(sc, SUMMON_TYPE_XYZ, tp, tp, false, false, POS_FACEUP)
  		sc:CompleteProcedure()
  	end
  end
  
  
source_text: Noble
  Equip only to a "Noble Knight" monster. It cannot be targeted by an opponent's card effects. During your turn, except the turn this card was sent to the Graveyard: You can banish this card from your Graveyard, then target 1 "Noble Knight" Xyz Monster you control; Special Summon from your Extra Deck, 1 "Noble Knight" Xyz Monster with a different name, by using that target as the Xyz Material. (This Special Summon is treated as an Xyz Summon. Xyz Materials attached to it also become Xyz Materials on the Summoned monster.) You can only use this effect of "Noble Arms - Excaliburn" once per turn.
target_text: -- Noble
  local SETCARD_ID_0 = 0x107a --Noble
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--Untargetable
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_EQUIP)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetValue(aux.tgoval)
  	c:RegisterEffect(e3)
  	--Equip limit
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_EQUIP_LIMIT)
  	e4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e4:SetValue(s.eqlimit)
  	c:RegisterEffect(e4)
  end
  function s.eqlimit(e, c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, c, tc)
  	end
  end
  function s.filter1(c, e, tp)
  	return c:IsFaceup()
  		and c:IsType(TYPE_XYZ)
  		and c:IsSetCard(SETCARD_ID_0)
  		and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c, c:GetCode())
  		and aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_XMATERIAL)
  end
  function s.filter2(c, e, tp, mc, code)
  	return c:IsType(TYPE_XYZ)
  		and c:IsSetCard(SETCARD_ID_0)
  		and not c:IsCode(code)
  		and mc:IsCanBeXyzMaterial(c)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_XYZ, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.sptg(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)
  	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.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not aux.MustMaterialCheck(tc, tp, EFFECT_MUST_BE_XMATERIAL) 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, tc:GetCode())
  	local sc = g:GetFirst()
  	if sc then
  		local mg = tc:GetOverlayGroup()
  		if mg:GetCount() ~= 0 then
  			Duel.Overlay(sc, mg)
  		end
  		sc:SetMaterial(Group.FromCards(tc))
  		Duel.Overlay(sc, Group.FromCards(tc))
  		Duel.SpecialSummon(sc, SUMMON_TYPE_XYZ, tp, tp, false, false, POS_FACEUP)
  		sc:CompleteProcedure()
  	end
  end
  
  