name: Cosmo
card_text: Cannot be Normal Summoned/Set. Must first be Special Summoned by sending 1 non-Effect Monster from your hand or face-up field to the GY. This card gains ATK equal to the Level of the monster sent to the GY this way x 200. You can Tribute 1 Effect Monster; Special Summon 1 Normal Monster from your hand or Deck. You can only use this effect of "Cosmo Brain" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.sprcon)
  	e1:SetTarget(s.sprtg)
  	e1:SetOperation(s.sprop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.spcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.sprfilter(c, tp)
  	return (c:IsLocation(LOCATION_HAND) or c:IsFaceup()) and not c:IsType(TYPE_EFFECT) and c:IsType(TYPE_MONSTER) and c:IsAbleToGraveAsCost() and Duel.GetMZoneCount(tp, c) > 0
  end
  function s.sprcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	return Duel.IsExistingMatchingCard(s.sprfilter, tp, LOCATION_HAND + LOCATION_MZONE, 0, 1, nil, tp)
  end
  function s.sprtg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.sprfilter, tp, LOCATION_HAND + LOCATION_MZONE, 0, nil, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local tc = g:SelectUnselect(nil, tp, false, true, 1, 1)
  	if tc then
  		e:SetLabelObject(tc)
  		return true
  	else
  		return false
  	end
  end
  function s.sprop(e, tp, eg, ep, ev, re, r, rp, c)
  	local rc = e:GetLabelObject()
  	local lv = rc:GetLevel()
  	Duel.SendtoGrave(rc, REASON_SPSUMMON)
  	if not rc:IsType(TYPE_MONSTER) or lv <= 0 then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(lv * 200)
  	e1:SetReset(RESET_EVENT + 0xff0000)
  	c:RegisterEffect(e1)
  end
  function s.costfilter(c, tp)
  	return c:IsType(TYPE_EFFECT) and Duel.GetMZoneCount(tp, c, tp) > 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, s.costfilter, 1, nil, tp)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.costfilter, 1, 1, nil, tp)
  	Duel.Release(g, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:IsType(TYPE_NORMAL) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Cosmo
  Cannot be Normal Summoned/Set. Must first be Special Summoned by sending 1 non-Effect Monster from your hand or face-up field to the GY. This card gains ATK equal to the Level of the monster sent to the GY this way x 200. You can Tribute 1 Effect Monster; Special Summon 1 Normal Monster from your hand or Deck. You can only use this effect of "Cosmo Brain" once per turn.
target_text: -- Cosmo
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.sprcon)
  	e1:SetTarget(s.sprtg)
  	e1:SetOperation(s.sprop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.spcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.sprfilter(c, tp)
  	return (c:IsLocation(LOCATION_HAND) or c:IsFaceup()) and not c:IsType(TYPE_EFFECT) and c:IsType(TYPE_MONSTER) and c:IsAbleToGraveAsCost() and Duel.GetMZoneCount(tp, c) > 0
  end
  function s.sprcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	return Duel.IsExistingMatchingCard(s.sprfilter, tp, LOCATION_HAND + LOCATION_MZONE, 0, 1, nil, tp)
  end
  function s.sprtg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.sprfilter, tp, LOCATION_HAND + LOCATION_MZONE, 0, nil, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local tc = g:SelectUnselect(nil, tp, false, true, 1, 1)
  	if tc then
  		e:SetLabelObject(tc)
  		return true
  	else
  		return false
  	end
  end
  function s.sprop(e, tp, eg, ep, ev, re, r, rp, c)
  	local rc = e:GetLabelObject()
  	local lv = rc:GetLevel()
  	Duel.SendtoGrave(rc, REASON_SPSUMMON)
  	if not rc:IsType(TYPE_MONSTER) or lv <= 0 then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(lv * 200)
  	e1:SetReset(RESET_EVENT + 0xff0000)
  	c:RegisterEffect(e1)
  end
  function s.costfilter(c, tp)
  	return c:IsType(TYPE_EFFECT) and Duel.GetMZoneCount(tp, c, tp) > 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, s.costfilter, 1, nil, tp)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.costfilter, 1, 1, nil, tp)
  	Duel.Release(g, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:IsType(TYPE_NORMAL) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  