name: Ruddy
card_text: You can Tribute this card; add 1 "Witch of the Black Rose" from your Deck to your hand, and if you do, take 1 Level 3 or lower Plant monster from your Deck and place it on top of your Deck, then immediately after this effect resolves, you can Normal Summon 1 "Witch of the Black Rose" from your hand. You can banish this card from your GY; return 1 of your "Black Rose Dragon" or "Ruddy Rose Dragon" that is banished or in your GY to the Extra Deck. You can only use each effect of "Ruddy Rose Witch" once per turn.
external_ids: local CARD_ID_0 = 73580471 --Black Rose Dragon
  local CARD_ID_1 = 40139997 --Ruddy Rose Dragon
  local CARD_ID_2 = 17720747 --Witch of the Black Rose
  
lua: local CARD_ID_0 = 73580471 --Black Rose Dragon
  local CARD_ID_1 = 40139997 --Ruddy Rose Dragon
  local CARD_ID_2 = 17720747 --Witch of the Black Rose
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.thcost)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--to extra
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOEXTRA)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.tetg)
  	e2:SetOperation(s.teop)
  	c:RegisterEffect(e2)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.thfilter(c, tp, solve)
  	return c:IsCode(CARD_ID_2) and c:IsAbleToHand() and (solve or Duel.IsExistingMatchingCard(s.dtfilter, tp, LOCATION_DECK, 0, 1, c))
  end
  function s.dtfilter(c)
  	return c:IsLevelBelow(3) and c:IsRace(RACE_PLANT)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_SUMMON, nil, 0, 0, 0)
  end
  function s.sumfilter(c)
  	return c:IsCode(CARD_ID_2) and c:IsSummonable(true, nil)
  end
  function s.thop(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, tp, true)
  	local tc = g:GetFirst()
  	if tc and Duel.SendtoHand(tc, nil, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_HAND) then
  		Duel.ConfirmCards(1 - tp, tc)
  		Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  		local dg = Duel.SelectMatchingCard(tp, s.dtfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		local dc = dg:GetFirst()
  		if dc then
  			Duel.ShuffleDeck(tp)
  			Duel.MoveSequence(dc, SEQ_DECKTOP)
  			Duel.ConfirmDecktop(tp, 1)
  			if Duel.IsExistingMatchingCard(s.sumfilter, tp, LOCATION_HAND, 0, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 3)) then
  				Duel.BreakEffect()
  				Duel.ShuffleHand(tp)
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SUMMON)
  				local sg = Duel.SelectMatchingCard(tp, s.sumfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  				local sc = sg:GetFirst()
  				if sc then
  					Duel.Summon(tp, sc, true, nil)
  				end
  			end
  		end
  	end
  end
  function s.tefilter(c)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsCode(CARD_ID_0, CARD_ID_1) and c:IsAbleToExtra()
  end
  function s.tetg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tefilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, e:GetHandler())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, nil, 1, tp, LOCATION_GRAVE + LOCATION_REMOVED)
  end
  function s.teop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.tefilter), tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  
source_text: Ruddy
  You can Tribute this card; add 1 "Witch of the Black Rose" from your Deck to your hand, and if you do, take 1 Level 3 or lower Plant monster from your Deck and place it on top of your Deck, then immediately after this effect resolves, you can Normal Summon 1 "Witch of the Black Rose" from your hand. You can banish this card from your GY; return 1 of your "Black Rose Dragon" or "Ruddy Rose Dragon" that is banished or in your GY to the Extra Deck. You can only use each effect of "Ruddy Rose Witch" once per turn.
target_text: -- Ruddy
  local CARD_ID_0 = 73580471 --Black Rose Dragon
  local CARD_ID_1 = 40139997 --Ruddy Rose Dragon
  local CARD_ID_2 = 17720747 --Witch of the Black Rose
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.thcost)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--to extra
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOEXTRA)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.tetg)
  	e2:SetOperation(s.teop)
  	c:RegisterEffect(e2)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.thfilter(c, tp, solve)
  	return c:IsCode(CARD_ID_2) and c:IsAbleToHand() and (solve or Duel.IsExistingMatchingCard(s.dtfilter, tp, LOCATION_DECK, 0, 1, c))
  end
  function s.dtfilter(c)
  	return c:IsLevelBelow(3) and c:IsRace(RACE_PLANT)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_SUMMON, nil, 0, 0, 0)
  end
  function s.sumfilter(c)
  	return c:IsCode(CARD_ID_2) and c:IsSummonable(true, nil)
  end
  function s.thop(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, tp, true)
  	local tc = g:GetFirst()
  	if tc and Duel.SendtoHand(tc, nil, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_HAND) then
  		Duel.ConfirmCards(1 - tp, tc)
  		Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  		local dg = Duel.SelectMatchingCard(tp, s.dtfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		local dc = dg:GetFirst()
  		if dc then
  			Duel.ShuffleDeck(tp)
  			Duel.MoveSequence(dc, SEQ_DECKTOP)
  			Duel.ConfirmDecktop(tp, 1)
  			if Duel.IsExistingMatchingCard(s.sumfilter, tp, LOCATION_HAND, 0, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 3)) then
  				Duel.BreakEffect()
  				Duel.ShuffleHand(tp)
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SUMMON)
  				local sg = Duel.SelectMatchingCard(tp, s.sumfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  				local sc = sg:GetFirst()
  				if sc then
  					Duel.Summon(tp, sc, true, nil)
  				end
  			end
  		end
  	end
  end
  function s.tefilter(c)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsCode(CARD_ID_0, CARD_ID_1) and c:IsAbleToExtra()
  end
  function s.tetg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tefilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, e:GetHandler())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, nil, 1, tp, LOCATION_GRAVE + LOCATION_REMOVED)
  end
  function s.teop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.tefilter), tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  