name: Ma'at
card_text: Cannot be Normal Summoned/Set. Must be Special Summoned (from your hand) by sending 1 LIGHT Dragon-Type monster and 1 LIGHT Fairy-Type monster you control to the Graveyard, and cannot be Special Summoned by other ways. Once per turn: You can declare 3 card names; excavate the top 3 cards of your Deck, add any of them that you named to your hand, also send the remaining cards to the Graveyard. This card's ATK and DEF each become equal to the number of cards added to your hand by this effect x 1000.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.FALSE)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_SPSUMMON_PROC)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--announce 3 cards
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DECKDES + CATEGORY_ATKCHANGE)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.anctg)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c)
  	return c:IsFaceup() and c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsAbleToGraveAsCost()
  end
  function s.fselect(g, tp)
  	return aux.mzctcheck(g, tp) and aux.gfcheck(g, Card.IsRace, RACE_FAIRY, RACE_DRAGON)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_MZONE, 0, nil)
  	return g:CheckSubGroup(s.fselect, 2, 2, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:SelectSubGroup(tp, s.fselect, true, 2, 2, tp)
  	if sg then
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = e:GetLabelObject()
  	Duel.SendtoGrave(g, REASON_SPSUMMON)
  	g:DeleteGroup()
  end
  function s.anctg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if not Duel.IsPlayerCanDiscardDeck(tp, 3) then
  			return false
  		end
  		local g = Duel.GetDecktopGroup(tp, 3)
  		return g:FilterCount(Card.IsAbleToHand, nil) > 0
  	end
  	getmetatable(e:GetHandler()).announce_filter = { TYPE_FUSION + TYPE_SYNCHRO + TYPE_XYZ + TYPE_LINK, OPCODE_ISTYPE, OPCODE_NOT }
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CODE)
  	local ac1 = Duel.AnnounceCard(tp, table.unpack(getmetatable(e:GetHandler()).announce_filter))
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CODE)
  	local ac2 = Duel.AnnounceCard(tp, table.unpack(getmetatable(e:GetHandler()).announce_filter))
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CODE)
  	local ac3 = Duel.AnnounceCard(tp, table.unpack(getmetatable(e:GetHandler()).announce_filter))
  	e:SetOperation(s.retop(ac1, ac2, ac3))
  end
  function s.hfilter(c, code1, code2, code3)
  	return c:IsCode(code1, code2, code3) and c:IsAbleToHand()
  end
  function s.retop(code1, code2, code3)
  	return function(e, tp, eg, ep, ev, re, r, rp)
  		if not Duel.IsPlayerCanDiscardDeck(tp, 3) then
  			return
  		end
  		local c = e:GetHandler()
  		Duel.ConfirmDecktop(tp, 3)
  		local g = Duel.GetDecktopGroup(tp, 3)
  		local hg = g:Filter(s.hfilter, nil, code1, code2, code3)
  		g:Sub(hg)
  		if hg:GetCount() ~= 0 then
  			Duel.DisableShuffleCheck()
  			Duel.SendtoHand(hg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, hg)
  			Duel.ShuffleHand(tp)
  		end
  		if g:GetCount() ~= 0 then
  			Duel.DisableShuffleCheck()
  			Duel.SendtoGrave(g, REASON_EFFECT + REASON_REVEAL)
  		end
  		if c:IsRelateToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetValue(hg:GetCount() * 1000)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  			c:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetCode(EFFECT_SET_DEFENSE_FINAL)
  			c:RegisterEffect(e2)
  		end
  	end
  end
  
  
source_text: Ma'at
  Cannot be Normal Summoned/Set. Must be Special Summoned (from your hand) by sending 1 LIGHT Dragon-Type monster and 1 LIGHT Fairy-Type monster you control to the Graveyard, and cannot be Special Summoned by other ways. Once per turn: You can declare 3 card names; excavate the top 3 cards of your Deck, add any of them that you named to your hand, also send the remaining cards to the Graveyard. This card's ATK and DEF each become equal to the number of cards added to your hand by this effect x 1000.
target_text: -- Ma'at
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.FALSE)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_SPSUMMON_PROC)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--announce 3 cards
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DECKDES + CATEGORY_ATKCHANGE)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.anctg)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c)
  	return c:IsFaceup() and c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsAbleToGraveAsCost()
  end
  function s.fselect(g, tp)
  	return aux.mzctcheck(g, tp) and aux.gfcheck(g, Card.IsRace, RACE_FAIRY, RACE_DRAGON)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_MZONE, 0, nil)
  	return g:CheckSubGroup(s.fselect, 2, 2, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:SelectSubGroup(tp, s.fselect, true, 2, 2, tp)
  	if sg then
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = e:GetLabelObject()
  	Duel.SendtoGrave(g, REASON_SPSUMMON)
  	g:DeleteGroup()
  end
  function s.anctg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if not Duel.IsPlayerCanDiscardDeck(tp, 3) then
  			return false
  		end
  		local g = Duel.GetDecktopGroup(tp, 3)
  		return g:FilterCount(Card.IsAbleToHand, nil) > 0
  	end
  	getmetatable(e:GetHandler()).announce_filter = { TYPE_FUSION + TYPE_SYNCHRO + TYPE_XYZ + TYPE_LINK, OPCODE_ISTYPE, OPCODE_NOT }
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CODE)
  	local ac1 = Duel.AnnounceCard(tp, table.unpack(getmetatable(e:GetHandler()).announce_filter))
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CODE)
  	local ac2 = Duel.AnnounceCard(tp, table.unpack(getmetatable(e:GetHandler()).announce_filter))
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CODE)
  	local ac3 = Duel.AnnounceCard(tp, table.unpack(getmetatable(e:GetHandler()).announce_filter))
  	e:SetOperation(s.retop(ac1, ac2, ac3))
  end
  function s.hfilter(c, code1, code2, code3)
  	return c:IsCode(code1, code2, code3) and c:IsAbleToHand()
  end
  function s.retop(code1, code2, code3)
  	return function(e, tp, eg, ep, ev, re, r, rp)
  		if not Duel.IsPlayerCanDiscardDeck(tp, 3) then
  			return
  		end
  		local c = e:GetHandler()
  		Duel.ConfirmDecktop(tp, 3)
  		local g = Duel.GetDecktopGroup(tp, 3)
  		local hg = g:Filter(s.hfilter, nil, code1, code2, code3)
  		g:Sub(hg)
  		if hg:GetCount() ~= 0 then
  			Duel.DisableShuffleCheck()
  			Duel.SendtoHand(hg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, hg)
  			Duel.ShuffleHand(tp)
  		end
  		if g:GetCount() ~= 0 then
  			Duel.DisableShuffleCheck()
  			Duel.SendtoGrave(g, REASON_EFFECT + REASON_REVEAL)
  		end
  		if c:IsRelateToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetValue(hg:GetCount() * 1000)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  			c:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetCode(EFFECT_SET_DEFENSE_FINAL)
  			c:RegisterEffect(e2)
  		end
  	end
  end
  
  