name: Arcana
card_text: During damage calculation (Quick Effect): You can discard this card; you take no battle damage from that battle. If this card is Summoned: Toss a coin.
  ● Heads: Halve all battle damage you take.
  ● Tails: Halve all battle damage your opponent takes.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--no damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e1:SetCondition(s.damcon)
  	e1:SetCost(s.damcost)
  	e1:SetOperation(s.damop)
  	c:RegisterEffect(e1)
  	--coin
  	aux.EnableArcanaCoin(c, EVENT_SUMMON_SUCCESS, EVENT_FLIP_SUMMON_SUCCESS, EVENT_SPSUMMON_SUCCESS)
  	--coin effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(1, 0)
  	e2:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e2:SetCondition(s.rdcon1)
  	e2:SetValue(HALF_DAMAGE)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetTargetRange(0, 1)
  	e3:SetCondition(s.rdcon2)
  	c:RegisterEffect(e3)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetBattleDamage(tp) > 0
  end
  function s.damcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetReset(RESET_PHASE + PHASE_DAMAGE_CAL)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.rdcon1(e)
  	return e:GetHandler():GetFlagEffectLabel(FLAG_ID_ARCANA_COIN) == 1
  end
  function s.rdcon2(e)
  	return e:GetHandler():GetFlagEffectLabel(FLAG_ID_ARCANA_COIN) == 0
  end
  
  
source_text: Arcana
  During damage calculation (Quick Effect): You can discard this card; you take no battle damage from that battle. If this card is Summoned: Toss a coin.
  ● Heads: Halve all battle damage you take.
  ● Tails: Halve all battle damage your opponent takes.
target_text: -- Arcana
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--no damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e1:SetCondition(s.damcon)
  	e1:SetCost(s.damcost)
  	e1:SetOperation(s.damop)
  	c:RegisterEffect(e1)
  	--coin
  	aux.EnableArcanaCoin(c, EVENT_SUMMON_SUCCESS, EVENT_FLIP_SUMMON_SUCCESS, EVENT_SPSUMMON_SUCCESS)
  	--coin effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(1, 0)
  	e2:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e2:SetCondition(s.rdcon1)
  	e2:SetValue(HALF_DAMAGE)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetTargetRange(0, 1)
  	e3:SetCondition(s.rdcon2)
  	c:RegisterEffect(e3)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetBattleDamage(tp) > 0
  end
  function s.damcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetReset(RESET_PHASE + PHASE_DAMAGE_CAL)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.rdcon1(e)
  	return e:GetHandler():GetFlagEffectLabel(FLAG_ID_ARCANA_COIN) == 1
  end
  function s.rdcon2(e)
  	return e:GetHandler():GetFlagEffectLabel(FLAG_ID_ARCANA_COIN) == 0
  end
  
  