name: Rank-Up-Magic
card_text: Target 1 "Raidraptor" Xyz Monster in your Graveyard that was destroyed by battle and sent there this turn; Special Summon it, then Special Summon from your Extra Deck, 1 Xyz Monster that has twice the Rank of that monster, by using it as the Xyz Material. (This Special Summon is treated as an Xyz Summon.)
external_ids: local SETCARD_ID_0 = 0xba --Raidraptor
  
lua: local SETCARD_ID_0 = 0xba --Raidraptor
  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:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMING_DESTROY + TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	if not s.globle_check then
  		s.globle_check = true
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  		ge1:SetCode(EVENT_TO_GRAVE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	while tc do
  		if tc:IsSetCard(SETCARD_ID_0) and tc:IsType(TYPE_XYZ) and tc:IsReason(REASON_DESTROY) and tc:IsReason(REASON_BATTLE) then
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  		end
  		tc = eg:GetNext()
  	end
  end
  function s.filter1(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_XYZ)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and c:GetFlagEffect(id) ~= 0
  		and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c, c:GetRank() * 2)
  end
  function s.filter2(c, e, tp, mc, rk)
  	return c:IsRank(rk) 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.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter1(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanSpecialSummonCount(tp, 2)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_XMATERIAL)
  			and Duel.IsExistingTarget(s.filter1, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 2, tp, LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) or tc:IsImmuneToEffect(e) then
  		return
  	end
  	if Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) == 0 then
  		return
  	end
  	if not aux.MustMaterialCheck(tc, tp, EFFECT_MUST_BE_XMATERIAL) 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:GetRank() * 2)
  	local sc = g:GetFirst()
  	if sc then
  		Duel.BreakEffect()
  		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: Rank-Up-Magic
  Target 1 "Raidraptor" Xyz Monster in your Graveyard that was destroyed by battle and sent there this turn; Special Summon it, then Special Summon from your Extra Deck, 1 Xyz Monster that has twice the Rank of that monster, by using it as the Xyz Material. (This Special Summon is treated as an Xyz Summon.)
target_text: -- Rank-Up-Magic
  local SETCARD_ID_0 = 0xba --Raidraptor
  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:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMING_DESTROY + TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	if not s.globle_check then
  		s.globle_check = true
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  		ge1:SetCode(EVENT_TO_GRAVE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	while tc do
  		if tc:IsSetCard(SETCARD_ID_0) and tc:IsType(TYPE_XYZ) and tc:IsReason(REASON_DESTROY) and tc:IsReason(REASON_BATTLE) then
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  		end
  		tc = eg:GetNext()
  	end
  end
  function s.filter1(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_XYZ)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and c:GetFlagEffect(id) ~= 0
  		and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c, c:GetRank() * 2)
  end
  function s.filter2(c, e, tp, mc, rk)
  	return c:IsRank(rk) 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.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter1(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanSpecialSummonCount(tp, 2)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_XMATERIAL)
  			and Duel.IsExistingTarget(s.filter1, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 2, tp, LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) or tc:IsImmuneToEffect(e) then
  		return
  	end
  	if Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) == 0 then
  		return
  	end
  	if not aux.MustMaterialCheck(tc, tp, EFFECT_MUST_BE_XMATERIAL) 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:GetRank() * 2)
  	local sc = g:GetFirst()
  	if sc then
  		Duel.BreakEffect()
  		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
  
  