name: Dream
card_text: You can banish 2 face-down cards from your Extra Deck, face-down; add 2 Level 10 Beast monsters with different names from your Deck to your hand. You cannot Special Summon monsters from the Extra Deck the turn you activate this effect, except Pendulum Monsters. You can only use this effect of "Dream Tower of Princess Nemleria" once per turn. If a "Nemleria" monster(s) you control would be destroyed by battle or an opponent's card effect, while you have "Dreaming Nemleria" face-up in your Extra Deck, you can banish 1 face-down card from your Extra Deck face-down, instead.
external_ids: local CARD_ID_0 = 70155677 --Dreaming Nemleria
  local SETCARD_ID_0 = 0x191 --Nemleria
  
lua: local CARD_ID_0 = 70155677 --Dreaming Nemleria
  local SETCARD_ID_0 = 0x191 --Nemleria
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_SPSUMMON, s.counterfilter)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(s.repcon)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.counterfilter(c)
  	return not c:IsSummonLocation(LOCATION_EXTRA) or c:IsType(TYPE_PENDULUM)
  end
  function s.rmfilter(c)
  	return c:IsFacedown() and c:IsAbleToRemoveAsCost(POS_FACEDOWN)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local check = Duel.GetCustomActivityCount(id, tp, ACTIVITY_SPSUMMON) == 0
  	local g = Duel.GetMatchingGroup(s.rmfilter, tp, LOCATION_EXTRA, 0, nil)
  	if chk == 0 then
  		return #g >= 2 and check
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local rg = g:Select(tp, 2, 2, nil)
  	Duel.Remove(rg, POS_FACEDOWN, REASON_COST)
  end
  function s.splimit(e, c)
  	return c:IsLocation(LOCATION_EXTRA) and not c:IsType(TYPE_PENDULUM)
  end
  function s.filter(c)
  	return c:IsLevel(10) and c:IsRace(RACE_BEAST) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil)
  	if chk == 0 then
  		return g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 2, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil)
  	if g:GetClassCount(Card.GetCode) < 2 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	if not sg then
  		return
  	end
  	Duel.SendtoHand(sg, nil, REASON_EFFECT)
  	Duel.ConfirmCards(1 - tp, sg)
  end
  function s.reprmfilter(c, tp)
  	return c:IsFacedown() and c:IsAbleToRemove(tp, POS_FACEDOWN, REASON_EFFECT)
  end
  function s.repcon(e)
  	local tp = e:GetHandlerPlayer()
  	return Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceup, Card.IsCode), tp, LOCATION_EXTRA, 0, 1, nil, CARD_ID_0)
  end
  function s.repfilter(c, tp)
  	return not c:IsReason(REASON_REPLACE)
  		and c:IsFaceup()
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsControler(tp)
  		and c:IsSetCard(SETCARD_ID_0)
  		and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp))
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp) and Duel.IsExistingMatchingCard(s.reprmfilter, tp, LOCATION_EXTRA, 0, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_CARD, 0, id)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.reprmfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, tp)
  	Duel.Remove(g, POS_FACEDOWN, REASON_EFFECT + REASON_REPLACE)
  end
  
  
source_text: Dream
  You can banish 2 face-down cards from your Extra Deck, face-down; add 2 Level 10 Beast monsters with different names from your Deck to your hand. You cannot Special Summon monsters from the Extra Deck the turn you activate this effect, except Pendulum Monsters. You can only use this effect of "Dream Tower of Princess Nemleria" once per turn. If a "Nemleria" monster(s) you control would be destroyed by battle or an opponent's card effect, while you have "Dreaming Nemleria" face-up in your Extra Deck, you can banish 1 face-down card from your Extra Deck face-down, instead.
target_text: -- Dream
  local CARD_ID_0 = 70155677 --Dreaming Nemleria
  local SETCARD_ID_0 = 0x191 --Nemleria
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_SPSUMMON, s.counterfilter)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(s.repcon)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.counterfilter(c)
  	return not c:IsSummonLocation(LOCATION_EXTRA) or c:IsType(TYPE_PENDULUM)
  end
  function s.rmfilter(c)
  	return c:IsFacedown() and c:IsAbleToRemoveAsCost(POS_FACEDOWN)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local check = Duel.GetCustomActivityCount(id, tp, ACTIVITY_SPSUMMON) == 0
  	local g = Duel.GetMatchingGroup(s.rmfilter, tp, LOCATION_EXTRA, 0, nil)
  	if chk == 0 then
  		return #g >= 2 and check
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local rg = g:Select(tp, 2, 2, nil)
  	Duel.Remove(rg, POS_FACEDOWN, REASON_COST)
  end
  function s.splimit(e, c)
  	return c:IsLocation(LOCATION_EXTRA) and not c:IsType(TYPE_PENDULUM)
  end
  function s.filter(c)
  	return c:IsLevel(10) and c:IsRace(RACE_BEAST) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil)
  	if chk == 0 then
  		return g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 2, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil)
  	if g:GetClassCount(Card.GetCode) < 2 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	if not sg then
  		return
  	end
  	Duel.SendtoHand(sg, nil, REASON_EFFECT)
  	Duel.ConfirmCards(1 - tp, sg)
  end
  function s.reprmfilter(c, tp)
  	return c:IsFacedown() and c:IsAbleToRemove(tp, POS_FACEDOWN, REASON_EFFECT)
  end
  function s.repcon(e)
  	local tp = e:GetHandlerPlayer()
  	return Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceup, Card.IsCode), tp, LOCATION_EXTRA, 0, 1, nil, CARD_ID_0)
  end
  function s.repfilter(c, tp)
  	return not c:IsReason(REASON_REPLACE)
  		and c:IsFaceup()
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsControler(tp)
  		and c:IsSetCard(SETCARD_ID_0)
  		and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp))
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp) and Duel.IsExistingMatchingCard(s.reprmfilter, tp, LOCATION_EXTRA, 0, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_CARD, 0, id)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.reprmfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, tp)
  	Duel.Remove(g, POS_FACEDOWN, REASON_EFFECT + REASON_REPLACE)
  end
  
  