trucoshi 0.1.8 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -4
- package/dist/lib/classes/Deck.js +9 -9
- package/dist/lib/classes/GameLoop.js +30 -72
- package/dist/lib/classes/Hand.js +87 -136
- package/dist/lib/classes/Lobby.d.ts +1 -1
- package/dist/lib/classes/Lobby.js +28 -29
- package/dist/lib/classes/Match.js +37 -80
- package/dist/lib/classes/Play.js +5 -5
- package/dist/lib/classes/Player.js +28 -38
- package/dist/lib/classes/Round.js +9 -10
- package/dist/lib/classes/Table.js +6 -6
- package/dist/lib/classes/Team.js +10 -12
- package/dist/lib/classes/Truco.js +25 -65
- package/dist/lib/constants.js +17 -18
- package/dist/lib/utils.js +7 -8
- package/dist/types.d.ts +43 -6
- package/dist/types.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,34 +1,57 @@
|
|
|
1
1
|
# Trucoshi
|
|
2
2
|
|
|
3
|
-
### English
|
|
3
|
+
### English
|
|
4
|
+
|
|
5
|
+
Work in progress
|
|
6
|
+
|
|
4
7
|
Pretends to be an Argentinian Truco game socket server that allows you to put Satoshis on the table ;)
|
|
5
8
|
|
|
9
|
+
Try current demo at [Trucoshi](https://trucoshi.com)
|
|
10
|
+
|
|
6
11
|
### Spanish
|
|
12
|
+
|
|
13
|
+
En construccion
|
|
14
|
+
|
|
7
15
|
Pretende ser un server basado en sockets del juego de Truco Argentino que te permita poner unos Satoshis en la mesa ;)
|
|
8
16
|
|
|
17
|
+
Proba la demo actual en [Trucoshi](https://trucoshi.com)
|
|
18
|
+
|
|
9
19
|
# Test
|
|
20
|
+
|
|
10
21
|
Right now there's only a local CLI way of playing as there is no socket server implementation and its just the game logic.
|
|
11
22
|
|
|
12
23
|
### Installation
|
|
24
|
+
|
|
13
25
|
`yarn`
|
|
14
26
|
|
|
27
|
+
### Build
|
|
28
|
+
|
|
29
|
+
`yarn build`
|
|
30
|
+
|
|
15
31
|
### Play
|
|
32
|
+
|
|
16
33
|
`yarn test:play`
|
|
17
34
|
|
|
18
35
|
### Autoplay
|
|
36
|
+
|
|
19
37
|
`yarn test:autoplay`
|
|
20
38
|
|
|
21
|
-
# Todo
|
|
39
|
+
# Todo
|
|
40
|
+
|
|
22
41
|
[x] Logica de turnos, rondas y battalla de cartas
|
|
23
42
|
[x] Irse al mazo
|
|
24
43
|
[] Cantar truco
|
|
25
44
|
[] Cantar envido
|
|
26
45
|
[] Cantar flor
|
|
27
|
-
[] Socket server
|
|
46
|
+
[x] Socket server
|
|
28
47
|
[] Bitcoin Lightning integration
|
|
29
48
|
[] Unit tests
|
|
30
49
|
|
|
31
|
-
#
|
|
50
|
+
# Donations
|
|
51
|
+
|
|
52
|
+
Donate Bitcoin at [jfrader.com](https://jfrader.com)
|
|
53
|
+
|
|
54
|
+
# License
|
|
32
55
|
|
|
33
56
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
34
57
|
|
package/dist/lib/classes/Deck.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlayedCard = exports.Deck = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
6
|
function Deck() {
|
|
7
|
-
|
|
7
|
+
const deck = {
|
|
8
8
|
cards: Object.keys(constants_1.CARDS),
|
|
9
9
|
usedCards: [],
|
|
10
|
-
takeCard
|
|
11
|
-
|
|
10
|
+
takeCard() {
|
|
11
|
+
const card = deck.cards.shift();
|
|
12
12
|
deck.usedCards.push(card);
|
|
13
13
|
return card;
|
|
14
14
|
},
|
|
15
|
-
shuffle
|
|
15
|
+
shuffle() {
|
|
16
16
|
deck.cards = deck.cards.concat(deck.usedCards);
|
|
17
17
|
deck.usedCards = [];
|
|
18
18
|
deck.cards = (0, utils_1.shuffleArray)(deck.cards);
|
|
@@ -26,9 +26,9 @@ function Deck() {
|
|
|
26
26
|
}
|
|
27
27
|
exports.Deck = Deck;
|
|
28
28
|
function PlayedCard(player, card) {
|
|
29
|
-
|
|
30
|
-
player
|
|
31
|
-
card
|
|
29
|
+
const pc = {
|
|
30
|
+
player,
|
|
31
|
+
card,
|
|
32
32
|
get key() {
|
|
33
33
|
return card + player.session;
|
|
34
34
|
},
|
|
@@ -8,93 +8,51 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.GameLoop = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_onTruco:
|
|
44
|
-
_onTurn:
|
|
45
|
-
_onWinner:
|
|
13
|
+
const types_1 = require("../../types");
|
|
14
|
+
const GameLoop = (match) => {
|
|
15
|
+
let gameloop = {
|
|
16
|
+
_onTruco: () => Promise.resolve(),
|
|
17
|
+
_onTurn: () => Promise.resolve(),
|
|
18
|
+
_onWinner: () => Promise.resolve(),
|
|
46
19
|
teams: [],
|
|
47
20
|
winner: null,
|
|
48
21
|
hands: [],
|
|
49
|
-
onTruco:
|
|
22
|
+
onTruco: (callback) => {
|
|
50
23
|
gameloop._onTruco = callback;
|
|
51
24
|
return gameloop;
|
|
52
25
|
},
|
|
53
|
-
onTurn:
|
|
26
|
+
onTurn: (callback) => {
|
|
54
27
|
gameloop._onTurn = callback;
|
|
55
28
|
return gameloop;
|
|
56
29
|
},
|
|
57
|
-
onWinner:
|
|
30
|
+
onWinner: (callback) => {
|
|
58
31
|
gameloop._onWinner = callback;
|
|
59
32
|
return gameloop;
|
|
60
33
|
},
|
|
61
|
-
begin
|
|
62
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
_a.sent();
|
|
80
|
-
return [3 /*break*/, 1];
|
|
81
|
-
case 3:
|
|
82
|
-
if (!(play.state === types_1.EHandState.WAITING_PLAY)) return [3 /*break*/, 5];
|
|
83
|
-
play.player.setTurn(true);
|
|
84
|
-
return [4 /*yield*/, gameloop._onTurn(play)];
|
|
85
|
-
case 4:
|
|
86
|
-
_a.sent();
|
|
87
|
-
play.player.setTurn(false);
|
|
88
|
-
return [3 /*break*/, 1];
|
|
89
|
-
case 5: return [3 /*break*/, 1];
|
|
90
|
-
case 6:
|
|
91
|
-
gameloop.winner = match.winner;
|
|
92
|
-
return [4 /*yield*/, gameloop._onWinner(match.winner, match.teams)];
|
|
93
|
-
case 7:
|
|
94
|
-
_a.sent();
|
|
95
|
-
return [2 /*return*/];
|
|
34
|
+
begin() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
gameloop.teams = match.teams;
|
|
37
|
+
while (!match.winner) {
|
|
38
|
+
const play = match.play();
|
|
39
|
+
gameloop.hands = match.hands;
|
|
40
|
+
if (!play || !play.player) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (play.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
44
|
+
yield gameloop._onTruco(play);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (play.state === types_1.EHandState.WAITING_PLAY) {
|
|
48
|
+
play.player.setTurn(true);
|
|
49
|
+
yield gameloop._onTurn(play);
|
|
50
|
+
play.player.setTurn(false);
|
|
51
|
+
continue;
|
|
96
52
|
}
|
|
97
|
-
}
|
|
53
|
+
}
|
|
54
|
+
gameloop.winner = match.winner;
|
|
55
|
+
yield gameloop._onWinner(match.winner, match.teams);
|
|
98
56
|
});
|
|
99
57
|
},
|
|
100
58
|
};
|
package/dist/lib/classes/Hand.js
CHANGED
|
@@ -1,152 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
-
function step(op) {
|
|
7
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
-
switch (op[0]) {
|
|
12
|
-
case 0: case 1: t = op; break;
|
|
13
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
-
default:
|
|
17
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
-
if (t[2]) _.ops.pop();
|
|
22
|
-
_.trys.pop(); continue;
|
|
23
|
-
}
|
|
24
|
-
op = body.call(thisArg, _);
|
|
25
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
3
|
exports.Hand = void 0;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const Deck_1 = require("./Deck");
|
|
7
|
+
const Play_1 = require("./Play");
|
|
8
|
+
const Round_1 = require("./Round");
|
|
9
|
+
const Truco_1 = require("./Truco");
|
|
37
10
|
function Hand(match, deck, idx) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var playerHand = [deck.takeCard(), deck.takeCard(), deck.takeCard()];
|
|
11
|
+
match.teams.forEach((team) => {
|
|
12
|
+
team.players.forEach((player) => {
|
|
13
|
+
const playerHand = [deck.takeCard(), deck.takeCard(), deck.takeCard()];
|
|
42
14
|
player.setHand(playerHand);
|
|
43
15
|
player.enable();
|
|
44
16
|
// player.setHand(["5c", "4c", "6c"])
|
|
45
17
|
});
|
|
46
18
|
});
|
|
47
|
-
function roundsGeneratorSequence() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
hand.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
_a.label = 2;
|
|
69
|
-
case 2:
|
|
70
|
-
if (!(round.turn < match.table.players.length)) return [3 /*break*/, 8];
|
|
71
|
-
_a.label = 3;
|
|
72
|
-
case 3:
|
|
73
|
-
if (!(hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER)) return [3 /*break*/, 6];
|
|
74
|
-
value = hand.truco.getNextPlayer().value;
|
|
75
|
-
if (!(value && value.currentPlayer)) return [3 /*break*/, 5];
|
|
76
|
-
hand.setCurrentPlayer(value.currentPlayer);
|
|
77
|
-
return [4 /*yield*/, hand];
|
|
78
|
-
case 4:
|
|
79
|
-
_a.sent();
|
|
80
|
-
_a.label = 5;
|
|
81
|
-
case 5: return [3 /*break*/, 3];
|
|
82
|
-
case 6:
|
|
83
|
-
player = match.table.player(hand.turn);
|
|
84
|
-
hand.setCurrentPlayer(player);
|
|
85
|
-
if (player.disabled) {
|
|
86
|
-
hand.setCurrentPlayer(null);
|
|
87
|
-
}
|
|
88
|
-
return [4 /*yield*/, hand];
|
|
89
|
-
case 7:
|
|
90
|
-
_a.sent();
|
|
91
|
-
return [3 /*break*/, 2];
|
|
92
|
-
case 8:
|
|
93
|
-
if (match.teams[0].isTeamDisabled() && match.teams[1].isTeamDisabled()) {
|
|
94
|
-
hand.setState(types_1.EHandState.FINISHED);
|
|
95
|
-
return [3 /*break*/, 9];
|
|
96
|
-
}
|
|
97
|
-
winnerTeamIdx = (0, utils_1.checkHandWinner)(hand.rounds, forehandTeamIdx);
|
|
98
|
-
if (match.teams[0].isTeamDisabled()) {
|
|
99
|
-
winnerTeamIdx = 1;
|
|
100
|
-
}
|
|
101
|
-
if (match.teams[1].isTeamDisabled()) {
|
|
102
|
-
winnerTeamIdx = 0;
|
|
103
|
-
}
|
|
104
|
-
if (winnerTeamIdx !== null) {
|
|
105
|
-
hand.addPoints(winnerTeamIdx, hand.truco.state);
|
|
106
|
-
hand.setState(types_1.EHandState.FINISHED);
|
|
19
|
+
function* roundsGeneratorSequence() {
|
|
20
|
+
let currentRoundIdx = 0;
|
|
21
|
+
let forehandTeamIdx = match.table.player(hand.turn).teamIdx;
|
|
22
|
+
while (currentRoundIdx < 3 && !hand.finished()) {
|
|
23
|
+
const round = (0, Round_1.Round)(0);
|
|
24
|
+
hand.setCurrentRound(round);
|
|
25
|
+
hand.pushRound(round);
|
|
26
|
+
let previousRound = hand.rounds[currentRoundIdx - 1];
|
|
27
|
+
// Put previous round winner as forehand
|
|
28
|
+
if (previousRound && previousRound.winner && !previousRound.tie) {
|
|
29
|
+
const newTurn = match.table.getPlayerPosition(previousRound.winner.id);
|
|
30
|
+
if (newTurn !== -1) {
|
|
31
|
+
hand.setTurn(newTurn);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
while (round.turn < match.table.players.length) {
|
|
35
|
+
while (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
36
|
+
const { value } = hand.truco.getNextPlayer();
|
|
37
|
+
if (value && value.currentPlayer) {
|
|
38
|
+
hand.setCurrentPlayer(value.currentPlayer);
|
|
39
|
+
yield hand;
|
|
107
40
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
41
|
+
}
|
|
42
|
+
const player = match.table.player(hand.turn);
|
|
43
|
+
hand.setCurrentPlayer(player);
|
|
44
|
+
if (player.disabled) {
|
|
45
|
+
hand.setCurrentPlayer(null);
|
|
46
|
+
}
|
|
47
|
+
yield hand;
|
|
114
48
|
}
|
|
115
|
-
|
|
49
|
+
if (match.teams[0].isTeamDisabled() && match.teams[1].isTeamDisabled()) {
|
|
50
|
+
hand.setState(types_1.EHandState.FINISHED);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
let winnerTeamIdx = (0, utils_1.checkHandWinner)(hand.rounds, forehandTeamIdx);
|
|
54
|
+
if (match.teams[0].isTeamDisabled()) {
|
|
55
|
+
winnerTeamIdx = 1;
|
|
56
|
+
}
|
|
57
|
+
if (match.teams[1].isTeamDisabled()) {
|
|
58
|
+
winnerTeamIdx = 0;
|
|
59
|
+
}
|
|
60
|
+
if (winnerTeamIdx !== null) {
|
|
61
|
+
hand.addPoints(winnerTeamIdx, hand.truco.state);
|
|
62
|
+
hand.setState(types_1.EHandState.FINISHED);
|
|
63
|
+
}
|
|
64
|
+
currentRoundIdx++;
|
|
65
|
+
}
|
|
66
|
+
yield hand;
|
|
116
67
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
68
|
+
const roundsGenerator = roundsGeneratorSequence();
|
|
69
|
+
const commands = {
|
|
70
|
+
[types_1.ESayCommand.MAZO]: (player) => {
|
|
120
71
|
hand.disablePlayer(player);
|
|
121
72
|
},
|
|
122
|
-
|
|
123
|
-
|
|
73
|
+
[types_1.ESayCommand.TRUCO]: (player) => {
|
|
74
|
+
const { teamIdx } = hand.truco;
|
|
124
75
|
if (teamIdx === null || teamIdx !== player.teamIdx) {
|
|
125
76
|
hand.setState(types_1.EHandState.WAITING_FOR_TRUCO_ANSWER);
|
|
126
77
|
hand.truco.sayTruco(player.teamIdx, match.teams[Number(!player.teamIdx)].players);
|
|
127
78
|
}
|
|
128
79
|
},
|
|
129
|
-
|
|
80
|
+
[types_1.ESayCommand.QUIERO]: () => {
|
|
130
81
|
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
131
82
|
hand.truco.setAnswer(true);
|
|
132
83
|
hand.setState(types_1.EHandState.WAITING_PLAY);
|
|
133
84
|
}
|
|
134
85
|
},
|
|
135
|
-
|
|
86
|
+
[types_1.ESayCommand.NO_QUIERO]: (player) => {
|
|
136
87
|
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
137
88
|
hand.truco.setAnswer(false);
|
|
138
89
|
hand.setState(types_1.EHandState.WAITING_PLAY);
|
|
139
90
|
}
|
|
140
91
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
idx
|
|
92
|
+
[types_1.ESayCommand.FLOR]: () => { },
|
|
93
|
+
[types_1.ESayCommand.CONTRAFLOR]: () => { },
|
|
94
|
+
[types_1.EEnvidoCommand.ENVIDO]: () => { },
|
|
95
|
+
[types_1.EEnvidoCommand.ENVIDO_ENVIDO]: () => { },
|
|
96
|
+
[types_1.EEnvidoCommand.REAL_ENVIDO]: () => { },
|
|
97
|
+
[types_1.EEnvidoCommand.FALTA_ENVIDO]: () => { },
|
|
98
|
+
};
|
|
99
|
+
const hand = {
|
|
100
|
+
idx,
|
|
150
101
|
turn: Number(match.table.forehandIdx),
|
|
151
102
|
state: types_1.EHandState.WAITING_PLAY,
|
|
152
103
|
rounds: [],
|
|
@@ -168,24 +119,24 @@ function Hand(match, deck, idx) {
|
|
|
168
119
|
}
|
|
169
120
|
return hand._currentPlayer;
|
|
170
121
|
},
|
|
171
|
-
commands
|
|
172
|
-
play
|
|
122
|
+
commands,
|
|
123
|
+
play() {
|
|
173
124
|
return (0, Play_1.PlayInstance)(hand, match.teams);
|
|
174
125
|
},
|
|
175
|
-
use
|
|
176
|
-
|
|
177
|
-
|
|
126
|
+
use(idx, card) {
|
|
127
|
+
const player = hand.currentPlayer;
|
|
128
|
+
const round = hand.currentRound;
|
|
178
129
|
if (!player || !round) {
|
|
179
130
|
return null;
|
|
180
131
|
}
|
|
181
|
-
|
|
132
|
+
const playerCard = player.useCard(idx, card);
|
|
182
133
|
if (playerCard) {
|
|
183
134
|
hand.nextTurn();
|
|
184
135
|
return round.use((0, Deck_1.PlayedCard)(player, playerCard));
|
|
185
136
|
}
|
|
186
137
|
return null;
|
|
187
138
|
},
|
|
188
|
-
nextTurn
|
|
139
|
+
nextTurn() {
|
|
189
140
|
var _a;
|
|
190
141
|
if (hand.turn >= match.table.players.length - 1) {
|
|
191
142
|
hand.setTurn(0);
|
|
@@ -195,36 +146,36 @@ function Hand(match, deck, idx) {
|
|
|
195
146
|
}
|
|
196
147
|
(_a = hand.currentRound) === null || _a === void 0 ? void 0 : _a.nextTurn();
|
|
197
148
|
},
|
|
198
|
-
getNextPlayer
|
|
149
|
+
getNextPlayer() {
|
|
199
150
|
return roundsGenerator.next();
|
|
200
151
|
},
|
|
201
|
-
disablePlayer
|
|
152
|
+
disablePlayer(player) {
|
|
202
153
|
match.teams[player.teamIdx].disable(player);
|
|
203
154
|
},
|
|
204
|
-
addPoints
|
|
155
|
+
addPoints(team, points) {
|
|
205
156
|
hand.points[team] = hand.points[team] + points;
|
|
206
157
|
},
|
|
207
|
-
pushRound
|
|
158
|
+
pushRound(round) {
|
|
208
159
|
hand.rounds.push(round);
|
|
209
160
|
return round;
|
|
210
161
|
},
|
|
211
|
-
setTurn
|
|
162
|
+
setTurn(turn) {
|
|
212
163
|
hand.turn = turn;
|
|
213
164
|
return match.table.player(hand.turn);
|
|
214
165
|
},
|
|
215
|
-
setCurrentRound
|
|
166
|
+
setCurrentRound(round) {
|
|
216
167
|
hand.currentRound = round;
|
|
217
168
|
return hand.currentRound;
|
|
218
169
|
},
|
|
219
|
-
setCurrentPlayer
|
|
170
|
+
setCurrentPlayer(player) {
|
|
220
171
|
hand._currentPlayer = player;
|
|
221
172
|
return hand._currentPlayer;
|
|
222
173
|
},
|
|
223
|
-
setState
|
|
174
|
+
setState(state) {
|
|
224
175
|
hand.state = state;
|
|
225
176
|
return hand.state;
|
|
226
177
|
},
|
|
227
|
-
finished:
|
|
178
|
+
finished: () => {
|
|
228
179
|
return hand.state === types_1.EHandState.FINISHED;
|
|
229
180
|
},
|
|
230
181
|
};
|
|
@@ -22,6 +22,6 @@ export interface IPrivateLobby {
|
|
|
22
22
|
calculateFull(): boolean;
|
|
23
23
|
startMatch(matchPoint?: 9 | 12 | 15): IGameLoop;
|
|
24
24
|
}
|
|
25
|
-
export interface ILobby extends Pick<IPrivateLobby, "addPlayer" | "removePlayer" | "startMatch" | "ready" | "full" | "started" | "teams" | "players" | "gameLoop" | "table" | "calculateReady"> {
|
|
25
|
+
export interface ILobby extends Pick<IPrivateLobby, "addPlayer" | "removePlayer" | "startMatch" | "ready" | "full" | "started" | "teams" | "players" | "gameLoop" | "table" | "maxPlayers" | "calculateReady"> {
|
|
26
26
|
}
|
|
27
27
|
export declare function Lobby(teamSize?: 1 | 2 | 3): ILobby;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Lobby = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
|
+
const GameLoop_1 = require("./GameLoop");
|
|
7
|
+
const Match_1 = require("./Match");
|
|
8
|
+
const Player_1 = require("./Player");
|
|
9
|
+
const Table_1 = require("./Table");
|
|
10
|
+
const Team_1 = require("./Team");
|
|
11
11
|
function Lobby(teamSize) {
|
|
12
|
-
|
|
12
|
+
const lobby = {
|
|
13
13
|
lastTeamIdx: 1,
|
|
14
14
|
_players: [],
|
|
15
15
|
get players() {
|
|
16
|
-
return lobby._players.filter(
|
|
16
|
+
return lobby._players.filter((player) => Boolean(player && player.id));
|
|
17
17
|
},
|
|
18
18
|
teams: [],
|
|
19
19
|
table: null,
|
|
@@ -22,20 +22,20 @@ function Lobby(teamSize) {
|
|
|
22
22
|
ready: false,
|
|
23
23
|
started: false,
|
|
24
24
|
gameLoop: undefined,
|
|
25
|
-
calculateReady
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
lobby.players.filter(
|
|
29
|
-
|
|
25
|
+
calculateReady() {
|
|
26
|
+
const allPlayersReady = lobby.players.reduce((prev, curr) => Boolean(prev && curr && curr.ready), true);
|
|
27
|
+
const teamsSameSize = lobby.players.filter((player) => player.teamIdx === 0).length ===
|
|
28
|
+
lobby.players.filter((player) => player.teamIdx === 1).length;
|
|
29
|
+
const allTeamsComplete = lobby.players.length % 2 === 0;
|
|
30
30
|
lobby.ready = allPlayersReady && allTeamsComplete && teamsSameSize;
|
|
31
31
|
return lobby.ready;
|
|
32
32
|
},
|
|
33
|
-
calculateFull
|
|
33
|
+
calculateFull() {
|
|
34
34
|
lobby.full = lobby.players.length >= lobby.maxPlayers;
|
|
35
35
|
return lobby.full;
|
|
36
36
|
},
|
|
37
|
-
addPlayer
|
|
38
|
-
|
|
37
|
+
addPlayer(id, session, teamIdx, isOwner) {
|
|
38
|
+
const exists = lobby.players.find((player) => player.session === session);
|
|
39
39
|
if (exists) {
|
|
40
40
|
if (exists.teamIdx === teamIdx) {
|
|
41
41
|
return exists;
|
|
@@ -48,15 +48,15 @@ function Lobby(teamSize) {
|
|
|
48
48
|
if (lobby.full) {
|
|
49
49
|
throw new Error(types_1.GAME_ERROR.LOBBY_IS_FULL);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const maxSize = teamSize ? teamSize : 3;
|
|
52
52
|
if (lobby.full ||
|
|
53
|
-
lobby.players.filter(
|
|
53
|
+
lobby.players.filter((player) => player.teamIdx === teamIdx).length > maxSize) {
|
|
54
54
|
throw new Error(types_1.GAME_ERROR.TEAM_IS_FULL);
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
const player = (0, Player_1.Player)(id, teamIdx !== undefined ? teamIdx : Number(!lobby.lastTeamIdx), isOwner);
|
|
57
57
|
player.setSession(session);
|
|
58
58
|
lobby.lastTeamIdx = Number(!lobby.lastTeamIdx);
|
|
59
|
-
for (
|
|
59
|
+
for (let i = 0; i < lobby._players.length; i++) {
|
|
60
60
|
if (!lobby._players[i].id) {
|
|
61
61
|
if (player.teamIdx === 0 && i % 2 === 0) {
|
|
62
62
|
lobby._players[i] = player;
|
|
@@ -72,8 +72,8 @@ function Lobby(teamSize) {
|
|
|
72
72
|
lobby.calculateReady();
|
|
73
73
|
return player;
|
|
74
74
|
},
|
|
75
|
-
removePlayer
|
|
76
|
-
|
|
75
|
+
removePlayer(session) {
|
|
76
|
+
const idx = lobby._players.findIndex((player) => player && player.session === session);
|
|
77
77
|
if (idx !== -1) {
|
|
78
78
|
lobby._players[idx] = {};
|
|
79
79
|
lobby.calculateFull();
|
|
@@ -81,10 +81,9 @@ function Lobby(teamSize) {
|
|
|
81
81
|
}
|
|
82
82
|
return lobby;
|
|
83
83
|
},
|
|
84
|
-
startMatch
|
|
85
|
-
if (matchPoint === void 0) { matchPoint = 9; }
|
|
84
|
+
startMatch(matchPoint = 9) {
|
|
86
85
|
lobby.calculateReady();
|
|
87
|
-
|
|
86
|
+
const actualTeamSize = lobby.players.length / 2;
|
|
88
87
|
if (!constants_1.TEAM_SIZE_VALUES.includes(actualTeamSize)) {
|
|
89
88
|
throw new Error(types_1.GAME_ERROR.UNEXPECTED_TEAM_SIZE);
|
|
90
89
|
}
|
|
@@ -92,8 +91,8 @@ function Lobby(teamSize) {
|
|
|
92
91
|
throw new Error(types_1.GAME_ERROR.TEAM_NOT_READY);
|
|
93
92
|
}
|
|
94
93
|
lobby.teams = [
|
|
95
|
-
(0, Team_1.Team)(lobby.players.filter(
|
|
96
|
-
(0, Team_1.Team)(lobby.players.filter(
|
|
94
|
+
(0, Team_1.Team)(lobby.players.filter((player) => player.teamIdx === 0)),
|
|
95
|
+
(0, Team_1.Team)(lobby.players.filter((player) => player.teamIdx === 1)),
|
|
97
96
|
];
|
|
98
97
|
if (lobby.teams[0].players.length !== actualTeamSize ||
|
|
99
98
|
lobby.teams[1].players.length !== actualTeamSize) {
|
|
@@ -105,7 +104,7 @@ function Lobby(teamSize) {
|
|
|
105
104
|
return lobby.gameLoop;
|
|
106
105
|
},
|
|
107
106
|
};
|
|
108
|
-
for (
|
|
107
|
+
for (let i = 0; i < lobby.maxPlayers; i++) {
|
|
109
108
|
lobby._players.push({});
|
|
110
109
|
}
|
|
111
110
|
return lobby;
|