name: Ebon
card_text: 2 Level 7 Spellcaster monsters
  While this card has material, you can activate a Quick-Play Spell Card or a Trap Card from your hand during your opponent's turn by detaching 1 material from this card at activation. If this Xyz Summoned card is destroyed by battle and sent to the GY, or if this Xyz Summoned card you control is sent to your GY by an opponent's card effect: You can Special Summon 1 DARK Spellcaster monster from your hand or Deck, then you can destroy 1 card on the field.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, aux.FilterBoolFunction(Card.IsRace, RACE_SPELLCASTER), 7, 2)
  	c:EnableReviveLimit()
  	--act qp/trap in hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 2))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_QP_ACT_IN_NTPHAND)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_HAND, 0)
  	e1:SetCondition(s.handcon)
  	e1:SetCost(s.handcost)
  	e1:SetValue(id)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(id)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE + EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetRange(LOCATION_MZONE)
  	c:RegisterEffect(e3)
  	--spsummon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_TO_GRAVE)
  	e5:SetCondition(s.spcon)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.handcon(e)
  	return Duel.GetTurnPlayer() ~= e:GetHandlerPlayer()
  end
  function s.similarfilter(c, tp)
  	return c:IsHasEffect(id) and c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT)
  end
  function s.handcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT)
  	end
  	local g = Duel.GetMatchingGroup(s.similarfilter, tp, LOCATION_MZONE, 0, c, tp)
  	if #g > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DEATTACHFROM)
  		local tc = (g + c):Select(tp, 1, 1, nil):GetFirst()
  		tc:RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  	else
  		c:RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return ((rp == 1 - tp and c:IsReason(REASON_EFFECT) and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE)) or c:IsReason(REASON_BATTLE)) and c:IsSummonType(SUMMON_TYPE_XYZ)
  end
  function s.spfilter(c, e, tp)
  	return c:IsRace(RACE_SPELLCASTER) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	local dg = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	if g:GetCount() > 0 and Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP) ~= 0 and dg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local sg = dg:Select(tp, 1, 1, nil)
  		Duel.HintSelection(sg)
  		Duel.Destroy(sg, REASON_EFFECT)
  	end
  end
  
  
source_text: Ebon
  2 Level 7 Spellcaster monsters
  While this card has material, you can activate a Quick-Play Spell Card or a Trap Card from your hand during your opponent's turn by detaching 1 material from this card at activation. If this Xyz Summoned card is destroyed by battle and sent to the GY, or if this Xyz Summoned card you control is sent to your GY by an opponent's card effect: You can Special Summon 1 DARK Spellcaster monster from your hand or Deck, then you can destroy 1 card on the field.
target_text: -- Ebon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, aux.FilterBoolFunction(Card.IsRace, RACE_SPELLCASTER), 7, 2)
  	c:EnableReviveLimit()
  	--act qp/trap in hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 2))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_QP_ACT_IN_NTPHAND)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_HAND, 0)
  	e1:SetCondition(s.handcon)
  	e1:SetCost(s.handcost)
  	e1:SetValue(id)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(id)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE + EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetRange(LOCATION_MZONE)
  	c:RegisterEffect(e3)
  	--spsummon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_TO_GRAVE)
  	e5:SetCondition(s.spcon)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.handcon(e)
  	return Duel.GetTurnPlayer() ~= e:GetHandlerPlayer()
  end
  function s.similarfilter(c, tp)
  	return c:IsHasEffect(id) and c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT)
  end
  function s.handcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT)
  	end
  	local g = Duel.GetMatchingGroup(s.similarfilter, tp, LOCATION_MZONE, 0, c, tp)
  	if #g > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DEATTACHFROM)
  		local tc = (g + c):Select(tp, 1, 1, nil):GetFirst()
  		tc:RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  	else
  		c:RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return ((rp == 1 - tp and c:IsReason(REASON_EFFECT) and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE)) or c:IsReason(REASON_BATTLE)) and c:IsSummonType(SUMMON_TYPE_XYZ)
  end
  function s.spfilter(c, e, tp)
  	return c:IsRace(RACE_SPELLCASTER) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	local dg = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	if g:GetCount() > 0 and Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP) ~= 0 and dg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local sg = dg:Select(tp, 1, 1, nil)
  		Duel.HintSelection(sg)
  		Duel.Destroy(sg, REASON_EFFECT)
  	end
  end
  
  