name: Phantom
card_text: Each time your opponent activates a card or effect that targets a "The Phantom Knights" monster(s) you control, inflict 500 damage to your opponent immediately after it resolves. If a DARK monster you control would be destroyed by battle or an opponent's card effect, you can banish this card from your GY instead.
external_ids: local SETCARD_ID_0 = 0x10db --The
  
lua: local SETCARD_ID_0 = 0x10db --The
  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)
  	c:RegisterEffect(e1)
  	--damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetTarget(s.reptg)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop)
  	c:RegisterEffect(e3)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	if not re or not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then
  		return false
  	end
  	local g = Duel.GetChainInfo(ev, CHAININFO_TARGET_CARDS)
  	return g and g:IsExists(s.filter, 1, nil) and 1 - tp == rp
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_CHAIN_SOLVING)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetLabelObject(re)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET + RESET_CHAIN)
  	e1:SetCondition(s.damcon)
  	e1:SetOperation(s.damop)
  	c:RegisterEffect(e1)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return re == e:GetLabelObject()
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_CARD, 0, id)
  	Duel.Damage(1 - tp, 500, REASON_EFFECT)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsControler(tp)
  		and c:IsAttribute(ATTRIBUTE_DARK)
  		and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp))
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  
source_text: Phantom
  Each time your opponent activates a card or effect that targets a "The Phantom Knights" monster(s) you control, inflict 500 damage to your opponent immediately after it resolves. If a DARK monster you control would be destroyed by battle or an opponent's card effect, you can banish this card from your GY instead.
target_text: -- Phantom
  local SETCARD_ID_0 = 0x10db --The
  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)
  	c:RegisterEffect(e1)
  	--damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetTarget(s.reptg)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop)
  	c:RegisterEffect(e3)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	if not re or not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then
  		return false
  	end
  	local g = Duel.GetChainInfo(ev, CHAININFO_TARGET_CARDS)
  	return g and g:IsExists(s.filter, 1, nil) and 1 - tp == rp
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_CHAIN_SOLVING)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetLabelObject(re)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET + RESET_CHAIN)
  	e1:SetCondition(s.damcon)
  	e1:SetOperation(s.damop)
  	c:RegisterEffect(e1)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return re == e:GetLabelObject()
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_CARD, 0, id)
  	Duel.Damage(1 - tp, 500, REASON_EFFECT)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsControler(tp)
  		and c:IsAttribute(ATTRIBUTE_DARK)
  		and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp))
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  