-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautoplay.js
More file actions
56 lines (45 loc) · 1.37 KB
/
autoplay.js
File metadata and controls
56 lines (45 loc) · 1.37 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
/**
* # Autoplay code
* Copyright(c) 2015 Stefano Balietti
* MIT Licensed
*
* Handles bidding, and responds between two players automatically.
*
* http://www.nodegame.org
*/
module.exports = function(treatmentName, settings, stager, setup, gameRoom) {
const ngc = require('nodegame-client');
var stager;
let game = gameRoom.getClientType('player');
game.nodename = 'autoplay';
game.env.allowTimeup = true;
// game.env.allowDisconnect = true;
game.nodename = 'autoplay';
stager = ngc.getStager(game.plot);
stager.extendAllSteps({
cb: function() {
if (node.env('allowDisconnect') && Math.random() < 0.5) {
node.socket.disconnect();
node.game.stop();
node.timer.randomExec(function() {
node.socket.reconnect();
}, 4000);
}
else {
if (!node.env('allowTimeup') || Math.random() < 0.5) {
node.timer.randomExec(function() {
button.click();
}, 3000);
}
}
}
});
// Gameover will be executed only in 'auto' mode.
stager.setOnGameOver(function() {
node.timer.randomExec(function() {
node.socket.disconnect();
window.close();
}, 60000);
});
return game;
};