name: Ryzeal
card_text: Target face-up cards your opponent controls, up to the number of "Ryzeal" Xyz Monsters you control; destroy them, then you can attach 1 "Ryzeal" card from your GY to 1 Rank 4 Xyz Monster you control. You can banish this card from your GY; immediately after this effect resolves, Xyz Summon 1 Xyz Monster using monsters you control, including a "Ryzeal" monster. You can only use each effect of "Ryzeal Plasma Hole" once per turn.
external_ids: local SETCARD_ID_0 = 0x1be --Ryzeal
  
lua: local SETCARD_ID_0 = 0x1be --Ryzeal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--xyz
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e2:SetCountLimit(1, id + o)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.xyztg)
  	e2:SetOperation(s.xyzop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp)
  	end
  	local gc = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return gc > 0 and Duel.IsExistingTarget(Card.IsFaceup, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local sg = Duel.SelectTarget(tp, Card.IsFaceup, tp, 0, LOCATION_ONFIELD, 1, gc, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, sg, sg:GetCount(), 0, 0)
  end
  function s.xyzfilter(c, e, tp)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and c:IsRank(4) and Duel.IsExistingMatchingCard(aux.NecroValleyFilter(s.mtfilter), tp, LOCATION_GRAVE, 0, 1, nil, e)
  end
  function s.mtfilter(c, e)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanOverlay() and not (e and c:IsImmuneToEffect(e))
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 and Duel.Destroy(tg, REASON_EFFECT) ~= 0 and Duel.IsExistingMatchingCard(s.xyzfilter, tp, LOCATION_MZONE, 0, 1, nil, e, tp) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  		Duel.BreakEffect()
  		local g = Duel.SelectMatchingCard(tp, s.xyzfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  		local xc = g:GetFirst()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local mg = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.mtfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e)
  		if mg:GetCount() > 0 then
  			Duel.Overlay(xc, mg)
  		end
  	end
  end
  function s.filter(c)
  	return c:IsCanOverlay() and c:IsFaceup()
  end
  function s.xyztg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local mg = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.xyzfilter2, tp, LOCATION_EXTRA, 0, 1, nil, mg)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.xyzfilter2(c, mg)
  	return c:IsType(TYPE_XYZ) and mg:CheckSubGroup(s.gselect, 1, #mg, c)
  end
  function s.gselect(sg, c)
  	return sg:IsExists(Card.IsSetCard, 1, nil, 0x1be) and c:IsXyzSummonable(sg, #sg, #sg)
  end
  function s.xyzop(e, tp, eg, ep, ev, re, r, rp)
  	local mg = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, 0, nil)
  	local exg = Duel.GetMatchingGroup(s.xyzfilter2, tp, LOCATION_EXTRA, 0, nil, mg)
  	if exg:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local tg = exg:Select(tp, 1, 1, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local sg = mg:SelectSubGroup(tp, s.gselect, false, 1, mg:GetCount(), tg:GetFirst())
  		Duel.XyzSummon(tp, tg:GetFirst(), sg, #sg, #sg)
  	end
  end
  
  
source_text: Ryzeal
  Target face-up cards your opponent controls, up to the number of "Ryzeal" Xyz Monsters you control; destroy them, then you can attach 1 "Ryzeal" card from your GY to 1 Rank 4 Xyz Monster you control. You can banish this card from your GY; immediately after this effect resolves, Xyz Summon 1 Xyz Monster using monsters you control, including a "Ryzeal" monster. You can only use each effect of "Ryzeal Plasma Hole" once per turn.
target_text: -- Ryzeal
  local SETCARD_ID_0 = 0x1be --Ryzeal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--xyz
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e2:SetCountLimit(1, id + o)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.xyztg)
  	e2:SetOperation(s.xyzop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp)
  	end
  	local gc = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return gc > 0 and Duel.IsExistingTarget(Card.IsFaceup, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local sg = Duel.SelectTarget(tp, Card.IsFaceup, tp, 0, LOCATION_ONFIELD, 1, gc, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, sg, sg:GetCount(), 0, 0)
  end
  function s.xyzfilter(c, e, tp)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and c:IsRank(4) and Duel.IsExistingMatchingCard(aux.NecroValleyFilter(s.mtfilter), tp, LOCATION_GRAVE, 0, 1, nil, e)
  end
  function s.mtfilter(c, e)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanOverlay() and not (e and c:IsImmuneToEffect(e))
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 and Duel.Destroy(tg, REASON_EFFECT) ~= 0 and Duel.IsExistingMatchingCard(s.xyzfilter, tp, LOCATION_MZONE, 0, 1, nil, e, tp) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  		Duel.BreakEffect()
  		local g = Duel.SelectMatchingCard(tp, s.xyzfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  		local xc = g:GetFirst()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local mg = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.mtfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e)
  		if mg:GetCount() > 0 then
  			Duel.Overlay(xc, mg)
  		end
  	end
  end
  function s.filter(c)
  	return c:IsCanOverlay() and c:IsFaceup()
  end
  function s.xyztg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local mg = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.xyzfilter2, tp, LOCATION_EXTRA, 0, 1, nil, mg)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.xyzfilter2(c, mg)
  	return c:IsType(TYPE_XYZ) and mg:CheckSubGroup(s.gselect, 1, #mg, c)
  end
  function s.gselect(sg, c)
  	return sg:IsExists(Card.IsSetCard, 1, nil, 0x1be) and c:IsXyzSummonable(sg, #sg, #sg)
  end
  function s.xyzop(e, tp, eg, ep, ev, re, r, rp)
  	local mg = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, 0, nil)
  	local exg = Duel.GetMatchingGroup(s.xyzfilter2, tp, LOCATION_EXTRA, 0, nil, mg)
  	if exg:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local tg = exg:Select(tp, 1, 1, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local sg = mg:SelectSubGroup(tp, s.gselect, false, 1, mg:GetCount(), tg:GetFirst())
  		Duel.XyzSummon(tp, tg:GetFirst(), sg, #sg, #sg)
  	end
  end
  
  