forked from cryptovoxels/scripting-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.js
86 lines (79 loc) · 2.18 KB
/
player.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const EventEmitter = require("events");
const { throttle } = require("lodash");
const emojis = require("./helpers.js").emojis;
const animations = require("./helpers.js").animations;
class Player extends EventEmitter {
constructor(description, parcel) {
super();
Object.assign(this, description);
this.parcel = parcel;
this.uuid = description && description.uuid;
this.name = description && description.name;
this.wallet = description && description.wallet;
this.position = new Vector3();
this.rotation = new Vector3();
this.collectibles = description && description.collectibles;
}
emote = throttle(
(emoji) => {
if(!emojis.includes(emoji)){
return
}
this.parcel.broadcast({
type: "player-emote",
uuid: this.uuid,
emote: emoji,
});
},
500,
{ leading: true, trailing: false }
);
animate = throttle(
(animation) => {
const a = animations.find((a)=>a.name==animation)
if(!a){
return
}
this.parcel.broadcast({
type: "player-animate",
uuid: this.uuid,
animation: a.animation,
});
},
10000,
{ leading: true, trailing: false }
);
teleportTo(coords) {
if (!coords || coords == "") {
return;
}
// Avoid spamming of teleport
if (this._numTeleport++ > 5) {
setTimeout(() => {
this._numTeleport = 0;
}, 4000);
return;
}
this._numTeleport++;
this.parcel.broadcast({
type: "player-teleport",
uuid: this.uuid,
coordinates: coords,
});
}
hasWearable(tokenId, collectionId = 1) {
return !!this.collectibles.find((c) => {
let collection_id = c.collection_id || 1;
return c.wearable_id == tokenId && collectionId == collection_id;
});
}
get isAnonymous() {
return this.name.toLowerCase() == "Anonymous".toLowerCase();
}
onMove(msg) {
this.position.set(msg.position[0], msg.position[1], msg.position[2]);
this.rotation.set(msg.rotation[0], msg.rotation[1], msg.rotation[2]);
this.emit("move", msg);
}
}
module.exports = Player;