name: Diced
card_text: Roll a six-sided die, and if you roll a 1 or 6, add 1 card from your Deck to your hand that requires a die roll. If you roll a number other than 1 or 6, roll it again, and apply the appropriate effect.
  ● 1 or 6: Return this card to the hand.
  ● 2, 3, 4, or 5: Place this card on top of the Deck.
  You can only activate 1 "Diced Dice" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DICE + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsEffectProperty(aux.EffectPropertyFilter(EFFECT_FLAG_DICE)) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local dice1 = Duel.TossDice(tp, 1)
  	if dice1 == 1 or dice1 == 6 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local tc = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil):GetFirst()
  		if tc then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, tc)
  		end
  		return
  	elseif c:IsRelateToEffect(e) then
  		local dice2 = Duel.TossDice(tp, 1)
  		if dice2 == 1 or dice2 == 6 then
  			c:CancelToGrave()
  			Duel.SendtoHand(c, nil, REASON_EFFECT)
  		elseif dice2 >= 2 and dice2 <= 5 then
  			c:CancelToGrave()
  			Duel.SendtoDeck(c, nil, SEQ_DECKTOP, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Diced
  Roll a six-sided die, and if you roll a 1 or 6, add 1 card from your Deck to your hand that requires a die roll. If you roll a number other than 1 or 6, roll it again, and apply the appropriate effect.
  ● 1 or 6: Return this card to the hand.
  ● 2, 3, 4, or 5: Place this card on top of the Deck.
  You can only activate 1 "Diced Dice" per turn.
target_text: -- Diced
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DICE + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsEffectProperty(aux.EffectPropertyFilter(EFFECT_FLAG_DICE)) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local dice1 = Duel.TossDice(tp, 1)
  	if dice1 == 1 or dice1 == 6 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local tc = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil):GetFirst()
  		if tc then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, tc)
  		end
  		return
  	elseif c:IsRelateToEffect(e) then
  		local dice2 = Duel.TossDice(tp, 1)
  		if dice2 == 1 or dice2 == 6 then
  			c:CancelToGrave()
  			Duel.SendtoHand(c, nil, REASON_EFFECT)
  		elseif dice2 >= 2 and dice2 <= 5 then
  			c:CancelToGrave()
  			Duel.SendtoDeck(c, nil, SEQ_DECKTOP, REASON_EFFECT)
  		end
  	end
  end
  
  