--SP-电子科技区
function c87593013.initial_effect(c)
	--remove
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_REMOVE)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCondition(c87593013.condition)
	e1:SetTarget(c87593013.target)
	e1:SetOperation(c87593013.operation)
	c:RegisterEffect(e1)
end
function c87593013.condition(e,tp,eg,ep,ev,re,r,rp)
	local f=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,nil,87593200):GetFirst()
	if f:GetControler()==tp then cou1=0x871 cou2=0x872 else cou1=0x872 cou2=0x871 end
	return f:GetCounter(cou2)-f:GetCounter(cou1)>=5
end
function c87593013.filter(c,e,tp)
	local g=Duel.GetMatchingGroup(c87593013.mfilter,tp,0,LOCATION_MZONE,nil):GetMaxGroup(Card.GetAttack)
	return c:IsFaceup() and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
		and g:GetCount()>0 and c:GetAttack()<g:GetFirst():GetAttack()
end
function c87593013.mfilter(c)
	return c:IsFaceup() and c:GetAttack()>0
end
function c87593013.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(c87593013.mfilter,tp,0,LOCATION_MZONE,1,nil)
	 and Duel.IsExistingTarget(c87593013.filter,tp,LOCATION_MZONE,0,1,nil,e,tp)
		and Duel.GetCurrentPhase()==PHASE_MAIN1 end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)
	local g=Duel.SelectTarget(tp,c87593013.filter,tp,LOCATION_MZONE,0,1,1,nil,e,tp)
	Duel.SetOperationInfo(0,CATEGORY_REMOVE,g,1,0,0)
end
function c87593013.operation(e,tp,eg,ep,ev,re,r,rp)
	local tc=Duel.GetFirstTarget()
	if tc:IsRelateToEffect(e) and tc:IsFaceup() and Duel.Remove(tc,0,REASON_EFFECT+REASON_TEMPORARY)~=0 then
		local e1=Effect.CreateEffect(e:GetHandler())
		e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
		e1:SetCode(EVENT_PHASE+PHASE_BATTLE)
		e1:SetReset(RESET_PHASE+PHASE_END+RESET_SELF_TURN,2)
		e1:SetLabelObject(tc)
		e1:SetCountLimit(1)
		e1:SetCondition(c87593013.condition2)
		e1:SetOperation(c87593013.retop)
		Duel.RegisterEffect(e1,tp)
	end
end
function c87593013.condition2(e,tp,eg,ep,ev,re,r,rp)
	return Duel.GetTurnPlayer()==1-tp
end
function c87593013.retop(e,tp,eg,ep,ev,re,r,rp)
	local tc=e:GetLabelObject()
	if Duel.ReturnToField(e:GetLabelObject()) then
		local e1=Effect.CreateEffect(e:GetOwner())
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
		e1:SetValue(tc:GetBaseAttack()*2)
		e1:SetReset(RESET_EVENT+0x1fe0000+RESET_PHASE+PHASE_END+RESET_SELF_TURN)
		tc:RegisterEffect(e1)
	local e2=Effect.CreateEffect(e:GetOwner())
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_CHANGE_RACE)
	e2:SetValue(RACE_MACHINE)
	e2:SetReset(RESET_EVENT+0x1fe0000+RESET_PHASE+PHASE_END+RESET_SELF_TURN)
	tc:RegisterEffect(e2)
	end
end

