name: Virtual
card_text: Place 1 "Virtual World Gate" card from your Deck face-up in your Spell & Trap Zone, then you can apply any of the following effect(s) in sequence, based on the number of "Virtual World Gate" cards you control.
  ● 2+: All "Virtual World" monsters you control gain 200 ATK this turn.
  ● 3+: Send the top 3 cards of your Deck to the GY.
  ● 4: Special Summon up to 4 "Virtual World" monsters with different names from your Extra Deck.
  You can only activate 1 "Virtual World City - Kauwloon" per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 29724053 --Summon Gate
  local SETCARD_ID_0 = 0x114e --Virtual
  local SETCARD_ID_1 = 0x14e --Virtual
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 29724053 --Summon Gate
  local SETCARD_ID_0 = 0x114e --Virtual
  local SETCARD_ID_1 = 0x14e --Virtual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DECKDES + CATEGORY_TOGRAVE + CATEGORY_ATKCHANGE + CATEGORY_SPECIAL_SUMMON)
  	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.tffilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_1) and not c:IsType(TYPE_FIELD + TYPE_MONSTER) and not c:IsForbidden() and c:CheckUniqueOnField(tp)
  end
  function s.gtfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsFaceup()
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.exfilter1(c)
  	return c:IsFacedown() and c:IsType(TYPE_XYZ + TYPE_SYNCHRO + TYPE_FUSION)
  end
  function s.exfilter2(c)
  	return c:IsFaceup() and c:IsType(TYPE_PENDULUM) or c:IsFacedown() and c:IsType(TYPE_LINK)
  end
  function s.fselect(g, ft1, ft2, ect, ft)
  	return aux.dncheck(g) and #g <= ft and #g <= ect and g:FilterCount(s.exfilter1, nil) <= ft1 and g:FilterCount(s.exfilter2, nil) <= ft2
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  		if e:IsHasType(EFFECT_TYPE_ACTIVATE) and not e:GetHandler():IsLocation(LOCATION_SZONE) then
  			ft = ft - 1
  		end
  		return ft > 0 and Duel.IsExistingMatchingCard(s.tffilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local tc = Duel.SelectMatchingCard(tp, s.tffilter, tp, LOCATION_DECK, 0, 1, 1, nil, tp):GetFirst()
  	if tc then
  		if Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true) then
  			local gc = Duel.GetMatchingGroupCount(s.gtfilter, tp, LOCATION_ONFIELD, 0, nil)
  			if gc >= 2 and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  				Duel.BreakEffect()
  				local e1 = Effect.CreateEffect(e:GetHandler())
  				e1:SetType(EFFECT_TYPE_FIELD)
  				e1:SetCode(EFFECT_UPDATE_ATTACK)
  				e1:SetTargetRange(LOCATION_MZONE, 0)
  				e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_1))
  				e1:SetValue(200)
  				e1:SetReset(RESET_PHASE + PHASE_END)
  				Duel.RegisterEffect(e1, tp)
  			end
  			if gc >= 3 and Duel.IsPlayerCanDiscardDeck(tp, 3) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  				Duel.BreakEffect()
  				Duel.DiscardDeck(tp, 3, REASON_EFFECT)
  			end
  			if gc == 4 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp) then
  				local ft1 = Duel.GetLocationCountFromEx(tp, tp, nil, TYPE_XYZ + TYPE_SYNCHRO + TYPE_FUSION)
  				local ft2 = Duel.GetLocationCountFromEx(tp, tp, nil, TYPE_PENDULUM + TYPE_LINK)
  				local ft = Duel.GetUsableMZoneCount(tp)
  				if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  					if ft1 > 0 then
  						ft1 = 1
  					end
  					if ft2 > 0 then
  						ft2 = 1
  					end
  					if ft > 0 then
  						ft = 1
  					end
  				end
  				local ect = (c29724053 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1) and c29724053[tp]) or ft
  				if ect > 0 and (ft1 > 0 or ft2 > 0) and Duel.SelectYesNo(tp, aux.Stringid(id, 3)) then
  					Duel.BreakEffect()
  					local sg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_EXTRA, 0, nil, e, tp)
  					Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  					local rg = sg:SelectSubGroup(tp, s.fselect, false, 1, 4, ft1, ft2, ect, ft)
  					Duel.SpecialSummon(rg, 0, tp, tp, false, false, POS_FACEUP)
  				end
  			end
  		end
  	end
  end
  
  
source_text: Virtual
  Place 1 "Virtual World Gate" card from your Deck face-up in your Spell & Trap Zone, then you can apply any of the following effect(s) in sequence, based on the number of "Virtual World Gate" cards you control.
  ● 2+: All "Virtual World" monsters you control gain 200 ATK this turn.
  ● 3+: Send the top 3 cards of your Deck to the GY.
  ● 4: Special Summon up to 4 "Virtual World" monsters with different names from your Extra Deck.
  You can only activate 1 "Virtual World City - Kauwloon" per turn.
target_text: -- Virtual
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 29724053 --Summon Gate
  local SETCARD_ID_0 = 0x114e --Virtual
  local SETCARD_ID_1 = 0x14e --Virtual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DECKDES + CATEGORY_TOGRAVE + CATEGORY_ATKCHANGE + CATEGORY_SPECIAL_SUMMON)
  	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.tffilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_1) and not c:IsType(TYPE_FIELD + TYPE_MONSTER) and not c:IsForbidden() and c:CheckUniqueOnField(tp)
  end
  function s.gtfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsFaceup()
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.exfilter1(c)
  	return c:IsFacedown() and c:IsType(TYPE_XYZ + TYPE_SYNCHRO + TYPE_FUSION)
  end
  function s.exfilter2(c)
  	return c:IsFaceup() and c:IsType(TYPE_PENDULUM) or c:IsFacedown() and c:IsType(TYPE_LINK)
  end
  function s.fselect(g, ft1, ft2, ect, ft)
  	return aux.dncheck(g) and #g <= ft and #g <= ect and g:FilterCount(s.exfilter1, nil) <= ft1 and g:FilterCount(s.exfilter2, nil) <= ft2
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  		if e:IsHasType(EFFECT_TYPE_ACTIVATE) and not e:GetHandler():IsLocation(LOCATION_SZONE) then
  			ft = ft - 1
  		end
  		return ft > 0 and Duel.IsExistingMatchingCard(s.tffilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local tc = Duel.SelectMatchingCard(tp, s.tffilter, tp, LOCATION_DECK, 0, 1, 1, nil, tp):GetFirst()
  	if tc then
  		if Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true) then
  			local gc = Duel.GetMatchingGroupCount(s.gtfilter, tp, LOCATION_ONFIELD, 0, nil)
  			if gc >= 2 and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  				Duel.BreakEffect()
  				local e1 = Effect.CreateEffect(e:GetHandler())
  				e1:SetType(EFFECT_TYPE_FIELD)
  				e1:SetCode(EFFECT_UPDATE_ATTACK)
  				e1:SetTargetRange(LOCATION_MZONE, 0)
  				e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_1))
  				e1:SetValue(200)
  				e1:SetReset(RESET_PHASE + PHASE_END)
  				Duel.RegisterEffect(e1, tp)
  			end
  			if gc >= 3 and Duel.IsPlayerCanDiscardDeck(tp, 3) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  				Duel.BreakEffect()
  				Duel.DiscardDeck(tp, 3, REASON_EFFECT)
  			end
  			if gc == 4 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp) then
  				local ft1 = Duel.GetLocationCountFromEx(tp, tp, nil, TYPE_XYZ + TYPE_SYNCHRO + TYPE_FUSION)
  				local ft2 = Duel.GetLocationCountFromEx(tp, tp, nil, TYPE_PENDULUM + TYPE_LINK)
  				local ft = Duel.GetUsableMZoneCount(tp)
  				if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  					if ft1 > 0 then
  						ft1 = 1
  					end
  					if ft2 > 0 then
  						ft2 = 1
  					end
  					if ft > 0 then
  						ft = 1
  					end
  				end
  				local ect = (c29724053 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1) and c29724053[tp]) or ft
  				if ect > 0 and (ft1 > 0 or ft2 > 0) and Duel.SelectYesNo(tp, aux.Stringid(id, 3)) then
  					Duel.BreakEffect()
  					local sg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_EXTRA, 0, nil, e, tp)
  					Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  					local rg = sg:SelectSubGroup(tp, s.fselect, false, 1, 4, ft1, ft2, ect, ft)
  					Duel.SpecialSummon(rg, 0, tp, tp, false, false, POS_FACEUP)
  				end
  			end
  		end
  	end
  end
  
  