name: Exosisters
card_text: 2 Rank 4 "Exosister" Xyz Monsters
  Must be Xyz Summoned with the above materials. Can make a second attack during each Battle Phase. Once per turn (Quick Effect): You can detach 1 material from this card; banish 1 card your opponent controls. When your opponent activates a card or effect (Quick Effect): You can return 1 Xyz Monster you own attached to this card to your Extra Deck, then you can Special Summon that monster from your Extra Deck, by using this card you control as material. (This is treated as an Xyz Summon. Transfer this card's materials to the Summoned monster.)
external_ids: local SETCARD_ID_0 = 0x172 --Exosister
  
lua: local SETCARD_ID_0 = 0x172 --Exosister
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	c:EnableReviveLimit()
  	aux.AddXyzProcedureLevelFree(c, s.mfilter, nil, 2, 2)
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.FALSE)
  	c:RegisterEffect(e1)
  	--extra attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_EXTRA_ATTACK)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--remove
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e3:SetCost(s.rmcost)
  	e3:SetTarget(s.rmtg)
  	e3:SetOperation(s.rmop)
  	c:RegisterEffect(e3)
  	--spsummon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_TOEXTRA + CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_CHAINING)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.mfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsRank(4)
  end
  function s.rmcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, 1 - tp, LOCATION_ONFIELD)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, 0, LOCATION_ONFIELD, nil)
  	if g:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.HintSelection(sg)
  		Duel.Remove(sg, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED)
  end
  function s.toexfilter(c, tp)
  	return c:IsType(TYPE_XYZ) and c:IsAbleToExtra() and c:GetOwner() == tp
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local g = c:GetOverlayGroup()
  	if chk == 0 then
  		return g:IsExists(s.toexfilter, 1, nil, tp)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = c:GetOverlayGroup()
  	if c:IsRelateToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local sc = g:FilterSelect(tp, s.toexfilter, 1, 1, nil, tp):GetFirst()
  		if
  			sc
  			and Duel.SendtoDeck(sc, nil, 0, REASON_EFFECT) > 0
  			and sc:IsLocation(LOCATION_EXTRA)
  			and c:IsFaceup()
  			and c:IsControler(tp)
  			and not c:IsImmuneToEffect(e)
  			and aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_XMATERIAL)
  			and c:IsCanBeXyzMaterial(sc)
  			and sc:IsCanBeSpecialSummoned(e, SUMMON_TYPE_XYZ, tp, false, false)
  			and Duel.GetLocationCountFromEx(tp, tp, c, sc) > 0
  			and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  		then
  			Duel.BreakEffect()
  			local mg = c:GetOverlayGroup()
  			if mg:GetCount() ~= 0 then
  				Duel.Overlay(sc, mg)
  			end
  			sc:SetMaterial(Group.FromCards(c))
  			Duel.Overlay(sc, Group.FromCards(c))
  			Duel.SpecialSummon(sc, SUMMON_TYPE_XYZ, tp, tp, false, false, POS_FACEUP)
  			sc:CompleteProcedure()
  		end
  	end
  end
  
  
source_text: Exosisters
  2 Rank 4 "Exosister" Xyz Monsters
  Must be Xyz Summoned with the above materials. Can make a second attack during each Battle Phase. Once per turn (Quick Effect): You can detach 1 material from this card; banish 1 card your opponent controls. When your opponent activates a card or effect (Quick Effect): You can return 1 Xyz Monster you own attached to this card to your Extra Deck, then you can Special Summon that monster from your Extra Deck, by using this card you control as material. (This is treated as an Xyz Summon. Transfer this card's materials to the Summoned monster.)
target_text: -- Exosisters
  local SETCARD_ID_0 = 0x172 --Exosister
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	c:EnableReviveLimit()
  	aux.AddXyzProcedureLevelFree(c, s.mfilter, nil, 2, 2)
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.FALSE)
  	c:RegisterEffect(e1)
  	--extra attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_EXTRA_ATTACK)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--remove
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e3:SetCost(s.rmcost)
  	e3:SetTarget(s.rmtg)
  	e3:SetOperation(s.rmop)
  	c:RegisterEffect(e3)
  	--spsummon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_TOEXTRA + CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_CHAINING)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.mfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsRank(4)
  end
  function s.rmcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, 1 - tp, LOCATION_ONFIELD)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, 0, LOCATION_ONFIELD, nil)
  	if g:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.HintSelection(sg)
  		Duel.Remove(sg, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED)
  end
  function s.toexfilter(c, tp)
  	return c:IsType(TYPE_XYZ) and c:IsAbleToExtra() and c:GetOwner() == tp
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local g = c:GetOverlayGroup()
  	if chk == 0 then
  		return g:IsExists(s.toexfilter, 1, nil, tp)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = c:GetOverlayGroup()
  	if c:IsRelateToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local sc = g:FilterSelect(tp, s.toexfilter, 1, 1, nil, tp):GetFirst()
  		if
  			sc
  			and Duel.SendtoDeck(sc, nil, 0, REASON_EFFECT) > 0
  			and sc:IsLocation(LOCATION_EXTRA)
  			and c:IsFaceup()
  			and c:IsControler(tp)
  			and not c:IsImmuneToEffect(e)
  			and aux.MustMaterialCheck(c, tp, EFFECT_MUST_BE_XMATERIAL)
  			and c:IsCanBeXyzMaterial(sc)
  			and sc:IsCanBeSpecialSummoned(e, SUMMON_TYPE_XYZ, tp, false, false)
  			and Duel.GetLocationCountFromEx(tp, tp, c, sc) > 0
  			and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  		then
  			Duel.BreakEffect()
  			local mg = c:GetOverlayGroup()
  			if mg:GetCount() ~= 0 then
  				Duel.Overlay(sc, mg)
  			end
  			sc:SetMaterial(Group.FromCards(c))
  			Duel.Overlay(sc, Group.FromCards(c))
  			Duel.SpecialSummon(sc, SUMMON_TYPE_XYZ, tp, tp, false, false, POS_FACEUP)
  			sc:CompleteProcedure()
  		end
  	end
  end
  
  