name: Virtual
card_text: You can target 1 face-up card on the field; shuffle 2 of your banished "Virtual World" cards with different names from each other into the Deck, then destroy that card. During your Main Phase: You can banish this card from your GY, then target 1 "Virtual World" monster you control; increase or decrease its Level/Rank by 3 until the end of this turn. You can only use each effect of "Virtual World Gate - Chuche" once per turn.
external_ids: local SETCARD_ID_0 = 0x14e --Virtual
  
lua: local SETCARD_ID_0 = 0x14e --Virtual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_TODECK)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	--tohand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.lvcon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.lvtg)
  	e3:SetOperation(s.lvop)
  	c:RegisterEffect(e3)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck() and c:IsFaceup()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_REMOVED, 0, nil)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsFaceup()
  	end
  	local xg = nil
  	if not e:GetHandler():IsStatus(STATUS_EFFECT_ENABLED) then
  		xg = e:GetHandler()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, xg) and g:CheckSubGroup(aux.dncheck, 2, 2)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local tg = Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, xg)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, tg, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 2, tp, LOCATION_REMOVED)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_REMOVED, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local sg = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	if sg then
  		Duel.HintSelection(sg)
  		if Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and sg:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK + LOCATION_EXTRA) and tc:IsRelateToEffect(e) then
  			Duel.Destroy(tc, REASON_EFFECT)
  		end
  	end
  end
  function s.lvcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp and (Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2)
  end
  function s.lvfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsFaceup() and (c:GetLevel() > 0 or c:GetRank() > 0)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.lvfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local sel = 0
  		local lvl = 3
  		if tc:IsLevelBelow(3) or tc:IsRankBelow(3) then
  			sel = Duel.SelectOption(tp, aux.Stringid(id, 2))
  		else
  			sel = Duel.SelectOption(tp, aux.Stringid(id, 2), aux.Stringid(id, 3))
  		end
  		if sel == 1 then
  			lvl = -3
  		end
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(lvl)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_UPDATE_RANK)
  		e2:SetValue(lvl)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e2)
  	end
  end
  
  
source_text: Virtual
  You can target 1 face-up card on the field; shuffle 2 of your banished "Virtual World" cards with different names from each other into the Deck, then destroy that card. During your Main Phase: You can banish this card from your GY, then target 1 "Virtual World" monster you control; increase or decrease its Level/Rank by 3 until the end of this turn. You can only use each effect of "Virtual World Gate - Chuche" once per turn.
target_text: -- Virtual
  local SETCARD_ID_0 = 0x14e --Virtual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_TODECK)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	--tohand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.lvcon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.lvtg)
  	e3:SetOperation(s.lvop)
  	c:RegisterEffect(e3)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck() and c:IsFaceup()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_REMOVED, 0, nil)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsFaceup()
  	end
  	local xg = nil
  	if not e:GetHandler():IsStatus(STATUS_EFFECT_ENABLED) then
  		xg = e:GetHandler()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, xg) and g:CheckSubGroup(aux.dncheck, 2, 2)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local tg = Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, xg)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, tg, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 2, tp, LOCATION_REMOVED)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_REMOVED, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local sg = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  	if sg then
  		Duel.HintSelection(sg)
  		if Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and sg:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK + LOCATION_EXTRA) and tc:IsRelateToEffect(e) then
  			Duel.Destroy(tc, REASON_EFFECT)
  		end
  	end
  end
  function s.lvcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp and (Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2)
  end
  function s.lvfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsFaceup() and (c:GetLevel() > 0 or c:GetRank() > 0)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.lvfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local sel = 0
  		local lvl = 3
  		if tc:IsLevelBelow(3) or tc:IsRankBelow(3) then
  			sel = Duel.SelectOption(tp, aux.Stringid(id, 2))
  		else
  			sel = Duel.SelectOption(tp, aux.Stringid(id, 2), aux.Stringid(id, 3))
  		end
  		if sel == 1 then
  			lvl = -3
  		end
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(lvl)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_UPDATE_RANK)
  		e2:SetValue(lvl)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e2)
  	end
  end
  
  