name: New
card_text: If your opponent Special Summons a Ritual, Fusion, Synchro, Xyz, and/or Link Monster(s) (except during the Damage Step): You can activate 1 of these effects;
  ● Add 1 "Fallen of Albaz", or 1 monster that mentions it, from your Deck to your hand.
  ● Special Summon 1 "Fallen of Albaz", or 1 monster that mentions it, from your hand.
  You can only use each effect of "New Frontier" once per turn.
external_ids: local CARD_ID_0 = 68468459 --Fallen of Albaz
  
lua: local CARD_ID_0 = 68468459 --Fallen of Albaz
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.condition)
  	e2:SetTarget(s.target)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c, sp)
  	return c:IsFaceup() and c:IsSummonPlayer(sp) and c:IsType(TYPE_RITUAL + TYPE_FUSION + TYPE_SYNCHRO + TYPE_XYZ + TYPE_LINK)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, 1 - tp)
  end
  function s.thfilter(c)
  	return (c:IsCode(CARD_ID_0) or aux.IsCodeListed(c, CARD_ID_0) and c:IsType(TYPE_MONSTER)) and c:IsAbleToHand()
  end
  function s.spfilter(c, e, tp)
  	return (c:IsCode(CARD_ID_0) or aux.IsCodeListed(c, CARD_ID_0) and c:IsType(TYPE_MONSTER)) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local l = Duel.GetFlagEffectLabel(tp, id)
  	local b1 = (not l or l & 1 == 0) and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	local b2 = (not l or l & 2 == 0) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EFFECT)
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	end
  	if op == 0 then
  		e:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  		e:SetOperation(s.thop)
  		if l then
  			Duel.SetFlagEffectLabel(tp, id, l | 1)
  		else
  			Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1, 1)
  		end
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	else
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		e:SetOperation(s.spop)
  		if l then
  			Duel.SetFlagEffectLabel(tp, id, l | 2)
  		else
  			Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1, 2)
  		end
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  	end
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.SendtoHand(g, nil, REASON_EFFECT)
  	Duel.ConfirmCards(1 - tp, g)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: New
  If your opponent Special Summons a Ritual, Fusion, Synchro, Xyz, and/or Link Monster(s) (except during the Damage Step): You can activate 1 of these effects;
  ● Add 1 "Fallen of Albaz", or 1 monster that mentions it, from your Deck to your hand.
  ● Special Summon 1 "Fallen of Albaz", or 1 monster that mentions it, from your hand.
  You can only use each effect of "New Frontier" once per turn.
target_text: -- New
  local CARD_ID_0 = 68468459 --Fallen of Albaz
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.condition)
  	e2:SetTarget(s.target)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c, sp)
  	return c:IsFaceup() and c:IsSummonPlayer(sp) and c:IsType(TYPE_RITUAL + TYPE_FUSION + TYPE_SYNCHRO + TYPE_XYZ + TYPE_LINK)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, 1 - tp)
  end
  function s.thfilter(c)
  	return (c:IsCode(CARD_ID_0) or aux.IsCodeListed(c, CARD_ID_0) and c:IsType(TYPE_MONSTER)) and c:IsAbleToHand()
  end
  function s.spfilter(c, e, tp)
  	return (c:IsCode(CARD_ID_0) or aux.IsCodeListed(c, CARD_ID_0) and c:IsType(TYPE_MONSTER)) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local l = Duel.GetFlagEffectLabel(tp, id)
  	local b1 = (not l or l & 1 == 0) and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	local b2 = (not l or l & 2 == 0) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EFFECT)
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	end
  	if op == 0 then
  		e:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  		e:SetOperation(s.thop)
  		if l then
  			Duel.SetFlagEffectLabel(tp, id, l | 1)
  		else
  			Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1, 1)
  		end
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	else
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		e:SetOperation(s.spop)
  		if l then
  			Duel.SetFlagEffectLabel(tp, id, l | 2)
  		else
  			Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1, 2)
  		end
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  	end
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.SendtoHand(g, nil, REASON_EFFECT)
  	Duel.ConfirmCards(1 - tp, g)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  