name: Aegis
card_text: Gain 3000 LP. If this face-up card leaves the field, the controller of this card takes 3000 damage.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCategory(CATEGORY_RECOVER)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.rectg)
  	e1:SetOperation(s.recop)
  	c:RegisterEffect(e1)
  	--leave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_LEAVE_FIELD_P)
  	e2:SetOperation(s.checkop)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetLabelObject(e2)
  	e3:SetOperation(s.leave)
  	c:RegisterEffect(e3)
  end
  function s.rectg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(3000)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, 3000)
  end
  function s.recop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Recover(p, d, REASON_EFFECT)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsDisabled() or not c:IsStatus(STATUS_EFFECT_ENABLED) then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.leave(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if e:GetLabelObject():GetLabel() == 0 and c:IsPreviousControler(tp) then
  		Duel.Damage(tp, 3000, REASON_EFFECT)
  	end
  end
  
  
source_text: Aegis
  Gain 3000 LP. If this face-up card leaves the field, the controller of this card takes 3000 damage.
target_text: -- Aegis
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCategory(CATEGORY_RECOVER)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.rectg)
  	e1:SetOperation(s.recop)
  	c:RegisterEffect(e1)
  	--leave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_LEAVE_FIELD_P)
  	e2:SetOperation(s.checkop)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetLabelObject(e2)
  	e3:SetOperation(s.leave)
  	c:RegisterEffect(e3)
  end
  function s.rectg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(3000)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, 3000)
  end
  function s.recop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Recover(p, d, REASON_EFFECT)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsDisabled() or not c:IsStatus(STATUS_EFFECT_ENABLED) then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.leave(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if e:GetLabelObject():GetLabel() == 0 and c:IsPreviousControler(tp) then
  		Duel.Damage(tp, 3000, REASON_EFFECT)
  	end
  end
  
  