name: Dice
card_text: When this card is activated: You can add 1 "Dimension Dice" from your Deck to your hand. At the start of the Battle Phase: You can activate this effect; each player rolls a six-sided die and applies the result to all monsters they control, until the end of this turn.
  ● 1: Lose 1000 ATK.
  ● 2: Gain 1000 ATK.
  ● 3: Lose 500 ATK.
  ● 4: Gain 500 ATK.
  ● 5: Halve their ATK.
  ● 6: Double their ATK.
external_ids: local CARD_ID_0 = 47292920 --Dimension Dice
  
lua: local CARD_ID_0 = 47292920 --Dimension Dice
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--dice roll
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DICE + CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE_START)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.dicetg)
  	e2:SetOperation(s.diceop)
  	c:RegisterEffect(e2)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  function s.dicetg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DICE, nil, 0, PLAYER_ALL, 1)
  end
  function s.diceop(e, tp, eg, ep, ev, re, r, rp)
  	for p in aux.TurnPlayers() do
  		local dice = Duel.TossDice(p, 1)
  		if dice >= 1 and dice <= 6 then
  			local g = Duel.GetMatchingGroup(Card.IsFaceup, p, LOCATION_MZONE, 0, nil)
  			local sc = g:GetFirst()
  			while sc do
  				local atk = sc:GetAttack()
  				local e1 = Effect.CreateEffect(e:GetHandler())
  				e1:SetType(EFFECT_TYPE_SINGLE)
  				e1:SetCode(dice < 5 and EFFECT_UPDATE_ATTACK or EFFECT_SET_ATTACK_FINAL)
  				e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  				e1:SetValue(({ -1000, 1000, -500, 500, math.ceil(atk / 2), atk * 2 })[dice])
  				sc:RegisterEffect(e1)
  				sc = g:GetNext()
  			end
  		end
  	end
  end
  
  
source_text: Dice
  When this card is activated: You can add 1 "Dimension Dice" from your Deck to your hand. At the start of the Battle Phase: You can activate this effect; each player rolls a six-sided die and applies the result to all monsters they control, until the end of this turn.
  ● 1: Lose 1000 ATK.
  ● 2: Gain 1000 ATK.
  ● 3: Lose 500 ATK.
  ● 4: Gain 500 ATK.
  ● 5: Halve their ATK.
  ● 6: Double their ATK.
target_text: -- Dice
  local CARD_ID_0 = 47292920 --Dimension Dice
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--dice roll
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DICE + CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE_START)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.dicetg)
  	e2:SetOperation(s.diceop)
  	c:RegisterEffect(e2)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  function s.dicetg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DICE, nil, 0, PLAYER_ALL, 1)
  end
  function s.diceop(e, tp, eg, ep, ev, re, r, rp)
  	for p in aux.TurnPlayers() do
  		local dice = Duel.TossDice(p, 1)
  		if dice >= 1 and dice <= 6 then
  			local g = Duel.GetMatchingGroup(Card.IsFaceup, p, LOCATION_MZONE, 0, nil)
  			local sc = g:GetFirst()
  			while sc do
  				local atk = sc:GetAttack()
  				local e1 = Effect.CreateEffect(e:GetHandler())
  				e1:SetType(EFFECT_TYPE_SINGLE)
  				e1:SetCode(dice < 5 and EFFECT_UPDATE_ATTACK or EFFECT_SET_ATTACK_FINAL)
  				e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  				e1:SetValue(({ -1000, 1000, -500, 500, math.ceil(atk / 2), atk * 2 })[dice])
  				sc:RegisterEffect(e1)
  				sc = g:GetNext()
  			end
  		end
  	end
  end
  
  