name: Vaalmonica
card_text: Apply 1 of these effects.
  ● Special Summon 1 "Vaalmonica" monster from your Deck, also for the rest of this turn after this card resolves, you cannot activate the effects of monsters on the field, except "Vaalmonica" monsters.
  ● If you control a non-Pendulum "Vaalmonica" monster, take 2 "Vaalmonica" Pendulum Monsters with different names from your Deck, add 1 of them to your hand, and add the other to your face-up Extra Deck.
  You can only activate 1 "Vaalmonica Invitare" per turn.
external_ids: local SETCARD_ID_0 = 0x1a3 --Vaalmonica
  
lua: local SETCARD_ID_0 = 0x1a3 --Vaalmonica
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOEXTRA + CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.thfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and (c:IsAbleToExtra() or c:IsAbleToHand())
  end
  function s.cfilter(c)
  	return not c:IsType(TYPE_PENDULUM) and c:IsSetCard(SETCARD_ID_0) and c:IsFaceup()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	local b1 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	local b2 = g:CheckSubGroup(s.Group, 2, 2) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	if chk == 0 then
  		return b1 or b2
  	end
  end
  function s.thfilter2(c, g)
  	return c:IsAbleToExtra() and g:FilterCount(Card.IsAbleToHand, c) == 1
  end
  function s.Group(g)
  	return aux.dncheck(g) and g:FilterCount(s.thfilter2, nil, g) ~= 0
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	local b1 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	local b2 = g:CheckSubGroup(s.Group, 2, 2) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2)) + 1
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	elseif b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 2
  	end
  	if op == 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  		if sg:GetCount() > 0 then
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  		end
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  		e1:SetTargetRange(1, 0)
  		e1:SetValue(s.aclimit)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	elseif op == 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:SelectSubGroup(tp, s.Group, false, 2, 2)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local tc = sg:FilterSelect(tp, Card.IsAbleToHand, 1, 1, nil):GetFirst()
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tc)
  		sg:RemoveCard(tc)
  		Duel.SendtoExtraP(sg, nil, REASON_EFFECT)
  	end
  end
  function s.aclimit(e, re, tp)
  	local c = re:GetHandler()
  	return not c:IsSetCard(SETCARD_ID_0) and re:IsActiveType(TYPE_MONSTER) and c:IsLocation(LOCATION_MZONE)
  end
  
  
source_text: Vaalmonica
  Apply 1 of these effects.
  ● Special Summon 1 "Vaalmonica" monster from your Deck, also for the rest of this turn after this card resolves, you cannot activate the effects of monsters on the field, except "Vaalmonica" monsters.
  ● If you control a non-Pendulum "Vaalmonica" monster, take 2 "Vaalmonica" Pendulum Monsters with different names from your Deck, add 1 of them to your hand, and add the other to your face-up Extra Deck.
  You can only activate 1 "Vaalmonica Invitare" per turn.
target_text: -- Vaalmonica
  local SETCARD_ID_0 = 0x1a3 --Vaalmonica
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOEXTRA + CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.thfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and (c:IsAbleToExtra() or c:IsAbleToHand())
  end
  function s.cfilter(c)
  	return not c:IsType(TYPE_PENDULUM) and c:IsSetCard(SETCARD_ID_0) and c:IsFaceup()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	local b1 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	local b2 = g:CheckSubGroup(s.Group, 2, 2) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	if chk == 0 then
  		return b1 or b2
  	end
  end
  function s.thfilter2(c, g)
  	return c:IsAbleToExtra() and g:FilterCount(Card.IsAbleToHand, c) == 1
  end
  function s.Group(g)
  	return aux.dncheck(g) and g:FilterCount(s.thfilter2, nil, g) ~= 0
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	local b1 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	local b2 = g:CheckSubGroup(s.Group, 2, 2) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2)) + 1
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	elseif b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 2
  	end
  	if op == 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  		if sg:GetCount() > 0 then
  			Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  		end
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  		e1:SetTargetRange(1, 0)
  		e1:SetValue(s.aclimit)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	elseif op == 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:SelectSubGroup(tp, s.Group, false, 2, 2)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local tc = sg:FilterSelect(tp, Card.IsAbleToHand, 1, 1, nil):GetFirst()
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tc)
  		sg:RemoveCard(tc)
  		Duel.SendtoExtraP(sg, nil, REASON_EFFECT)
  	end
  end
  function s.aclimit(e, re, tp)
  	local c = re:GetHandler()
  	return not c:IsSetCard(SETCARD_ID_0) and re:IsActiveType(TYPE_MONSTER) and c:IsLocation(LOCATION_MZONE)
  end
  
  