name: Dicephoon
card_text: Roll a six-sided die and apply the result.
  ● 2, 3, or 4: Destroy 1 Spell/Trap on the field.
  ● 5: Destroy 2 Spells/Traps on the field.
  ● 1 or 6: You take 1000 damage.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE + CATEGORY_DICE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	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)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, e:GetHandler())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DICE, nil, 0, tp, 1)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local dc = Duel.TossDice(tp, 1)
  	if dc == 1 or dc == 6 then
  		Duel.Damage(tp, 1000, REASON_EFFECT)
  	elseif dc == 5 then
  		local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, aux.ExceptThisCard(e))
  		if g:GetCount() < 2 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local dg = g:Select(tp, 2, 2, nil)
  		Duel.Destroy(dg, REASON_EFFECT)
  	elseif dc >= 2 and dc <= 4 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, aux.ExceptThisCard(e))
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  
source_text: Dicephoon
  Roll a six-sided die and apply the result.
  ● 2, 3, or 4: Destroy 1 Spell/Trap on the field.
  ● 5: Destroy 2 Spells/Traps on the field.
  ● 1 or 6: You take 1000 damage.
target_text: -- Dicephoon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE + CATEGORY_DICE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	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)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, e:GetHandler())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DICE, nil, 0, tp, 1)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local dc = Duel.TossDice(tp, 1)
  	if dc == 1 or dc == 6 then
  		Duel.Damage(tp, 1000, REASON_EFFECT)
  	elseif dc == 5 then
  		local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, aux.ExceptThisCard(e))
  		if g:GetCount() < 2 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local dg = g:Select(tp, 2, 2, nil)
  		Duel.Destroy(dg, REASON_EFFECT)
  	elseif dc >= 2 and dc <= 4 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, aux.ExceptThisCard(e))
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  