var Tree = require('../entities/Tree');
var GameObj = require('../entities/GameObject');
var Utils = require('../utils/Utils');

class GameManager {
	getObjsNear(socket, radius) {
		var px = socket.player.x;
		var py = socket.player.y;
		var x1 = px - radius;
		var x2 = px + radius;
		var y1 = py - radius;
		var y2 = py + radius;
		var near = [];
		for (var i = 0; i < this.objs.length; ++i) {
			var x = this.objs[i].x;
			var y = this.objs[i].y;
			if ((x1 <= x && x <= x2) &&
				(y1 <= y && y <= y2)) {
				near.push(this.objs[i]);
			}
		}
		socket.player.objsNear = near;
		return near;
	}
	getRandCoord() {
		var me = this;
		return Utils.rand(me.gameServer.config.mapSize);
	}
	generateObjects(amount) {
		// Create random objects
		this.objLen = amount;
		for (var i = 0; i < amount; ++i) {
			// For now just generate trees
			this.objs.push(new Tree(i));
			this.objs[i].x = this.getRandCoord();
			this.objs[i].y = this.getRandCoord();
		}
	}
	constructor(gameServer) {
		this.gameServer = gameServer;
		this.objs = [];
		this.objLen = 0;
	}
}
module.exports = GameManager;
@@ -169,24 +169,41 @@
 , radius) %7B%0A
+%09%09var me = this;%0A
 %09%09var px = s
@@ -548,16 +548,164 @@
 js%5Bi%5D);%0A
+%09%09%09%09if (!socket.player.objsNear.includes(this.objs%5Bi%5D)) %7B%0A%09%09%09%09%09var data = this.objs%5Bi%5D.serialize();%0A%09%09%09%09%09me.gameServer.manager.sendObj(data);%0A%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Implement sendObj method