name: 死霊の巣
card_text: 自分の墓地に存在するモンスターを任意の枚数ゲームから除外する事で、その枚数と同じレベルを持つフィールド上に表側表示で存在するモンスター1体を破壊する。
lua: 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)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e2:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e2:SetCost(s.cost)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.tfilter(c, lv)
  	return c:IsFaceup() and c:IsLevelBelow(lv)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local cg = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_GRAVE, 0, nil)
  		local tg = Duel.GetMatchingGroup(s.tfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, cg:GetCount())
  		return tg:GetCount() > 0
  	end
  	e:SetLabel(0)
  	local cg = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_GRAVE, 0, nil)
  	local tg = Duel.GetMatchingGroup(s.tfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, cg:GetCount())
  	local lvt = {}
  	local tc = tg:GetFirst()
  	while tc do
  		local tlv = tc:GetLevel()
  		lvt[tlv] = tlv
  		tc = tg:GetNext()
  	end
  	local pc = 1
  	local _, lvmax = tg:GetMaxGroup(Card.GetLevel)
  	local max = math.min(lvmax, 255)
  	for i = 1, max do
  		if lvt[i] then
  			lvt[i] = nil
  			lvt[pc] = i
  			pc = pc + 1
  		end
  	end
  	lvt[pc] = nil
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	local lv = Duel.AnnounceNumber(tp, table.unpack(lvt))
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local rg = cg:Select(tp, lv, lv, nil)
  	Duel.Remove(rg, POS_FACEUP, REASON_COST)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, tg, 1, 0, 0)
  	Duel.SetTargetParam(lv)
  end
  function s.dfilter(c, lv)
  	return c:IsFaceup() and c:IsLevel(lv)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local lv = Duel.GetChainInfo(0, CHAININFO_TARGET_PARAM)
  	if lv == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, s.dfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, lv)
  	Duel.Destroy(g, REASON_EFFECT)
  end
  
  
source_text: 死霊の巣
  自分の墓地に存在するモンスターを任意の枚数ゲームから除外する事で、その枚数と同じレベルを持つフィールド上に表側表示で存在するモンスター1体を破壊する。
target_text: -- 死霊の巣
  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)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e2:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e2:SetCost(s.cost)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.tfilter(c, lv)
  	return c:IsFaceup() and c:IsLevelBelow(lv)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local cg = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_GRAVE, 0, nil)
  		local tg = Duel.GetMatchingGroup(s.tfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, cg:GetCount())
  		return tg:GetCount() > 0
  	end
  	e:SetLabel(0)
  	local cg = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_GRAVE, 0, nil)
  	local tg = Duel.GetMatchingGroup(s.tfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, cg:GetCount())
  	local lvt = {}
  	local tc = tg:GetFirst()
  	while tc do
  		local tlv = tc:GetLevel()
  		lvt[tlv] = tlv
  		tc = tg:GetNext()
  	end
  	local pc = 1
  	local _, lvmax = tg:GetMaxGroup(Card.GetLevel)
  	local max = math.min(lvmax, 255)
  	for i = 1, max do
  		if lvt[i] then
  			lvt[i] = nil
  			lvt[pc] = i
  			pc = pc + 1
  		end
  	end
  	lvt[pc] = nil
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	local lv = Duel.AnnounceNumber(tp, table.unpack(lvt))
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local rg = cg:Select(tp, lv, lv, nil)
  	Duel.Remove(rg, POS_FACEUP, REASON_COST)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, tg, 1, 0, 0)
  	Duel.SetTargetParam(lv)
  end
  function s.dfilter(c, lv)
  	return c:IsFaceup() and c:IsLevel(lv)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local lv = Duel.GetChainInfo(0, CHAININFO_TARGET_PARAM)
  	if lv == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, s.dfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, lv)
  	Duel.Destroy(g, REASON_EFFECT)
  end
  
  