name: Storm
card_text: Destroy as many Spells/Traps you control as possible, then destroy as many Spells/Traps your opponent controls as possible, up to the number of cards destroyed by this effect.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY)
  	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)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_ONFIELD, 0, 1, c)
  	end
  	local g1 = Duel.GetMatchingGroup(s.filter, tp, LOCATION_ONFIELD, 0, c)
  	local g2 = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_ONFIELD, nil)
  	local ct1 = g1:GetCount()
  	local ct2 = g2:GetCount()
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g1, ct1 + ((ct1 > ct2) and ct2 or ct1), 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g1 = Duel.GetMatchingGroup(s.filter, tp, LOCATION_ONFIELD, 0, aux.ExceptThisCard(e))
  	local ct1 = Duel.Destroy(g1, REASON_EFFECT)
  	if ct1 == 0 then
  		return
  	end
  	local g2 = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_ONFIELD, nil)
  	local ct2 = g2:GetCount()
  	if ct2 == 0 then
  		return
  	end
  	Duel.BreakEffect()
  	if ct2 <= ct1 then
  		Duel.Destroy(g2, REASON_EFFECT)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g3 = g2:Select(tp, ct1, ct1, nil)
  		Duel.HintSelection(g3)
  		Duel.Destroy(g3, REASON_EFFECT)
  	end
  end
  
  
source_text: Storm
  Destroy as many Spells/Traps you control as possible, then destroy as many Spells/Traps your opponent controls as possible, up to the number of cards destroyed by this effect.
target_text: -- Storm
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY)
  	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)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_ONFIELD, 0, 1, c)
  	end
  	local g1 = Duel.GetMatchingGroup(s.filter, tp, LOCATION_ONFIELD, 0, c)
  	local g2 = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_ONFIELD, nil)
  	local ct1 = g1:GetCount()
  	local ct2 = g2:GetCount()
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g1, ct1 + ((ct1 > ct2) and ct2 or ct1), 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g1 = Duel.GetMatchingGroup(s.filter, tp, LOCATION_ONFIELD, 0, aux.ExceptThisCard(e))
  	local ct1 = Duel.Destroy(g1, REASON_EFFECT)
  	if ct1 == 0 then
  		return
  	end
  	local g2 = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_ONFIELD, nil)
  	local ct2 = g2:GetCount()
  	if ct2 == 0 then
  		return
  	end
  	Duel.BreakEffect()
  	if ct2 <= ct1 then
  		Duel.Destroy(g2, REASON_EFFECT)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g3 = g2:Select(tp, ct1, ct1, nil)
  		Duel.HintSelection(g3)
  		Duel.Destroy(g3, REASON_EFFECT)
  	end
  end
  
  