name: Cupid
card_text: If all monsters you control are monsters with 600 DEF (min. 1): You can Special Summon this card from your hand. (Quick Effect): You can discard 1 card, then target 1 LIGHT Fairy monster you control and 1 face-up monster on the field; the Level of your monster becomes the other monster's Level, until the end of this turn. You can only use each effect of "Cupid Fore" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--lv
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.lvcost)
  	e2:SetTarget(s.lvtg)
  	e2:SetOperation(s.lvop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsDefense(600)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_MZONE, 0, nil)
  	return ct > 0 and ct == Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.lvcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD, nil)
  end
  function s.lvfilter(c, tp)
  	return c:IsFaceup() and c:IsLevelAbove(1) and c:IsRace(RACE_FAIRY) and c:IsAttribute(ATTRIBUTE_LIGHT) and Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, c, c:GetLevel())
  end
  function s.cfilter(c, lv)
  	return c:IsFaceup() and c:IsLevelAbove(1) and not c:IsLevel(lv)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  	local tc = g:GetFirst()
  	e:SetLabelObject(tc)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, tc, tc:GetLevel())
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local lc = tg:GetFirst()
  	if lc == tc then
  		lc = tg:GetNext()
  	end
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsControler(tp) and lc:IsRelateToEffect(e) and lc:IsFaceup() then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetValue(lc:GetLevel())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  
  
source_text: Cupid
  If all monsters you control are monsters with 600 DEF (min. 1): You can Special Summon this card from your hand. (Quick Effect): You can discard 1 card, then target 1 LIGHT Fairy monster you control and 1 face-up monster on the field; the Level of your monster becomes the other monster's Level, until the end of this turn. You can only use each effect of "Cupid Fore" once per turn.
target_text: -- Cupid
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--lv
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.lvcost)
  	e2:SetTarget(s.lvtg)
  	e2:SetOperation(s.lvop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsDefense(600)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_MZONE, 0, nil)
  	return ct > 0 and ct == Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.lvcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD, nil)
  end
  function s.lvfilter(c, tp)
  	return c:IsFaceup() and c:IsLevelAbove(1) and c:IsRace(RACE_FAIRY) and c:IsAttribute(ATTRIBUTE_LIGHT) and Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, c, c:GetLevel())
  end
  function s.cfilter(c, lv)
  	return c:IsFaceup() and c:IsLevelAbove(1) and not c:IsLevel(lv)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  	local tc = g:GetFirst()
  	e:SetLabelObject(tc)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, tc, tc:GetLevel())
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local lc = tg:GetFirst()
  	if lc == tc then
  		lc = tg:GetNext()
  	end
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsControler(tp) and lc:IsRelateToEffect(e) and lc:IsFaceup() then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetValue(lc:GetLevel())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  
  