name: Level
card_text: Select 1 face-up "LV" monster on the field to activate this card. Return the selected card to its owner's Deck and Special Summon 1 monster from the owner's Graveyard to their side of the field with the same name but lower "LV" (ignoring the Summoning conditions).
external_ids: local SETCARD_ID_0 = 0x41 --LV
  
lua: local SETCARD_ID_0 = 0x41 --LV
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TODECK)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, e, tp)
  	if c:IsFacedown() or not c:IsSetCard(SETCARD_ID_0) or not c:IsAbleToDeck() then
  		return false
  	end
  	local op = c:GetOwner()
  	local locct = Duel.GetLocationCount(op, LOCATION_MZONE)
  	local cp = c:GetControler()
  	if op == cp and locct <= -1 then
  		return false
  	end
  	if op ~= cp and locct <= 0 then
  		return false
  	end
  	local code = c:GetCode()
  	local class = _G["c" .. code]
  	return class and class.lvdn ~= nil and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, class, e, tp, op)
  end
  function s.spfilter(c, class, e, tp, op)
  	if not c:IsControler(op) then
  		return false
  	end
  	local code = c:GetCode()
  	return c:IsCode(table.unpack(class.lvdn)) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false, POS_FACEUP, op)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local code = tc:GetCode()
  	local op = tc:GetOwner()
  	if not tc:IsRelateToEffect(e) or tc:IsFacedown() then
  		return
  	end
  	if Duel.SendtoDeck(tc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) == 0 then
  		return
  	end
  	if Duel.GetLocationCount(op, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local class = _G["c" .. code]
  	if class == nil or class.lvdn == nil then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil, class, e, tp, op)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, op, true, false, POS_FACEUP)
  	end
  end
  
  
source_text: Level
  Select 1 face-up "LV" monster on the field to activate this card. Return the selected card to its owner's Deck and Special Summon 1 monster from the owner's Graveyard to their side of the field with the same name but lower "LV" (ignoring the Summoning conditions).
target_text: -- Level
  local SETCARD_ID_0 = 0x41 --LV
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TODECK)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, e, tp)
  	if c:IsFacedown() or not c:IsSetCard(SETCARD_ID_0) or not c:IsAbleToDeck() then
  		return false
  	end
  	local op = c:GetOwner()
  	local locct = Duel.GetLocationCount(op, LOCATION_MZONE)
  	local cp = c:GetControler()
  	if op == cp and locct <= -1 then
  		return false
  	end
  	if op ~= cp and locct <= 0 then
  		return false
  	end
  	local code = c:GetCode()
  	local class = _G["c" .. code]
  	return class and class.lvdn ~= nil and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, class, e, tp, op)
  end
  function s.spfilter(c, class, e, tp, op)
  	if not c:IsControler(op) then
  		return false
  	end
  	local code = c:GetCode()
  	return c:IsCode(table.unpack(class.lvdn)) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false, POS_FACEUP, op)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local code = tc:GetCode()
  	local op = tc:GetOwner()
  	if not tc:IsRelateToEffect(e) or tc:IsFacedown() then
  		return
  	end
  	if Duel.SendtoDeck(tc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) == 0 then
  		return
  	end
  	if Duel.GetLocationCount(op, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local class = _G["c" .. code]
  	if class == nil or class.lvdn == nil then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil, class, e, tp, op)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, op, true, false, POS_FACEUP)
  	end
  end
  
  