x020015_g_scriptId=020015

x020015_g_BluePosX=82.55
x020015_g_BluePosZ=63.84731

x020015_g_RedPosX=40.76271
x020015_g_RedPosZ=63.75672

x020015_g_RobotRoleBaseId=0 --机器人ID

function x020015_OnObjEnter(scene,objId)

	if(x020015_g_Start == 1) then
		return
	end
	
	if(x020015_g_BluePlayerId == nil) then
		x020015_g_BluePlayerId = objId
		x020015_g_BluePlayerGuid = tostring(GetPlayerGuidById(scene,x020015_g_BluePlayerId)) 
		SetPos(scene,objId,x020015_g_BluePosX,x020015_g_BluePosZ,-3.14)
		TestFullHp(scene,objId)
		SetPvpCamp(scene,objId,6)
		RemoveCDTime(scene,objId)
		AutoCombat(scene,objId,true)
		x020015_g_RobotRoleBaseId = GetRobotRoleBaseIdByIndex(scene,0)
		if (x020015_g_RobotRoleBaseId > 0) then
			x020015_g_RedPlayerId = CreateMonster(scene,x020015_g_RobotRoleBaseId,0,x020015_g_RedPosX,x020015_g_RedPosZ)
			if (x020015_g_Start == nil) then
				x020015_g_Start = 1
			end
		end
	end
end

function x020015_OnObjLeave(scene,objId,rolebaseId)
	x020015_Modify(scene,objId)
end

function x020015_OnObjDie(scene,objId,rolebaseId,killerId)
	x020015_Modify(scene,objId)
end

function x020015_Modify(scene,objId)
	if (x020015_g_BluePlayerId ~= nil) and (GetCopySceneStatus(scene) < 4) then
		if	(objId == x020015_g_BluePlayerId) then
			RecordPvpRankData(scene,x020015_g_BluePlayerGuid,"0",1,false,true,GetRobotNameByIndex(scene,0))
		elseif(objId == x020015_g_RedPlayerId) then
			RecordPvpRankData(scene,x020015_g_BluePlayerGuid,"0",1,true,true,GetRobotNameByIndex(scene,0))
		else
			return
		end
		x020015_g_BluePlayerId = nil
		x020015_Succeed(scene)
		SetCopySceneSuccess(scene)
	end
end

function x020015_Succeed(scene)

	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do		
		local nUserObjId = GetUserObjIdByIdx(scene,i)
		AddActivtyNum(scene, nUserObjId , 8)
		SetHpFull(scene,nUserObjId)
		RemoveCDTime(scene,nUserObjId)
		SetPvpCamp(scene,nUserObjId,1)
	end
end



