name: Uni-Song
card_text: Target 1 Tuner in either GY and 1 face-up monster on the field; banish that Tuner in the GY, then, until the end of this turn, the Level of the targeted monster on the field becomes the Level of the banished Tuner, also it is treated as a Tuner. You can only activate 1 "Uni-Song Tuning" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c, tp)
  	local lv = c:GetLevel()
  	return lv > 0 and c:IsType(TYPE_TUNER) and c:IsAbleToRemove() and Duel.IsExistingTarget(s.filter2, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, lv)
  end
  function s.filter2(c, lv)
  	return c:IsFaceup() and c:IsLevelAbove(1) and (not c:IsType(TYPE_TUNER) or not c:IsLevel(lv))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter1, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil, tp)
  	e:SetLabelObject(g1:GetFirst())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g2 = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, g1:GetFirst():GetLevel())
  	if g1:GetFirst():IsControler(tp) then
  		Duel.SetOperationInfo(0, CATEGORY_REMOVE, g1, 1, tp, LOCATION_GRAVE)
  	else
  		Duel.SetOperationInfo(0, CATEGORY_REMOVE, g1, 1, 1 - tp, LOCATION_GRAVE)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local hc = e:GetLabelObject()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tc = g:GetFirst()
  	if tc == hc then
  		tc = g:GetNext()
  	end
  	if hc:IsRelateToEffect(e) and Duel.Remove(hc, POS_FACEUP, REASON_EFFECT) ~= 0 and hc:IsLocation(LOCATION_REMOVED) then
  		Duel.BreakEffect()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetValue(hc:GetLevel())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_ADD_TYPE)
  		e2:SetValue(TYPE_TUNER)
  		tc:RegisterEffect(e2)
  	end
  end
  
  
source_text: Uni-Song
  Target 1 Tuner in either GY and 1 face-up monster on the field; banish that Tuner in the GY, then, until the end of this turn, the Level of the targeted monster on the field becomes the Level of the banished Tuner, also it is treated as a Tuner. You can only activate 1 "Uni-Song Tuning" per turn.
target_text: -- Uni-Song
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c, tp)
  	local lv = c:GetLevel()
  	return lv > 0 and c:IsType(TYPE_TUNER) and c:IsAbleToRemove() and Duel.IsExistingTarget(s.filter2, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, lv)
  end
  function s.filter2(c, lv)
  	return c:IsFaceup() and c:IsLevelAbove(1) and (not c:IsType(TYPE_TUNER) or not c:IsLevel(lv))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter1, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectTarget(tp, s.filter1, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil, tp)
  	e:SetLabelObject(g1:GetFirst())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g2 = Duel.SelectTarget(tp, s.filter2, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, g1:GetFirst():GetLevel())
  	if g1:GetFirst():IsControler(tp) then
  		Duel.SetOperationInfo(0, CATEGORY_REMOVE, g1, 1, tp, LOCATION_GRAVE)
  	else
  		Duel.SetOperationInfo(0, CATEGORY_REMOVE, g1, 1, 1 - tp, LOCATION_GRAVE)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local hc = e:GetLabelObject()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tc = g:GetFirst()
  	if tc == hc then
  		tc = g:GetNext()
  	end
  	if hc:IsRelateToEffect(e) and Duel.Remove(hc, POS_FACEUP, REASON_EFFECT) ~= 0 and hc:IsLocation(LOCATION_REMOVED) then
  		Duel.BreakEffect()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetValue(hc:GetLevel())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_ADD_TYPE)
  		e2:SetValue(TYPE_TUNER)
  		tc:RegisterEffect(e2)
  	end
  end
  
  