--SP-同调英雄
function c87593012.initial_effect(c)
	--lv change
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_LVCHANGE)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCondition(c87593012.condition)
	e1:SetTarget(c87593012.target)
	e1:SetOperation(c87593012.operation)
	c:RegisterEffect(e1)
end
function c87593012.condition(e,tp,eg,ep,ev,re,r,rp)
	return Duel.IsExistingMatchingCard(c87593012.ofilter,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,nil,e,tp)
end
function c87593012.ofilter(c,e,tp)
	return c:IsCode(87593200)
end
function c87593012.filter(c)
	return c:IsFaceup() and c:IsLevelAbove(1)
end
function c87593012.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
	local f=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_SZONE,LOCATION_SZONE,nil,87593200):GetFirst()
	if f:GetControler()==tp then cou1=0x871 cou2=0x872 else cou1=0x872 cou2=0x871 end
	local s=f:GetCounter(cou1)-f:GetCounter(cou2)
	local d=math.floor(s/2)
	if chkc then return chkc:IsLocation(LOCATION_MZONE) and c87593012.filter(chkc) end
	if chk==0 then return Duel.IsExistingTarget(c87593012.filter,tp,LOCATION_MZONE,LOCATION_MZONE,1,nil) and (s>1 or s<-1) end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEUP)
	Duel.SelectTarget(tp,c87593012.filter,tp,LOCATION_MZONE,LOCATION_MZONE,1,1,nil)
	e:SetLabel(d)
end
function c87593012.operation(e,tp,eg,ep,ev,re,r,rp)
	local tc=Duel.GetFirstTarget()
	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
		local e1=Effect.CreateEffect(e:GetHandler())
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetCode(EFFECT_UPDATE_LEVEL)
		e1:SetReset(RESET_EVENT+0x1fe0000)
		e1:SetValue(e:GetLabel())
		tc:RegisterEffect(e1)
	end
end
