name: Bye
card_text: During damage calculation, if your monster is attacked: Your battling monster cannot be destroyed by that battle, also if you take battle damage from that battle, your opponent takes effect damage equal to double that amount. You can only apply this effect of "Bye Bye Damage" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local d = a:GetBattleTarget()
  	e:SetLabelObject(d)
  	return a:IsControler(1 - tp) and d and d:IsControler(tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) == 0
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFlagEffect(tp, id) ~= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	local tc = e:GetLabelObject()
  	if not tc:IsRelateToBattle() then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	e1:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	tc:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_BATTLE_DAMAGE)
  	e2:SetCondition(s.damcon)
  	e2:SetOperation(s.damop)
  	e2:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	Duel.RegisterEffect(e2, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Damage(1 - tp, ev * 2, REASON_EFFECT)
  end
  
  
source_text: Bye
  During damage calculation, if your monster is attacked: Your battling monster cannot be destroyed by that battle, also if you take battle damage from that battle, your opponent takes effect damage equal to double that amount. You can only apply this effect of "Bye Bye Damage" once per turn.
target_text: -- Bye
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local d = a:GetBattleTarget()
  	e:SetLabelObject(d)
  	return a:IsControler(1 - tp) and d and d:IsControler(tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) == 0
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFlagEffect(tp, id) ~= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	local tc = e:GetLabelObject()
  	if not tc:IsRelateToBattle() then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	e1:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	tc:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_BATTLE_DAMAGE)
  	e2:SetCondition(s.damcon)
  	e2:SetOperation(s.damop)
  	e2:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	Duel.RegisterEffect(e2, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Damage(1 - tp, ev * 2, REASON_EFFECT)
  end
  
  