name: Ketu
card_text: Add 1 "Dracotail" monster from your Deck to your hand, then if your opponent controls a monster, you can Fusion Summon 1 Dragon or Spellcaster monster from your Extra Deck, using monsters from your hand or field. You can only activate 1 "Ketu Dracotail" per turn.
external_ids: local SETCARD_ID_0 = 0x1c9 --Dracotail
  
lua: local SETCARD_ID_0 = 0x1c9 --Dracotail
  local s, id, o = GetID()
  function s.initial_effect(c)
  	local e0 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		matfilter = aux.NecroValleyFilter(),
  	})
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	e1:SetLabelObject(e0)
  	c:RegisterEffect(e1)
  end
  
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  
  function s.fusfilter(c)
  	return c:IsRace(RACE_DRAGON + RACE_SPELLCASTER)
  end
  
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  		Duel.AdjustAll()
  		if Duel.IsExistingMatchingCard(aux.TRUE, tp, 0, LOCATION_MZONE, 1, nil) then
  			local fusion_effect = e:GetLabelObject()
  			if fusion_effect:GetTarget()(e, tp, eg, ep, ev, re, r, rp, 0) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  				Duel.BreakEffect()
  				Duel.ShuffleHand(tp)
  				fusion_effect:GetOperation()(e, tp, eg, ep, ev, re, r, rp)
  			end
  		end
  	end
  end
  
  
source_text: Ketu
  Add 1 "Dracotail" monster from your Deck to your hand, then if your opponent controls a monster, you can Fusion Summon 1 Dragon or Spellcaster monster from your Extra Deck, using monsters from your hand or field. You can only activate 1 "Ketu Dracotail" per turn.
target_text: -- Ketu
  local SETCARD_ID_0 = 0x1c9 --Dracotail
  local s, id, o = GetID()
  function s.initial_effect(c)
  	local e0 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		matfilter = aux.NecroValleyFilter(),
  	})
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	e1:SetLabelObject(e0)
  	c:RegisterEffect(e1)
  end
  
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  
  function s.fusfilter(c)
  	return c:IsRace(RACE_DRAGON + RACE_SPELLCASTER)
  end
  
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  		Duel.AdjustAll()
  		if Duel.IsExistingMatchingCard(aux.TRUE, tp, 0, LOCATION_MZONE, 1, nil) then
  			local fusion_effect = e:GetLabelObject()
  			if fusion_effect:GetTarget()(e, tp, eg, ep, ev, re, r, rp, 0) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  				Duel.BreakEffect()
  				Duel.ShuffleHand(tp)
  				fusion_effect:GetOperation()(e, tp, eg, ep, ev, re, r, rp)
  			end
  		end
  	end
  end
  
  