name: Phantom
card_text: Activate this card by targeting 1 Effect Monster on the field; negate that face-up monster's effects, that face-up monster cannot attack, also monsters cannot target that face-up monster for attacks. When it leaves the field, destroy this card. You can banish this card from your GY, then target 1 "The Phantom Knights" monster in your GY; Special Summon it, but banish it when it leaves the field. You can only use this effect of "Phantom Knights' Fog Blade" once per turn.
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:SetCategory(CATEGORY_DISABLE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--cannot attack/disable
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_TARGET)
  	e3:SetCode(EFFECT_CANNOT_ATTACK)
  	e3:SetRange(LOCATION_SZONE)
  	c:RegisterEffect(e3)
  	local e5 = e3:Clone()
  	e5:SetCode(EFFECT_DISABLE)
  	c:RegisterEffect(e5)
  	--cannot be battle target
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e4:SetValue(s.tgval)
  	c:RegisterEffect(e4)
  	--destroy
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e6:SetRange(LOCATION_SZONE)
  	e6:SetCode(EVENT_LEAVE_FIELD)
  	e6:SetCondition(s.descon)
  	e6:SetOperation(s.desop)
  	c:RegisterEffect(e6)
  	--spsummon
  	local e7 = Effect.CreateEffect(c)
  	e7:SetDescription(aux.Stringid(id, 0))
  	e7:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e7:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e7:SetType(EFFECT_TYPE_QUICK_O)
  	e7:SetCode(EVENT_FREE_CHAIN)
  	e7:SetRange(LOCATION_GRAVE)
  	e7:SetCountLimit(1, id)
  	e7:SetCost(aux.bfgcost)
  	e7:SetTarget(s.sptg)
  	e7:SetOperation(s.spop)
  	c:RegisterEffect(e7)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_EFFECT)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, 1, 0, 0)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		c:SetCardTarget(tc)
  	end
  end
  function s.tgval(e, c)
  	return e:GetHandler():IsHasCardTarget(c)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetFirstCardTarget()
  	return tc and eg:IsContains(tc)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		tc:RegisterEffect(e1, true)
  	end
  end
  
  
source_text: Phantom
  Activate this card by targeting 1 Effect Monster on the field; negate that face-up monster's effects, that face-up monster cannot attack, also monsters cannot target that face-up monster for attacks. When it leaves the field, destroy this card. You can banish this card from your GY, then target 1 "The Phantom Knights" monster in your GY; Special Summon it, but banish it when it leaves the field. You can only use this effect of "Phantom Knights' Fog Blade" once per turn.
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:SetCategory(CATEGORY_DISABLE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--cannot attack/disable
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_TARGET)
  	e3:SetCode(EFFECT_CANNOT_ATTACK)
  	e3:SetRange(LOCATION_SZONE)
  	c:RegisterEffect(e3)
  	local e5 = e3:Clone()
  	e5:SetCode(EFFECT_DISABLE)
  	c:RegisterEffect(e5)
  	--cannot be battle target
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e4:SetValue(s.tgval)
  	c:RegisterEffect(e4)
  	--destroy
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e6:SetRange(LOCATION_SZONE)
  	e6:SetCode(EVENT_LEAVE_FIELD)
  	e6:SetCondition(s.descon)
  	e6:SetOperation(s.desop)
  	c:RegisterEffect(e6)
  	--spsummon
  	local e7 = Effect.CreateEffect(c)
  	e7:SetDescription(aux.Stringid(id, 0))
  	e7:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e7:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e7:SetType(EFFECT_TYPE_QUICK_O)
  	e7:SetCode(EVENT_FREE_CHAIN)
  	e7:SetRange(LOCATION_GRAVE)
  	e7:SetCountLimit(1, id)
  	e7:SetCost(aux.bfgcost)
  	e7:SetTarget(s.sptg)
  	e7:SetOperation(s.spop)
  	c:RegisterEffect(e7)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_EFFECT)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, 1, 0, 0)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		c:SetCardTarget(tc)
  	end
  end
  function s.tgval(e, c)
  	return e:GetHandler():IsHasCardTarget(c)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetFirstCardTarget()
  	return tc and eg:IsContains(tc)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e1:SetValue(LOCATION_REMOVED)
  		tc:RegisterEffect(e1, true)
  	end
  end
  
  