name: Altergeist
card_text: You can Tribute this card; excavate the top 3 cards of your Deck, add 1 excavated "Altergeist" card to your hand, also send the rest to the GY. You can only use this effect of "Altergeist Pixiel" once per turn.
external_ids: local SETCARD_ID_0 = 0x103 --Altergeist
  
lua: local SETCARD_ID_0 = 0x103 --Altergeist
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--mill
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.cost(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.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeck(tp, 3) and Duel.GetDecktopGroup(tp, 3):FilterCount(Card.IsAbleToHand, nil) > 0
  	end
  end
  function s.filter(c)
  	return c:IsAbleToHand() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.IsPlayerCanDiscardDeck(tp, 3) then
  		return
  	end
  	Duel.ConfirmDecktop(tp, 3)
  	local g = Duel.GetDecktopGroup(tp, 3)
  	if g:GetCount() > 0 then
  		Duel.DisableShuffleCheck()
  		if g:IsExists(s.filter, 1, nil) then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local sg = g:FilterSelect(tp, s.filter, 1, 1, nil)
  			Duel.SendtoHand(sg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sg)
  			Duel.ShuffleHand(tp)
  			g:Sub(sg)
  		end
  		Duel.SendtoGrave(g, REASON_EFFECT + REASON_REVEAL)
  	end
  end
  
  
source_text: Altergeist
  You can Tribute this card; excavate the top 3 cards of your Deck, add 1 excavated "Altergeist" card to your hand, also send the rest to the GY. You can only use this effect of "Altergeist Pixiel" once per turn.
target_text: -- Altergeist
  local SETCARD_ID_0 = 0x103 --Altergeist
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--mill
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.cost(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.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeck(tp, 3) and Duel.GetDecktopGroup(tp, 3):FilterCount(Card.IsAbleToHand, nil) > 0
  	end
  end
  function s.filter(c)
  	return c:IsAbleToHand() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.IsPlayerCanDiscardDeck(tp, 3) then
  		return
  	end
  	Duel.ConfirmDecktop(tp, 3)
  	local g = Duel.GetDecktopGroup(tp, 3)
  	if g:GetCount() > 0 then
  		Duel.DisableShuffleCheck()
  		if g:IsExists(s.filter, 1, nil) then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local sg = g:FilterSelect(tp, s.filter, 1, 1, nil)
  			Duel.SendtoHand(sg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sg)
  			Duel.ShuffleHand(tp)
  			g:Sub(sg)
  		end
  		Duel.SendtoGrave(g, REASON_EFFECT + REASON_REVEAL)
  	end
  end
  
  