name: Chosen
card_text: This card gains these effects depending on the number of face-up "Zefra" monsters with different names in your Extra Deck.
  ● 3 or more: Monsters you control gain 100 ATK for each face-up card in any Extra Deck.
  ● 5 or more: Monsters you control cannot be destroyed by an opponent's card effects.
  ● 8 or more: Monsters you control cannot be targeted by an opponent's card effects.
  ● 10: You can send this card to the Graveyard; shuffle all cards from your opponent's hand, field, and Graveyard into the Deck.
external_ids: local SETCARD_ID_0 = 0xc4 --Zefra
  
lua: local SETCARD_ID_0 = 0xc4 --Zefra
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetCondition(aux.dscon)
  	c:RegisterEffect(e1)
  	--Atk up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetCondition(s.effcon)
  	e2:SetValue(s.atkval)
  	e2:SetLabel(3)
  	c:RegisterEffect(e2)
  	--indes
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e3:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetCondition(s.effcon)
  	e3:SetValue(aux.indoval)
  	e3:SetLabel(5)
  	c:RegisterEffect(e3)
  	--cannot be target
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e4:SetProperty(EFFECT_FLAG_SET_AVAILABLE + EFFECT_FLAG_IGNORE_IMMUNE)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, 0)
  	e4:SetCondition(s.effcon)
  	e4:SetValue(aux.tgoval)
  	e4:SetLabel(8)
  	c:RegisterEffect(e4)
  	--todeck
  	local e5 = Effect.CreateEffect(c)
  	e5:SetCategory(CATEGORY_TODECK)
  	e5:SetType(EFFECT_TYPE_QUICK_O)
  	e5:SetCode(EVENT_FREE_CHAIN)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCondition(s.tdcon)
  	e5:SetCost(s.tdcost)
  	e5:SetTarget(s.tdtg)
  	e5:SetOperation(s.tdop)
  	c:RegisterEffect(e5)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.effcon(e)
  	return Duel.GetMatchingGroup(s.cfilter, e:GetHandlerPlayer(), LOCATION_EXTRA, 0, nil):GetClassCount(Card.GetCode) >= e:GetLabel()
  end
  function s.atkval(e, c)
  	return Duel.GetMatchingGroupCount(Card.IsFaceup, 0, LOCATION_EXTRA, LOCATION_EXTRA, nil) * 100
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_EXTRA, 0, nil):GetClassCount(Card.GetCode) == 10
  end
  function s.tdcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToDeck, tp, 0, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE, nil)
  	if aux.NecroValleyNegateCheck(g) then
  		return
  	end
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  end
  
  
source_text: Chosen
  This card gains these effects depending on the number of face-up "Zefra" monsters with different names in your Extra Deck.
  ● 3 or more: Monsters you control gain 100 ATK for each face-up card in any Extra Deck.
  ● 5 or more: Monsters you control cannot be destroyed by an opponent's card effects.
  ● 8 or more: Monsters you control cannot be targeted by an opponent's card effects.
  ● 10: You can send this card to the Graveyard; shuffle all cards from your opponent's hand, field, and Graveyard into the Deck.
target_text: -- Chosen
  local SETCARD_ID_0 = 0xc4 --Zefra
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetCondition(aux.dscon)
  	c:RegisterEffect(e1)
  	--Atk up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetCondition(s.effcon)
  	e2:SetValue(s.atkval)
  	e2:SetLabel(3)
  	c:RegisterEffect(e2)
  	--indes
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e3:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetCondition(s.effcon)
  	e3:SetValue(aux.indoval)
  	e3:SetLabel(5)
  	c:RegisterEffect(e3)
  	--cannot be target
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e4:SetProperty(EFFECT_FLAG_SET_AVAILABLE + EFFECT_FLAG_IGNORE_IMMUNE)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, 0)
  	e4:SetCondition(s.effcon)
  	e4:SetValue(aux.tgoval)
  	e4:SetLabel(8)
  	c:RegisterEffect(e4)
  	--todeck
  	local e5 = Effect.CreateEffect(c)
  	e5:SetCategory(CATEGORY_TODECK)
  	e5:SetType(EFFECT_TYPE_QUICK_O)
  	e5:SetCode(EVENT_FREE_CHAIN)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCondition(s.tdcon)
  	e5:SetCost(s.tdcost)
  	e5:SetTarget(s.tdtg)
  	e5:SetOperation(s.tdop)
  	c:RegisterEffect(e5)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.effcon(e)
  	return Duel.GetMatchingGroup(s.cfilter, e:GetHandlerPlayer(), LOCATION_EXTRA, 0, nil):GetClassCount(Card.GetCode) >= e:GetLabel()
  end
  function s.atkval(e, c)
  	return Duel.GetMatchingGroupCount(Card.IsFaceup, 0, LOCATION_EXTRA, LOCATION_EXTRA, nil) * 100
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_EXTRA, 0, nil):GetClassCount(Card.GetCode) == 10
  end
  function s.tdcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToDeck, tp, 0, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_GRAVE, nil)
  	if aux.NecroValleyNegateCheck(g) then
  		return
  	end
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  end
  
  