name: Psychic
card_text: Select 1 Psychic-Type monster in your Graveyard and Special Summon it in Attack Position. It is treated as a Tuner monster. When this card is removed from the field, destroy that monster. When that monster is removed from the field, destroy this card. When this card is sent to the Graveyard, take damage equal to that monster's Level x 400.
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:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetCode(EVENT_LEAVE_FIELD)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--Destroy2
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetCondition(s.descon2)
  	e3:SetOperation(s.desop2)
  	c:RegisterEffect(e3)
  	--Destroy2
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetTarget(s.damtg)
  	e4:SetOperation(s.damop)
  	c:RegisterEffect(e4)
  	--add type
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_TARGET)
  	e5:SetCode(EFFECT_ADD_TYPE)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetValue(TYPE_TUNER)
  	c:RegisterEffect(e5)
  end
  function s.filter(c, e, tp)
  	return c:IsRace(RACE_PSYCHO) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsRace(RACE_PSYCHO) then
  		local lv = tc:GetLevel()
  		if Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK) then
  			c:SetCardTarget(tc)
  			c:RegisterFlagEffect(id, RESET_EVENT + 0x17a0000, 0, 1, lv)
  		end
  		Duel.SpecialSummonComplete()
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetFirstCardTarget()
  	if tc and tc:IsLocation(LOCATION_MZONE) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  function s.descon2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetFirstCardTarget()
  	return tc and eg:IsContains(tc)
  end
  function s.desop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(id) ~= 0
  	end
  	Duel.SetTargetPlayer(tp)
  	local lv = e:GetHandler():GetFlagEffectLabel(id)
  	Duel.SetTargetParam(lv * 400)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, tp, lv * 400)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Damage(p, d, REASON_EFFECT)
  end
  
  
source_text: Psychic
  Select 1 Psychic-Type monster in your Graveyard and Special Summon it in Attack Position. It is treated as a Tuner monster. When this card is removed from the field, destroy that monster. When that monster is removed from the field, destroy this card. When this card is sent to the Graveyard, take damage equal to that monster's Level x 400.
target_text: -- Psychic
  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:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetCode(EVENT_LEAVE_FIELD)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--Destroy2
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetCondition(s.descon2)
  	e3:SetOperation(s.desop2)
  	c:RegisterEffect(e3)
  	--Destroy2
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetTarget(s.damtg)
  	e4:SetOperation(s.damop)
  	c:RegisterEffect(e4)
  	--add type
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_TARGET)
  	e5:SetCode(EFFECT_ADD_TYPE)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetValue(TYPE_TUNER)
  	c:RegisterEffect(e5)
  end
  function s.filter(c, e, tp)
  	return c:IsRace(RACE_PSYCHO) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsRace(RACE_PSYCHO) then
  		local lv = tc:GetLevel()
  		if Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK) then
  			c:SetCardTarget(tc)
  			c:RegisterFlagEffect(id, RESET_EVENT + 0x17a0000, 0, 1, lv)
  		end
  		Duel.SpecialSummonComplete()
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetFirstCardTarget()
  	if tc and tc:IsLocation(LOCATION_MZONE) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  function s.descon2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetFirstCardTarget()
  	return tc and eg:IsContains(tc)
  end
  function s.desop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(id) ~= 0
  	end
  	Duel.SetTargetPlayer(tp)
  	local lv = e:GetHandler():GetFlagEffectLabel(id)
  	Duel.SetTargetParam(lv * 400)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, tp, lv * 400)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Damage(p, d, REASON_EFFECT)
  end
  
  