name: Ghost
card_text: During the Main Phase: Target 1 Zombie Synchro Monster you control; Special Summon 1 of your Zombie monsters with the same Attribute, that is banished or in your GY, but banish it during the End Phase, also you cannot Special Summon monsters for the rest of this turn after this card resolves, except Zombie monsters. You can only activate 1 "Ghost Meets Girl - A Mayakashi's Manuscript" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	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)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.cfilter(c, e, tp)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO) and c:IsRace(RACE_ZOMBIE) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp, c:GetAttribute())
  end
  function s.spfilter(c, e, tp, att)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsRace(RACE_ZOMBIE) and c:IsAttribute(att) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.cfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE + LOCATION_REMOVED)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 then
  		local att = tc:GetAttribute()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp, att)
  		if g:GetCount() > 0 and Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  			local tc = g:GetFirst()
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  			e1:SetCode(EVENT_PHASE + PHASE_END)
  			e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  			e1:SetCountLimit(1)
  			e1:SetLabelObject(tc)
  			e1:SetCondition(s.rmcon)
  			e1:SetOperation(s.rmop)
  			Duel.RegisterEffect(e1, tp)
  		end
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_FIELD)
  		e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  		e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e2:SetTargetRange(1, 0)
  		e2:SetTarget(s.splimit)
  		e2:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	if tc:GetFlagEffect(id) ~= 0 then
  		return true
  	else
  		e:Reset()
  		return false
  	end
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  end
  function s.splimit(e, c)
  	return not c:IsRace(RACE_ZOMBIE)
  end
  
  
source_text: Ghost
  During the Main Phase: Target 1 Zombie Synchro Monster you control; Special Summon 1 of your Zombie monsters with the same Attribute, that is banished or in your GY, but banish it during the End Phase, also you cannot Special Summon monsters for the rest of this turn after this card resolves, except Zombie monsters. You can only activate 1 "Ghost Meets Girl - A Mayakashi's Manuscript" per turn.
target_text: -- Ghost
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	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)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.cfilter(c, e, tp)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO) and c:IsRace(RACE_ZOMBIE) and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp, c:GetAttribute())
  end
  function s.spfilter(c, e, tp, att)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsRace(RACE_ZOMBIE) and c:IsAttribute(att) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.cfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE + LOCATION_REMOVED)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 then
  		local att = tc:GetAttribute()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp, att)
  		if g:GetCount() > 0 and Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  			local tc = g:GetFirst()
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  			e1:SetCode(EVENT_PHASE + PHASE_END)
  			e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  			e1:SetCountLimit(1)
  			e1:SetLabelObject(tc)
  			e1:SetCondition(s.rmcon)
  			e1:SetOperation(s.rmop)
  			Duel.RegisterEffect(e1, tp)
  		end
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_FIELD)
  		e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  		e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e2:SetTargetRange(1, 0)
  		e2:SetTarget(s.splimit)
  		e2:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	if tc:GetFlagEffect(id) ~= 0 then
  		return true
  	else
  		e:Reset()
  		return false
  	end
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  end
  function s.splimit(e, c)
  	return not c:IsRace(RACE_ZOMBIE)
  end
  
  