name: Magicalibra
card_text: Pendulum Scale = 5
  [ Pendulum Effect ]
  You can declare a Level from 1 to 6, then target 2 face-up monsters you control; until the end of this turn, reduce the Level of 1 of those monsters by the declared amount, and if you do, increase the Level of the other by the same amount (even if this card leaves the field). You can only use this effect of "Magicalibra" once per turn.
  ----------------------------------------
  [ Monster Effect ]
  A sentient scale. It maintains the balance of the universe, but often places the stars on the wrong side.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--lv
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetTarget(s.lvtg)
  	e1:SetOperation(s.lvop)
  	c:RegisterEffect(e1)
  end
  function s.lvfilter1(c, tp)
  	return c:IsFaceup() and c:IsLevelAbove(2) and Duel.IsExistingTarget(s.lvfilter2, tp, LOCATION_MZONE, 0, 1, c)
  end
  function s.lvfilter2(c)
  	return c:IsFaceup() and c:IsLevelAbove(1)
  end
  function s.lvfilter3(c, tp, lv)
  	return c:IsFaceup() and c:IsLevelAbove(lv + 1) and Duel.IsExistingTarget(s.lvfilter2, tp, LOCATION_MZONE, 0, 1, c)
  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.lvfilter1, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	local g = Duel.GetMatchingGroup(s.lvfilter1, tp, LOCATION_MZONE, 0, nil, tp)
  	local mg, lv = g:GetMaxGroup(Card.GetLevel)
  	local alv = 0
  	if lv > 2 then
  		alv = Duel.AnnounceLevel(tp, 1, math.min(lv - 1, 6))
  	else
  		alv = Duel.AnnounceLevel(tp, 1, 1)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	local g1 = Duel.SelectTarget(tp, s.lvfilter3, tp, LOCATION_MZONE, 0, 1, 1, nil, tp, alv)
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	Duel.SelectTarget(tp, s.lvfilter2, tp, LOCATION_MZONE, 0, 1, 1, g1:GetFirst())
  	e:SetLabelObject(g1:GetFirst())
  	e:SetLabel(alv)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	local hc = e:GetLabelObject()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tc = g:GetFirst()
  	if tc == hc then
  		tc = g:GetNext()
  	end
  	local lv = e:GetLabel()
  	if hc:IsFaceup() and hc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(-lv)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		hc:RegisterEffect(e1)
  		if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_UPDATE_LEVEL)
  			e2:SetValue(lv)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc:RegisterEffect(e2)
  		end
  	end
  end
  
  
source_text: Magicalibra
  Pendulum Scale = 5
  [ Pendulum Effect ]
  You can declare a Level from 1 to 6, then target 2 face-up monsters you control; until the end of this turn, reduce the Level of 1 of those monsters by the declared amount, and if you do, increase the Level of the other by the same amount (even if this card leaves the field). You can only use this effect of "Magicalibra" once per turn.
  ----------------------------------------
  [ Monster Effect ]
  A sentient scale. It maintains the balance of the universe, but often places the stars on the wrong side.
target_text: -- Magicalibra
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--lv
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetTarget(s.lvtg)
  	e1:SetOperation(s.lvop)
  	c:RegisterEffect(e1)
  end
  function s.lvfilter1(c, tp)
  	return c:IsFaceup() and c:IsLevelAbove(2) and Duel.IsExistingTarget(s.lvfilter2, tp, LOCATION_MZONE, 0, 1, c)
  end
  function s.lvfilter2(c)
  	return c:IsFaceup() and c:IsLevelAbove(1)
  end
  function s.lvfilter3(c, tp, lv)
  	return c:IsFaceup() and c:IsLevelAbove(lv + 1) and Duel.IsExistingTarget(s.lvfilter2, tp, LOCATION_MZONE, 0, 1, c)
  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.lvfilter1, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	local g = Duel.GetMatchingGroup(s.lvfilter1, tp, LOCATION_MZONE, 0, nil, tp)
  	local mg, lv = g:GetMaxGroup(Card.GetLevel)
  	local alv = 0
  	if lv > 2 then
  		alv = Duel.AnnounceLevel(tp, 1, math.min(lv - 1, 6))
  	else
  		alv = Duel.AnnounceLevel(tp, 1, 1)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	local g1 = Duel.SelectTarget(tp, s.lvfilter3, tp, LOCATION_MZONE, 0, 1, 1, nil, tp, alv)
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	Duel.SelectTarget(tp, s.lvfilter2, tp, LOCATION_MZONE, 0, 1, 1, g1:GetFirst())
  	e:SetLabelObject(g1:GetFirst())
  	e:SetLabel(alv)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	local hc = e:GetLabelObject()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tc = g:GetFirst()
  	if tc == hc then
  		tc = g:GetNext()
  	end
  	local lv = e:GetLabel()
  	if hc:IsFaceup() and hc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(-lv)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		hc:RegisterEffect(e1)
  		if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_UPDATE_LEVEL)
  			e2:SetValue(lv)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc:RegisterEffect(e2)
  		end
  	end
  end
  
  