-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_surrender.js
71 lines (57 loc) · 1.85 KB
/
action_surrender.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
//"use strict";
//
// action_surrender.js
//
// Created by Alezia Kurdis, December 4th, 2022.
// Copyright 2022 Alezia Kurdis.
//
// Black Jack Game for Overte - trigger to stand.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function(){
var jsMainFileName = "action_surrender.js";
var ROOT = Script.resolvePath('').split(jsMainFileName)[0];
var channelComm = "ak.blackJack.ac.communication";
var oneTimeOnly = false;
function pay(entityID) {
if (oneTimeOnly === false) {
var message = {
"action": "ACTION_SURRENDER",
"avatarID": MyAvatar.sessionUUID
};
Messages.sendMessage(channelComm, JSON.stringify(message));
oneTimeOnly = true;
}
};
var MAX_CLICKABLE_DISTANCE_M = 2;
// Constructor
var _this = null;
function clickableUI() {
_this = this;
this.entityID = null;
}
// Entity methods
clickableUI.prototype = {
preload: function (id) {
_this.entityID = id;
HMD.displayModeChanged.connect(this.displayModeChangedCallback);
},
displayModeChangedCallback: function() {
if (_this && _this.entityID) {
//Nothing
}
},
mousePressOnEntity: function (entityID, event) {
if (event.isPrimaryButton &&
Vec3.distance(MyAvatar.position, Entities.getEntityProperties(_this.entityID, ["position"]).position) <= MAX_CLICKABLE_DISTANCE_M) {
pay(_this.entityID);
}
},
unload: function () {
HMD.displayModeChanged.disconnect(this.displayModeChangedCallback);
}
};
return new clickableUI();
})