name: ESP
card_text: All face-up Psychic-Type monsters you controlled when this card was activated gain 300 ATK for each of your Psychic-Type monsters that is removed from play when this card resolves. During the End Phase, remove from play all monsters that were affected by this effect.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	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)
  	if Duel.GetCurrentPhase() == PHASE_DAMAGE and Duel.IsDamageCalculated() then
  		return false
  	end
  	return true
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsRace(RACE_PSYCHO)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local sg = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, 0, nil)
  	local c = e:GetHandler()
  	local tc = sg:GetFirst()
  	local atk = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_REMOVED, 0, nil) * 300
  	while tc do
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e1:SetValue(atk)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  		e2:SetCode(EVENT_PHASE + PHASE_END)
  		e2:SetRange(LOCATION_MZONE)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e2:SetCountLimit(1)
  		e2:SetOperation(s.rmop)
  		tc:RegisterEffect(e2)
  		tc = sg:GetNext()
  	end
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  
source_text: ESP
  All face-up Psychic-Type monsters you controlled when this card was activated gain 300 ATK for each of your Psychic-Type monsters that is removed from play when this card resolves. During the End Phase, remove from play all monsters that were affected by this effect.
target_text: -- ESP
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	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)
  	if Duel.GetCurrentPhase() == PHASE_DAMAGE and Duel.IsDamageCalculated() then
  		return false
  	end
  	return true
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsRace(RACE_PSYCHO)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local sg = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, 0, nil)
  	local c = e:GetHandler()
  	local tc = sg:GetFirst()
  	local atk = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_REMOVED, 0, nil) * 300
  	while tc do
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e1:SetValue(atk)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  		e2:SetCode(EVENT_PHASE + PHASE_END)
  		e2:SetRange(LOCATION_MZONE)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e2:SetCountLimit(1)
  		e2:SetOperation(s.rmop)
  		tc:RegisterEffect(e2)
  		tc = sg:GetNext()
  	end
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  