This repository was archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathentityManager.js
More file actions
57 lines (46 loc) · 1.35 KB
/
entityManager.js
File metadata and controls
57 lines (46 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var EntityCollection = function() {
this.entities = [];
this.itemcount = 0;
};
EntityCollection.prototype.add = function(item) {
this.entities[item.entityId] = item;
this.itemcount++;
};
EntityCollection.prototype.remove = function(itemId) {
var idFilter = function(item, index) {
return item.entityId===itemId;
};
delete this.entities[itemId];
this.itemcount--;
};
EntityCollection.prototype.getAll = function() {
return this.entities;
}
EntityCollection.prototype.count = function() {
return this.itemcount;
}
EntityCollection.prototype.getItemsInVisualRange = function(position) {
var visualDistanceFilter = function(item) {
var xs = item.x - position.x;
xs = xs * xs;
var ys = item.y - position.y;
ys = ys * ys;
var zs = item.z - position.z;
zs = zs * zs;
return xs+ys+zs < 1000000;//TODO: Need to get the correct value for this. Per player?
};
return this.entities.filter(visualDistanceFilter);
};
EntityCollection.prototype.getItemsInPickupRange = function(position) {
var pickupDistanceFilter = function(item) {
var xs = item.x - position.x;
xs = xs * xs;
var ys = item.y - position.y;
ys = ys * ys;
var zs = item.z - position.z;
zs = zs * zs;
return xs+ys+zs < 2200; //TODO: Need to get the correct value for this
};
return this.entities.filter(pickupDistanceFilter);
};
module.exports = EntityCollection;