name: Reversal
card_text: Send all cards in your hand and on your side of the field to the Graveyard. Call the type of card (Spell, Trap, or Monster) on top of your Deck. If you call it right, exchange your current Life Points with your opponent's current ones.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return not c:IsAbleToGraveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetFieldGroup(tp, LOCATION_HAND + LOCATION_ONFIELD, 0)
  	g:RemoveCard(e:GetHandler())
  	if chk == 0 then
  		return g:FilterCount(Card.IsLocation, nil, LOCATION_HAND) > 0 and g:FilterCount(Card.IsLocation, nil, LOCATION_ONFIELD) > 0 and not g:IsExists(s.cfilter, 1, nil)
  	end
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLP(tp) ~= Duel.GetLP(1 - tp) and Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 0
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetDecktopGroup(tp, 1)
  	local tc = g:GetFirst()
  	if not tc then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CARDTYPE)
  	local res = Duel.AnnounceType(tp)
  	Duel.ConfirmDecktop(tp, 1)
  	if (res == 0 and tc:IsType(TYPE_MONSTER)) or (res == 1 and tc:IsType(TYPE_SPELL)) or (res == 2 and tc:IsType(TYPE_TRAP)) then
  		local lp1 = Duel.GetLP(tp)
  		local lp2 = Duel.GetLP(1 - tp)
  		Duel.SetLP(tp, lp2)
  		Duel.SetLP(1 - tp, lp1)
  	end
  	Duel.ShuffleDeck(tp)
  end
  
  
source_text: Reversal
  Send all cards in your hand and on your side of the field to the Graveyard. Call the type of card (Spell, Trap, or Monster) on top of your Deck. If you call it right, exchange your current Life Points with your opponent's current ones.
target_text: -- Reversal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return not c:IsAbleToGraveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetFieldGroup(tp, LOCATION_HAND + LOCATION_ONFIELD, 0)
  	g:RemoveCard(e:GetHandler())
  	if chk == 0 then
  		return g:FilterCount(Card.IsLocation, nil, LOCATION_HAND) > 0 and g:FilterCount(Card.IsLocation, nil, LOCATION_ONFIELD) > 0 and not g:IsExists(s.cfilter, 1, nil)
  	end
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLP(tp) ~= Duel.GetLP(1 - tp) and Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 0
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetDecktopGroup(tp, 1)
  	local tc = g:GetFirst()
  	if not tc then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CARDTYPE)
  	local res = Duel.AnnounceType(tp)
  	Duel.ConfirmDecktop(tp, 1)
  	if (res == 0 and tc:IsType(TYPE_MONSTER)) or (res == 1 and tc:IsType(TYPE_SPELL)) or (res == 2 and tc:IsType(TYPE_TRAP)) then
  		local lp1 = Duel.GetLP(tp)
  		local lp2 = Duel.GetLP(1 - tp)
  		Duel.SetLP(tp, lp2)
  		Duel.SetLP(1 - tp, lp1)
  	end
  	Duel.ShuffleDeck(tp)
  end
  
  