name: Speedroid
card_text: If this card is Normal or Special Summoned: You can excavate cards from the top of your Deck equal to the number of other WIND monsters you control, add 1 excavated card to your hand, also place the rest on the bottom of your Deck in any order. You can banish this card from your GY, then target 1 Level 3 or higher WIND monster you control; reduce its Level by 2. You can only use each effect of "Speedroid Fuki-Modoshi Piper" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--decrease level
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.target)
  	e3:SetOperation(s.operation)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsAttribute(ATTRIBUTE_WIND)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, e:GetHandler())
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) >= ct and Duel.GetDecktopGroup(tp, ct):IsExists(Card.IsAbleToHand, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, aux.ExceptThisCard(e))
  	Duel.ConfirmDecktop(tp, ct)
  	local g = Duel.GetDecktopGroup(tp, ct)
  	if #g > 0 then
  		Duel.DisableShuffleCheck()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sc = g:Select(tp, 1, 1, nil):GetFirst()
  		if sc:IsAbleToHand() then
  			Duel.SendtoHand(sc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sc)
  			Duel.ShuffleHand(tp)
  		else
  			Duel.SendtoGrave(sc, REASON_RULE)
  		end
  	end
  	if #g > 1 then
  		Duel.SortDecktop(tp, tp, #g - 1)
  		for i = 1, #g - 1 do
  			local dg = Duel.GetDecktopGroup(tp, 1)
  			Duel.MoveSequence(dg:GetFirst(), SEQ_DECKBOTTOM)
  		end
  	end
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLevelAbove(3) and c:IsAttribute(ATTRIBUTE_WIND)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(-2)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  
  
source_text: Speedroid
  If this card is Normal or Special Summoned: You can excavate cards from the top of your Deck equal to the number of other WIND monsters you control, add 1 excavated card to your hand, also place the rest on the bottom of your Deck in any order. You can banish this card from your GY, then target 1 Level 3 or higher WIND monster you control; reduce its Level by 2. You can only use each effect of "Speedroid Fuki-Modoshi Piper" once per turn.
target_text: -- Speedroid
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--decrease level
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.target)
  	e3:SetOperation(s.operation)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsAttribute(ATTRIBUTE_WIND)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, e:GetHandler())
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) >= ct and Duel.GetDecktopGroup(tp, ct):IsExists(Card.IsAbleToHand, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, aux.ExceptThisCard(e))
  	Duel.ConfirmDecktop(tp, ct)
  	local g = Duel.GetDecktopGroup(tp, ct)
  	if #g > 0 then
  		Duel.DisableShuffleCheck()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sc = g:Select(tp, 1, 1, nil):GetFirst()
  		if sc:IsAbleToHand() then
  			Duel.SendtoHand(sc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sc)
  			Duel.ShuffleHand(tp)
  		else
  			Duel.SendtoGrave(sc, REASON_RULE)
  		end
  	end
  	if #g > 1 then
  		Duel.SortDecktop(tp, tp, #g - 1)
  		for i = 1, #g - 1 do
  			local dg = Duel.GetDecktopGroup(tp, 1)
  			Duel.MoveSequence(dg:GetFirst(), SEQ_DECKBOTTOM)
  		end
  	end
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLevelAbove(3) and c:IsAttribute(ATTRIBUTE_WIND)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(-2)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  
  