trucoshi 0.2.11 → 0.2.13
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/LICENSE +674 -674
- package/README.md +60 -60
- package/dist/index.d.ts +3 -2
- package/dist/index.js +19 -18
- package/dist/lib/classes/Deck.d.ts +17 -17
- package/dist/lib/classes/Deck.js +41 -41
- package/dist/lib/classes/GameLoop.d.ts +23 -22
- package/dist/lib/classes/GameLoop.js +76 -74
- package/dist/lib/classes/Hand.d.ts +39 -38
- package/dist/lib/classes/Hand.js +192 -187
- package/dist/lib/classes/Lobby.d.ts +27 -27
- package/dist/lib/classes/Lobby.js +113 -113
- package/dist/lib/classes/Match.d.ts +20 -18
- package/dist/lib/classes/Match.js +87 -81
- package/dist/lib/classes/Play.d.ts +21 -20
- package/dist/lib/classes/Play.js +29 -28
- package/dist/lib/classes/Player.d.ts +32 -32
- package/dist/lib/classes/Player.js +79 -78
- package/dist/lib/classes/Round.d.ts +17 -17
- package/dist/lib/classes/Round.js +33 -33
- package/dist/lib/classes/Table.d.ts +12 -12
- package/dist/lib/classes/Table.js +30 -30
- package/dist/lib/classes/Team.d.ts +20 -20
- package/dist/lib/classes/Team.js +59 -59
- package/dist/lib/classes/Truco.d.ts +21 -20
- package/dist/lib/classes/Truco.js +131 -126
- package/dist/lib/classes/index.d.ts +11 -11
- package/dist/lib/classes/index.js +27 -27
- package/dist/lib/constants.d.ts +45 -45
- package/dist/lib/constants.js +84 -84
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/index.js +18 -18
- package/dist/lib/types.d.ts +50 -50
- package/dist/lib/types.js +34 -34
- package/dist/lib/utils.d.ts +5 -5
- package/dist/lib/utils.js +58 -58
- package/dist/types.d.ts +173 -167
- package/dist/types.js +106 -98
- package/package.json +13 -6
package/dist/lib/classes/Hand.js
CHANGED
|
@@ -1,187 +1,192 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Hand = void 0;
|
|
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");
|
|
10
|
-
function Hand(match, deck, idx) {
|
|
11
|
-
for (const team of match.teams) {
|
|
12
|
-
for (const player of team.players) {
|
|
13
|
-
player.enable();
|
|
14
|
-
player.setHand(deck.takeThree());
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function* roundsGeneratorSequence() {
|
|
18
|
-
let currentRoundIdx = 0;
|
|
19
|
-
let forehandTeamIdx = match.table.player(hand.turn).teamIdx;
|
|
20
|
-
while (currentRoundIdx < 3 && !hand.finished()) {
|
|
21
|
-
const round = (0, Round_1.Round)();
|
|
22
|
-
hand.setCurrentRound(round);
|
|
23
|
-
hand.pushRound(round);
|
|
24
|
-
let previousRound = hand.rounds[currentRoundIdx - 1];
|
|
25
|
-
// Put previous round winner as forehand
|
|
26
|
-
if (previousRound && previousRound.winner && !previousRound.tie) {
|
|
27
|
-
const newTurn = match.table.getPlayerPosition(previousRound.winner.id);
|
|
28
|
-
if (newTurn !== -1) {
|
|
29
|
-
hand.setTurn(newTurn);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
while (round.turn < match.table.players.length) {
|
|
33
|
-
while (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
34
|
-
const { value } = hand.truco.getNextPlayer();
|
|
35
|
-
if (value && value.currentPlayer) {
|
|
36
|
-
hand.setCurrentPlayer(value.currentPlayer);
|
|
37
|
-
yield hand;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (hand.truco.answer === false) {
|
|
41
|
-
hand.setState(types_1.EHandState.FINISHED);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
const player = match.table.player(hand.turn);
|
|
45
|
-
hand.setCurrentPlayer(player);
|
|
46
|
-
if (player.disabled
|
|
47
|
-
hand.setCurrentPlayer(null);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (match.teams[
|
|
57
|
-
winnerTeamIdx =
|
|
58
|
-
}
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
hand.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
[types_1.
|
|
98
|
-
[types_1.
|
|
99
|
-
[types_1.EEnvidoCommand.
|
|
100
|
-
[types_1.EEnvidoCommand.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Hand = void 0;
|
|
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");
|
|
10
|
+
function Hand(match, deck, idx) {
|
|
11
|
+
for (const team of match.teams) {
|
|
12
|
+
for (const player of team.players) {
|
|
13
|
+
player.enable();
|
|
14
|
+
player.setHand(deck.takeThree());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function* roundsGeneratorSequence() {
|
|
18
|
+
let currentRoundIdx = 0;
|
|
19
|
+
let forehandTeamIdx = match.table.player(hand.turn).teamIdx;
|
|
20
|
+
while (currentRoundIdx < 3 && !hand.finished()) {
|
|
21
|
+
const round = (0, Round_1.Round)();
|
|
22
|
+
hand.setCurrentRound(round);
|
|
23
|
+
hand.pushRound(round);
|
|
24
|
+
let previousRound = hand.rounds[currentRoundIdx - 1];
|
|
25
|
+
// Put previous round winner as forehand
|
|
26
|
+
if (previousRound && previousRound.winner && !previousRound.tie) {
|
|
27
|
+
const newTurn = match.table.getPlayerPosition(previousRound.winner.id);
|
|
28
|
+
if (newTurn !== -1) {
|
|
29
|
+
hand.setTurn(newTurn);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
while (round.turn < match.table.players.length) {
|
|
33
|
+
while (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
34
|
+
const { value } = hand.truco.getNextPlayer();
|
|
35
|
+
if (value && value.currentPlayer) {
|
|
36
|
+
hand.setCurrentPlayer(value.currentPlayer);
|
|
37
|
+
yield hand;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (hand.truco.answer === false) {
|
|
41
|
+
hand.setState(types_1.EHandState.FINISHED);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
const player = match.table.player(hand.turn);
|
|
45
|
+
hand.setCurrentPlayer(player);
|
|
46
|
+
if (player.disabled) {
|
|
47
|
+
hand.setCurrentPlayer(null);
|
|
48
|
+
}
|
|
49
|
+
if (match.teams.some((team) => team.isTeamDisabled())) {
|
|
50
|
+
hand.setState(types_1.EHandState.FINISHED);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
yield hand;
|
|
54
|
+
}
|
|
55
|
+
let winnerTeamIdx = (0, utils_1.checkHandWinner)(hand.rounds, forehandTeamIdx);
|
|
56
|
+
if (match.teams[0].isTeamDisabled()) {
|
|
57
|
+
winnerTeamIdx = 1;
|
|
58
|
+
}
|
|
59
|
+
if (match.teams[1].isTeamDisabled()) {
|
|
60
|
+
winnerTeamIdx = 0;
|
|
61
|
+
}
|
|
62
|
+
if (winnerTeamIdx !== null) {
|
|
63
|
+
hand.addPoints(winnerTeamIdx, hand.truco.state);
|
|
64
|
+
hand.setState(types_1.EHandState.FINISHED);
|
|
65
|
+
}
|
|
66
|
+
currentRoundIdx++;
|
|
67
|
+
}
|
|
68
|
+
yield hand;
|
|
69
|
+
}
|
|
70
|
+
const roundsGenerator = roundsGeneratorSequence();
|
|
71
|
+
const commands = {
|
|
72
|
+
[types_1.ESayCommand.MAZO]: (player) => {
|
|
73
|
+
hand.disablePlayer(player);
|
|
74
|
+
hand.setState(types_1.EHandState.WAITING_PLAY);
|
|
75
|
+
hand.truco.reset();
|
|
76
|
+
hand.nextTurn();
|
|
77
|
+
},
|
|
78
|
+
[types_1.ESayCommand.TRUCO]: (player) => {
|
|
79
|
+
hand.truco.sayTruco(player, () => {
|
|
80
|
+
hand.setState(types_1.EHandState.WAITING_FOR_TRUCO_ANSWER);
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
[types_1.ESayCommand.QUIERO]: (player) => {
|
|
84
|
+
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
85
|
+
hand.truco.sayAnswer(player, true, () => {
|
|
86
|
+
hand.setState(types_1.EHandState.WAITING_PLAY);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
[types_1.ESayCommand.NO_QUIERO]: (player) => {
|
|
91
|
+
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
92
|
+
hand.truco.sayAnswer(player, false, () => {
|
|
93
|
+
hand.setState(types_1.EHandState.WAITING_PLAY);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
[types_1.ESayCommand.FLOR]: () => { },
|
|
98
|
+
[types_1.ESayCommand.CONTRAFLOR]: () => { },
|
|
99
|
+
[types_1.EEnvidoCommand.ENVIDO]: () => { },
|
|
100
|
+
[types_1.EEnvidoCommand.ENVIDO_ENVIDO]: () => { },
|
|
101
|
+
[types_1.EEnvidoCommand.REAL_ENVIDO]: () => { },
|
|
102
|
+
[types_1.EEnvidoCommand.FALTA_ENVIDO]: () => { },
|
|
103
|
+
};
|
|
104
|
+
const hand = {
|
|
105
|
+
idx,
|
|
106
|
+
started: false,
|
|
107
|
+
turn: Number(match.table.forehandIdx),
|
|
108
|
+
state: types_1.EHandState.WAITING_PLAY,
|
|
109
|
+
rounds: [],
|
|
110
|
+
truco: (0, Truco_1.Truco)(match.teams),
|
|
111
|
+
envido: {
|
|
112
|
+
accept: 1,
|
|
113
|
+
decline: 2,
|
|
114
|
+
teamIdx: null,
|
|
115
|
+
},
|
|
116
|
+
points: [0, 0],
|
|
117
|
+
currentRound: null,
|
|
118
|
+
_currentPlayer: null,
|
|
119
|
+
set currentPlayer(player) {
|
|
120
|
+
hand._currentPlayer = player;
|
|
121
|
+
},
|
|
122
|
+
get currentPlayer() {
|
|
123
|
+
if (hand.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
|
|
124
|
+
return hand.truco.currentPlayer;
|
|
125
|
+
}
|
|
126
|
+
return hand._currentPlayer;
|
|
127
|
+
},
|
|
128
|
+
commands,
|
|
129
|
+
play(prevHand) {
|
|
130
|
+
return (0, Play_1.PlayInstance)(hand, prevHand, match.teams);
|
|
131
|
+
},
|
|
132
|
+
use(idx, card) {
|
|
133
|
+
hand.started = true;
|
|
134
|
+
const player = hand.currentPlayer;
|
|
135
|
+
const round = hand.currentRound;
|
|
136
|
+
if (!player || !round) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const playerCard = player.useCard(idx, card);
|
|
140
|
+
if (playerCard) {
|
|
141
|
+
const card = round.use((0, Deck_1.PlayedCard)(player, playerCard));
|
|
142
|
+
hand.nextTurn();
|
|
143
|
+
return card;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
},
|
|
147
|
+
nextTurn() {
|
|
148
|
+
var _a;
|
|
149
|
+
if (hand.turn >= match.table.players.length - 1) {
|
|
150
|
+
hand.setTurn(0);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
hand.setTurn(hand.turn + 1);
|
|
154
|
+
}
|
|
155
|
+
(_a = hand.currentRound) === null || _a === void 0 ? void 0 : _a.nextTurn();
|
|
156
|
+
},
|
|
157
|
+
getNextPlayer() {
|
|
158
|
+
return roundsGenerator.next();
|
|
159
|
+
},
|
|
160
|
+
disablePlayer(player) {
|
|
161
|
+
match.teams[player.teamIdx].disable(player);
|
|
162
|
+
},
|
|
163
|
+
addPoints(team, points) {
|
|
164
|
+
hand.points[team] = hand.points[team] + points;
|
|
165
|
+
},
|
|
166
|
+
pushRound(round) {
|
|
167
|
+
hand.rounds.push(round);
|
|
168
|
+
return round;
|
|
169
|
+
},
|
|
170
|
+
setTurn(turn) {
|
|
171
|
+
hand.turn = turn;
|
|
172
|
+
return match.table.player(hand.turn);
|
|
173
|
+
},
|
|
174
|
+
setCurrentRound(round) {
|
|
175
|
+
hand.currentRound = round;
|
|
176
|
+
return hand.currentRound;
|
|
177
|
+
},
|
|
178
|
+
setCurrentPlayer(player) {
|
|
179
|
+
hand._currentPlayer = player;
|
|
180
|
+
return hand._currentPlayer;
|
|
181
|
+
},
|
|
182
|
+
setState(state) {
|
|
183
|
+
hand.state = state;
|
|
184
|
+
return hand.state;
|
|
185
|
+
},
|
|
186
|
+
finished: () => {
|
|
187
|
+
return hand.state === types_1.EHandState.FINISHED;
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
return hand;
|
|
191
|
+
}
|
|
192
|
+
exports.Hand = Hand;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { IGameLoop } from "./GameLoop";
|
|
2
|
-
import { IPlayer } from "./Player";
|
|
3
|
-
import { ITable } from "./Table";
|
|
4
|
-
import { ITeam } from "./Team";
|
|
5
|
-
export interface IPrivateLobby {
|
|
6
|
-
gameLoop?: IGameLoop;
|
|
7
|
-
lastTeamIdx: 0 | 1;
|
|
8
|
-
_players: Array<IPlayer | {
|
|
9
|
-
id?: undefined;
|
|
10
|
-
session?: undefined;
|
|
11
|
-
}>;
|
|
12
|
-
get players(): Array<IPlayer>;
|
|
13
|
-
teams: Array<ITeam>;
|
|
14
|
-
maxPlayers: number;
|
|
15
|
-
table: ITable | null;
|
|
16
|
-
full: boolean;
|
|
17
|
-
ready: boolean;
|
|
18
|
-
started: boolean;
|
|
19
|
-
addPlayer(key: string, id: string, session: string, teamIdx?: 0 | 1, isOwner?: boolean): IPlayer;
|
|
20
|
-
removePlayer(session: string): ILobby;
|
|
21
|
-
calculateReady(): boolean;
|
|
22
|
-
calculateFull(): boolean;
|
|
23
|
-
startMatch(matchPoint?: 9 | 12 | 15): IGameLoop;
|
|
24
|
-
}
|
|
25
|
-
export interface ILobby extends Pick<IPrivateLobby, "addPlayer" | "removePlayer" | "startMatch" | "ready" | "full" | "started" | "teams" | "players" | "gameLoop" | "table" | "maxPlayers" | "calculateReady"> {
|
|
26
|
-
}
|
|
27
|
-
export declare function Lobby(teamSize?: 1 | 2 | 3): ILobby;
|
|
1
|
+
import { IGameLoop } from "./GameLoop";
|
|
2
|
+
import { IPlayer } from "./Player";
|
|
3
|
+
import { ITable } from "./Table";
|
|
4
|
+
import { ITeam } from "./Team";
|
|
5
|
+
export interface IPrivateLobby {
|
|
6
|
+
gameLoop?: IGameLoop;
|
|
7
|
+
lastTeamIdx: 0 | 1;
|
|
8
|
+
_players: Array<IPlayer | {
|
|
9
|
+
id?: undefined;
|
|
10
|
+
session?: undefined;
|
|
11
|
+
}>;
|
|
12
|
+
get players(): Array<IPlayer>;
|
|
13
|
+
teams: Array<ITeam>;
|
|
14
|
+
maxPlayers: number;
|
|
15
|
+
table: ITable | null;
|
|
16
|
+
full: boolean;
|
|
17
|
+
ready: boolean;
|
|
18
|
+
started: boolean;
|
|
19
|
+
addPlayer(key: string, id: string, session: string, teamIdx?: 0 | 1, isOwner?: boolean): IPlayer;
|
|
20
|
+
removePlayer(session: string): ILobby;
|
|
21
|
+
calculateReady(): boolean;
|
|
22
|
+
calculateFull(): boolean;
|
|
23
|
+
startMatch(matchPoint?: 9 | 12 | 15): IGameLoop;
|
|
24
|
+
}
|
|
25
|
+
export interface ILobby extends Pick<IPrivateLobby, "addPlayer" | "removePlayer" | "startMatch" | "ready" | "full" | "started" | "teams" | "players" | "gameLoop" | "table" | "maxPlayers" | "calculateReady"> {
|
|
26
|
+
}
|
|
27
|
+
export declare function Lobby(teamSize?: 1 | 2 | 3): ILobby;
|