name: Enchanting
card_text: Pay 800 LP; excavate the top 4 cards of your Deck and Special Summon all excavated Level 3 or lower Normal Monsters, also, after that, shuffle the rest back into your Deck.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 63060238 --Elemental HERO Blazeman
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 63060238 --Elemental HERO Blazeman
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckLPCost(tp, 800)
  	end
  	Duel.PayLPCost(tp, 800)
  end
  function s.filter(c, e, tp)
  	return c:IsType(TYPE_NORMAL) and c:IsLevelBelow(3) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanSpecialSummon(tp)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1)
  			and Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 3
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ConfirmDecktop(tp, 4)
  	local g = Duel.GetDecktopGroup(tp, 4):Filter(s.filter, nil, e, tp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	if g:GetCount() > 0 then
  		if ft <= 0 then
  			Duel.SendtoGrave(g, REASON_RULE)
  		elseif ft >= g:GetCount() then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		else
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local sg = g:Select(tp, ft, ft, nil)
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  			g:Sub(sg)
  			Duel.SendtoGrave(g, REASON_RULE)
  		end
  	end
  	Duel.ShuffleDeck(tp)
  end
  
  
source_text: Enchanting
  Pay 800 LP; excavate the top 4 cards of your Deck and Special Summon all excavated Level 3 or lower Normal Monsters, also, after that, shuffle the rest back into your Deck.
target_text: -- Enchanting
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 63060238 --Elemental HERO Blazeman
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckLPCost(tp, 800)
  	end
  	Duel.PayLPCost(tp, 800)
  end
  function s.filter(c, e, tp)
  	return c:IsType(TYPE_NORMAL) and c:IsLevelBelow(3) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanSpecialSummon(tp)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1)
  			and Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 3
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ConfirmDecktop(tp, 4)
  	local g = Duel.GetDecktopGroup(tp, 4):Filter(s.filter, nil, e, tp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	if g:GetCount() > 0 then
  		if ft <= 0 then
  			Duel.SendtoGrave(g, REASON_RULE)
  		elseif ft >= g:GetCount() then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		else
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local sg = g:Select(tp, ft, ft, nil)
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  			g:Sub(sg)
  			Duel.SendtoGrave(g, REASON_RULE)
  		end
  	end
  	Duel.ShuffleDeck(tp)
  end
  
  