name: Arcana
card_text: If this card is Summoned: Toss a coin.
  ● Heads: When this card destroys an opponent's monster by battle: You can Special Summon that monster to your field.
  ● Tails: Give control of this card to your opponent.
external_ids: local CARD_ID_0 = 73206827 --Light Barrier
  
lua: local CARD_ID_0 = 73206827 --Light Barrier
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--coin
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_COIN)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetTarget(aux.ArcanaCoinTarget)
  	e1:SetOperation(s.coinop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	local e3 = e1:Clone()
  	e3:SetCode(EVENT_FLIP_SUMMON_SUCCESS)
  	c:RegisterEffect(e3)
  	--coin effect
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_BATTLE_DESTROYING)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.coinop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local res = 0
  	local toss = false
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		res = 1 - Duel.SelectOption(tp, 60, 61)
  	else
  		res = Duel.TossCoin(tp, 1)
  		toss = true
  	end
  	if not c:IsRelateToEffect(e) or c:IsFacedown() then
  		return
  	end
  	if toss then
  		c:RegisterFlagEffect(FLAG_ID_REVERSAL_OF_FATE, RESET_EVENT + RESETS_STANDARD, 0, 1)
  	end
  	c:RegisterFlagEffect(FLAG_ID_ARCANA_COIN, RESET_EVENT + RESETS_STANDARD, EFFECT_FLAG_CLIENT_HINT, 1, res, 63 - res)
  	if res == 0 then
  		Duel.GetControl(c, 1 - tp)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:GetFlagEffectLabel(FLAG_ID_ARCANA_COIN) == 1 and c:IsRelateToBattle() and c:IsStatus(STATUS_OPPO_BATTLE)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local tc = e:GetHandler():GetBattleTarget()
  	if chk == 0 then
  		return tc:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  			and (
  				(tc:IsLocation(LOCATION_GRAVE) or tc:IsLocation(LOCATION_REMOVED) and tc:IsFaceup()) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  				or tc:IsLocation(LOCATION_EXTRA) and tc:IsFaceup() and Duel.GetLocationCountFromEx(tp, tp, nil, tc) > 0
  			)
  	end
  	Duel.SetTargetCard(tc)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, tc, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetBattleTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Arcana
  If this card is Summoned: Toss a coin.
  ● Heads: When this card destroys an opponent's monster by battle: You can Special Summon that monster to your field.
  ● Tails: Give control of this card to your opponent.
target_text: -- Arcana
  local CARD_ID_0 = 73206827 --Light Barrier
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--coin
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_COIN)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetTarget(aux.ArcanaCoinTarget)
  	e1:SetOperation(s.coinop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	local e3 = e1:Clone()
  	e3:SetCode(EVENT_FLIP_SUMMON_SUCCESS)
  	c:RegisterEffect(e3)
  	--coin effect
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_BATTLE_DESTROYING)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.coinop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local res = 0
  	local toss = false
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		res = 1 - Duel.SelectOption(tp, 60, 61)
  	else
  		res = Duel.TossCoin(tp, 1)
  		toss = true
  	end
  	if not c:IsRelateToEffect(e) or c:IsFacedown() then
  		return
  	end
  	if toss then
  		c:RegisterFlagEffect(FLAG_ID_REVERSAL_OF_FATE, RESET_EVENT + RESETS_STANDARD, 0, 1)
  	end
  	c:RegisterFlagEffect(FLAG_ID_ARCANA_COIN, RESET_EVENT + RESETS_STANDARD, EFFECT_FLAG_CLIENT_HINT, 1, res, 63 - res)
  	if res == 0 then
  		Duel.GetControl(c, 1 - tp)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:GetFlagEffectLabel(FLAG_ID_ARCANA_COIN) == 1 and c:IsRelateToBattle() and c:IsStatus(STATUS_OPPO_BATTLE)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local tc = e:GetHandler():GetBattleTarget()
  	if chk == 0 then
  		return tc:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  			and (
  				(tc:IsLocation(LOCATION_GRAVE) or tc:IsLocation(LOCATION_REMOVED) and tc:IsFaceup()) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  				or tc:IsLocation(LOCATION_EXTRA) and tc:IsFaceup() and Duel.GetLocationCountFromEx(tp, tp, nil, tc) > 0
  			)
  	end
  	Duel.SetTargetCard(tc)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, tc, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetBattleTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  