name: Time
card_text: Once per turn: You can toss a coin and call it. If you call it right, destroy all monsters your opponent controls. If you call it wrong, destroy as many monsters you control as possible, and if you do, take damage equal to half the total ATK those destroyed monsters had while face-up on the field.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_COIN + CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(nil, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_COIN, nil, 0, tp, 1)
  	if #g > 0 then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, e:GetHandler(), 1, 0, 0)
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_COIN)
  	local coin = Duel.AnnounceCoin(tp)
  	local res = Duel.TossCoin(tp, 1)
  	if coin ~= res then
  		local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_MZONE, nil)
  		Duel.Destroy(g, REASON_EFFECT)
  		Duel.RaiseEvent(e:GetHandler(), EVENT_CUSTOM + id, e, 0, 0, tp, 0)
  	else
  		local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, 0, nil)
  		Duel.Destroy(g, REASON_EFFECT)
  		local dg = Duel.GetOperatedGroup()
  		local sum = 0
  		for c in aux.Next(dg) do
  			sum = sum + math.max(c:GetAttack(), 0)
  		end
  		if sum > 0 then
  			Duel.Damage(tp, math.floor(sum / 2), REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Time
  Once per turn: You can toss a coin and call it. If you call it right, destroy all monsters your opponent controls. If you call it wrong, destroy as many monsters you control as possible, and if you do, take damage equal to half the total ATK those destroyed monsters had while face-up on the field.
target_text: -- Time
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_COIN + CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(nil, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_COIN, nil, 0, tp, 1)
  	if #g > 0 then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, e:GetHandler(), 1, 0, 0)
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_COIN)
  	local coin = Duel.AnnounceCoin(tp)
  	local res = Duel.TossCoin(tp, 1)
  	if coin ~= res then
  		local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_MZONE, nil)
  		Duel.Destroy(g, REASON_EFFECT)
  		Duel.RaiseEvent(e:GetHandler(), EVENT_CUSTOM + id, e, 0, 0, tp, 0)
  	else
  		local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, 0, nil)
  		Duel.Destroy(g, REASON_EFFECT)
  		local dg = Duel.GetOperatedGroup()
  		local sum = 0
  		for c in aux.Next(dg) do
  			sum = sum + math.max(c:GetAttack(), 0)
  		end
  		if sum > 0 then
  			Duel.Damage(tp, math.floor(sum / 2), REASON_EFFECT)
  		end
  	end
  end
  
  