trucoshi 0.3.4 → 0.3.51

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.
Files changed (42) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +60 -60
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +18 -18
  5. package/dist/lib/classes/Deck.d.ts +17 -17
  6. package/dist/lib/classes/Deck.js +41 -41
  7. package/dist/lib/classes/Envido.d.ts +34 -34
  8. package/dist/lib/classes/Envido.js +168 -167
  9. package/dist/lib/classes/Flor.js +1 -1
  10. package/dist/lib/classes/GameLoop.d.ts +28 -26
  11. package/dist/lib/classes/GameLoop.js +115 -105
  12. package/dist/lib/classes/Hand.d.ts +43 -43
  13. package/dist/lib/classes/Hand.js +295 -295
  14. package/dist/lib/classes/Lobby.d.ts +27 -27
  15. package/dist/lib/classes/Lobby.js +113 -113
  16. package/dist/lib/classes/Match.d.ts +21 -21
  17. package/dist/lib/classes/Match.js +90 -88
  18. package/dist/lib/classes/Play.d.ts +22 -22
  19. package/dist/lib/classes/Play.js +44 -44
  20. package/dist/lib/classes/Player.d.ts +35 -35
  21. package/dist/lib/classes/Player.js +114 -126
  22. package/dist/lib/classes/Round.d.ts +17 -17
  23. package/dist/lib/classes/Round.js +33 -33
  24. package/dist/lib/classes/Table.d.ts +12 -12
  25. package/dist/lib/classes/Table.js +38 -38
  26. package/dist/lib/classes/Team.d.ts +20 -20
  27. package/dist/lib/classes/Team.js +59 -59
  28. package/dist/lib/classes/Truco.d.ts +30 -30
  29. package/dist/lib/classes/Truco.js +97 -97
  30. package/dist/lib/classes/index.d.ts +11 -11
  31. package/dist/lib/classes/index.js +27 -27
  32. package/dist/lib/constants.d.ts +43 -43
  33. package/dist/lib/constants.js +46 -46
  34. package/dist/lib/index.d.ts +2 -2
  35. package/dist/lib/index.js +18 -18
  36. package/dist/lib/types.d.ts +44 -44
  37. package/dist/lib/types.js +21 -21
  38. package/dist/lib/utils.d.ts +5 -5
  39. package/dist/lib/utils.js +58 -58
  40. package/dist/types.d.ts +195 -184
  41. package/dist/types.js +123 -121
  42. package/package.json +1 -1
@@ -1,113 +1,113 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Lobby = void 0;
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
- function Lobby(teamSize) {
12
- const lobby = {
13
- lastTeamIdx: 1,
14
- _players: [],
15
- get players() {
16
- return lobby._players.filter((player) => Boolean(player && player.id));
17
- },
18
- teams: [],
19
- table: null,
20
- maxPlayers: teamSize ? teamSize * 2 : 6,
21
- full: false,
22
- ready: false,
23
- started: false,
24
- gameLoop: undefined,
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
- lobby.ready = allPlayersReady && allTeamsComplete && teamsSameSize;
31
- return lobby.ready;
32
- },
33
- calculateFull() {
34
- lobby.full = lobby.players.length >= lobby.maxPlayers;
35
- return lobby.full;
36
- },
37
- addPlayer(key, id, session, teamIdx, isOwner) {
38
- const exists = lobby.players.find((player) => player.session === session);
39
- if (exists) {
40
- if (exists.teamIdx === teamIdx) {
41
- return exists;
42
- }
43
- isOwner = exists.isOwner;
44
- lobby.removePlayer(exists.session);
45
- }
46
- if (lobby.started) {
47
- throw new Error(types_1.GAME_ERROR.MATCH_ALREADY_STARTED);
48
- }
49
- if (lobby.full) {
50
- throw new Error(types_1.GAME_ERROR.LOBBY_IS_FULL);
51
- }
52
- const maxSize = teamSize ? teamSize : 3;
53
- if (lobby.full ||
54
- lobby.players.filter((player) => player.teamIdx === teamIdx).length > maxSize) {
55
- throw new Error(types_1.GAME_ERROR.TEAM_IS_FULL);
56
- }
57
- const player = (0, Player_1.Player)(key, id, teamIdx !== undefined ? teamIdx : Number(!lobby.lastTeamIdx), isOwner);
58
- player.setSession(session);
59
- lobby.lastTeamIdx = Number(!lobby.lastTeamIdx);
60
- for (let i = 0; i < lobby._players.length; i++) {
61
- if (!lobby._players[i].id) {
62
- if (player.teamIdx === 0 && i % 2 === 0) {
63
- lobby._players[i] = player;
64
- break;
65
- }
66
- if (player.teamIdx === 1 && i % 2 !== 0) {
67
- lobby._players[i] = player;
68
- break;
69
- }
70
- }
71
- }
72
- lobby.calculateFull();
73
- lobby.calculateReady();
74
- return player;
75
- },
76
- removePlayer(session) {
77
- const idx = lobby._players.findIndex((player) => player && player.session === session);
78
- if (idx !== -1) {
79
- lobby._players[idx] = {};
80
- lobby.calculateFull();
81
- lobby.calculateReady();
82
- }
83
- return lobby;
84
- },
85
- startMatch(matchPoint = 9) {
86
- lobby.calculateReady();
87
- const actualTeamSize = lobby.players.length / 2;
88
- if (!constants_1.TEAM_SIZE_VALUES.includes(actualTeamSize)) {
89
- throw new Error(types_1.GAME_ERROR.UNEXPECTED_TEAM_SIZE);
90
- }
91
- if (!lobby.ready) {
92
- throw new Error(types_1.GAME_ERROR.TEAM_NOT_READY);
93
- }
94
- lobby.teams = [
95
- (0, Team_1.Team)(lobby.players.filter((player) => player.teamIdx === 0)),
96
- (0, Team_1.Team)(lobby.players.filter((player) => player.teamIdx === 1)),
97
- ];
98
- if (lobby.teams[0].players.length !== actualTeamSize ||
99
- lobby.teams[1].players.length !== actualTeamSize) {
100
- throw new Error(types_1.GAME_ERROR.UNEXPECTED_TEAM_SIZE);
101
- }
102
- lobby.table = (0, Table_1.Table)(lobby.players);
103
- lobby.gameLoop = (0, GameLoop_1.GameLoop)((0, Match_1.Match)(lobby.table, lobby.teams, matchPoint));
104
- lobby.started = true;
105
- return lobby.gameLoop;
106
- },
107
- };
108
- for (let i = 0; i < lobby.maxPlayers; i++) {
109
- lobby._players.push({});
110
- }
111
- return lobby;
112
- }
113
- exports.Lobby = Lobby;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Lobby = void 0;
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
+ function Lobby(teamSize) {
12
+ const lobby = {
13
+ lastTeamIdx: 1,
14
+ _players: [],
15
+ get players() {
16
+ return lobby._players.filter((player) => Boolean(player && player.id));
17
+ },
18
+ teams: [],
19
+ table: null,
20
+ maxPlayers: teamSize ? teamSize * 2 : 6,
21
+ full: false,
22
+ ready: false,
23
+ started: false,
24
+ gameLoop: undefined,
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
+ lobby.ready = allPlayersReady && allTeamsComplete && teamsSameSize;
31
+ return lobby.ready;
32
+ },
33
+ calculateFull() {
34
+ lobby.full = lobby.players.length >= lobby.maxPlayers;
35
+ return lobby.full;
36
+ },
37
+ addPlayer(key, id, session, teamIdx, isOwner) {
38
+ const exists = lobby.players.find((player) => player.session === session);
39
+ if (exists) {
40
+ if (exists.teamIdx === teamIdx) {
41
+ return exists;
42
+ }
43
+ isOwner = exists.isOwner;
44
+ lobby.removePlayer(exists.session);
45
+ }
46
+ if (lobby.started) {
47
+ throw new Error(types_1.GAME_ERROR.MATCH_ALREADY_STARTED);
48
+ }
49
+ if (lobby.full) {
50
+ throw new Error(types_1.GAME_ERROR.LOBBY_IS_FULL);
51
+ }
52
+ const maxSize = teamSize ? teamSize : 3;
53
+ if (lobby.full ||
54
+ lobby.players.filter((player) => player.teamIdx === teamIdx).length > maxSize) {
55
+ throw new Error(types_1.GAME_ERROR.TEAM_IS_FULL);
56
+ }
57
+ const player = (0, Player_1.Player)(key, id, teamIdx !== undefined ? teamIdx : Number(!lobby.lastTeamIdx), isOwner);
58
+ player.setSession(session);
59
+ lobby.lastTeamIdx = Number(!lobby.lastTeamIdx);
60
+ for (let i = 0; i < lobby._players.length; i++) {
61
+ if (!lobby._players[i].id) {
62
+ if (player.teamIdx === 0 && i % 2 === 0) {
63
+ lobby._players[i] = player;
64
+ break;
65
+ }
66
+ if (player.teamIdx === 1 && i % 2 !== 0) {
67
+ lobby._players[i] = player;
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ lobby.calculateFull();
73
+ lobby.calculateReady();
74
+ return player;
75
+ },
76
+ removePlayer(session) {
77
+ const idx = lobby._players.findIndex((player) => player && player.session === session);
78
+ if (idx !== -1) {
79
+ lobby._players[idx] = {};
80
+ lobby.calculateFull();
81
+ lobby.calculateReady();
82
+ }
83
+ return lobby;
84
+ },
85
+ startMatch(matchPoint = 9) {
86
+ lobby.calculateReady();
87
+ const actualTeamSize = lobby.players.length / 2;
88
+ if (!constants_1.TEAM_SIZE_VALUES.includes(actualTeamSize)) {
89
+ throw new Error(types_1.GAME_ERROR.UNEXPECTED_TEAM_SIZE);
90
+ }
91
+ if (!lobby.ready) {
92
+ throw new Error(types_1.GAME_ERROR.TEAM_NOT_READY);
93
+ }
94
+ lobby.teams = [
95
+ (0, Team_1.Team)(lobby.players.filter((player) => player.teamIdx === 0)),
96
+ (0, Team_1.Team)(lobby.players.filter((player) => player.teamIdx === 1)),
97
+ ];
98
+ if (lobby.teams[0].players.length !== actualTeamSize ||
99
+ lobby.teams[1].players.length !== actualTeamSize) {
100
+ throw new Error(types_1.GAME_ERROR.UNEXPECTED_TEAM_SIZE);
101
+ }
102
+ lobby.table = (0, Table_1.Table)(lobby.players);
103
+ lobby.gameLoop = (0, GameLoop_1.GameLoop)((0, Match_1.Match)(lobby.table, lobby.teams, matchPoint));
104
+ lobby.started = true;
105
+ return lobby.gameLoop;
106
+ },
107
+ };
108
+ for (let i = 0; i < lobby.maxPlayers; i++) {
109
+ lobby._players.push({});
110
+ }
111
+ return lobby;
112
+ }
113
+ exports.Lobby = Lobby;
@@ -1,21 +1,21 @@
1
- import { IHand, IHandPoints } from "./Hand";
2
- import { IPlayInstance } from "./Play";
3
- import { ITable } from "./Table";
4
- import { ITeam } from "./Team";
5
- export interface IMatch {
6
- teams: [ITeam, ITeam];
7
- hands: Array<IHand>;
8
- winner: ITeam | null;
9
- prevHand: IHand | null;
10
- currentHand: IHand | null;
11
- matchPoint: number;
12
- table: ITable;
13
- play(): IPlayInstance | null;
14
- addPoints(points: IHandPoints): [ITeam, ITeam];
15
- pushHand(hand: IHand): void;
16
- setPrevHand(hand: IHand | null): IHand | null;
17
- setCurrentHand(hand: IHand | null): IHand | null;
18
- setWinner(winner: ITeam): void;
19
- getNextTurn(): IteratorResult<IMatch | null, IMatch | null | void>;
20
- }
21
- export declare function Match(table: ITable, teams?: Array<ITeam>, matchPoint?: number): IMatch;
1
+ import { IHand, IHandPoints } from "./Hand";
2
+ import { IPlayInstance } from "./Play";
3
+ import { ITable } from "./Table";
4
+ import { ITeam } from "./Team";
5
+ export interface IMatch {
6
+ teams: [ITeam, ITeam];
7
+ hands: Array<IHand>;
8
+ winner: ITeam | null;
9
+ prevHand: IHand | null;
10
+ currentHand: IHand | null;
11
+ matchPoint: number;
12
+ table: ITable;
13
+ play(): IPlayInstance | null;
14
+ addPoints(points: IHandPoints): [ITeam, ITeam];
15
+ pushHand(hand: IHand): void;
16
+ setPrevHand(hand: IHand | null): IHand | null;
17
+ setCurrentHand(hand: IHand | null): IHand | null;
18
+ setWinner(winner: ITeam): void;
19
+ getNextTurn(): IteratorResult<IMatch | null, IMatch | null | void>;
20
+ }
21
+ export declare function Match(table: ITable, teams?: Array<ITeam>, matchPoint?: number): IMatch;
@@ -1,88 +1,90 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Match = void 0;
4
- const Deck_1 = require("./Deck");
5
- const Hand_1 = require("./Hand");
6
- const playerIsNotReady = (player) => !player.ready;
7
- function Match(table, teams = [], matchPoint = 9) {
8
- const deck = (0, Deck_1.Deck)().shuffle();
9
- const size = teams[0].players.length;
10
- if (size !== teams[1].players.length) {
11
- throw new Error("Team size mismatch");
12
- }
13
- function* handsGeneratorSequence() {
14
- while (!match.winner) {
15
- if (match.teams[0].players.every(playerIsNotReady)) {
16
- match.setWinner(match.teams[1]);
17
- break;
18
- }
19
- if (match.teams[1].players.every(playerIsNotReady)) {
20
- match.setWinner(match.teams[0]);
21
- break;
22
- }
23
- deck.shuffle();
24
- const hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
25
- match.setPrevHand(match.hands.at(-1) || null);
26
- match.pushHand(hand);
27
- while (!hand.finished()) {
28
- const { value } = hand.getNextPlayer();
29
- if (value && value.finished()) {
30
- continue;
31
- }
32
- match.setCurrentHand(value);
33
- yield match;
34
- }
35
- match.setCurrentHand(null);
36
- const teams = match.addPoints(hand.points);
37
- const winner = teams.find((team) => team.points.winner);
38
- if (winner) {
39
- match.setWinner(winner);
40
- match.setCurrentHand(null);
41
- break;
42
- }
43
- match.table.nextTurn();
44
- }
45
- yield match;
46
- }
47
- const handsGenerator = handsGeneratorSequence();
48
- const match = {
49
- winner: null,
50
- matchPoint,
51
- teams: teams,
52
- hands: [],
53
- table,
54
- prevHand: null,
55
- currentHand: null,
56
- play() {
57
- match.getNextTurn();
58
- if (!match.currentHand) {
59
- return null;
60
- }
61
- return match.currentHand.play(match.prevHand);
62
- },
63
- addPoints(points) {
64
- match.teams[0].addPoints(matchPoint, points[0]);
65
- match.teams[1].addPoints(matchPoint, points[1]);
66
- return match.teams;
67
- },
68
- pushHand(hand) {
69
- match.hands.push(hand);
70
- },
71
- setCurrentHand(hand) {
72
- match.currentHand = hand;
73
- return match.currentHand;
74
- },
75
- setPrevHand(hand) {
76
- match.prevHand = hand;
77
- return match.prevHand;
78
- },
79
- setWinner(winner) {
80
- match.winner = winner;
81
- },
82
- getNextTurn() {
83
- return handsGenerator.next();
84
- },
85
- };
86
- return match;
87
- }
88
- exports.Match = Match;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Match = void 0;
4
+ const Deck_1 = require("./Deck");
5
+ const Hand_1 = require("./Hand");
6
+ const playerIsNotReady = (player) => !player.ready;
7
+ function Match(table, teams = [], matchPoint = 9) {
8
+ const deck = (0, Deck_1.Deck)().shuffle();
9
+ const size = teams[0].players.length;
10
+ if (size !== teams[1].players.length) {
11
+ throw new Error("Team size mismatch");
12
+ }
13
+ function* handsGeneratorSequence() {
14
+ while (!match.winner) {
15
+ if (match.teams[0].players.every(playerIsNotReady)) {
16
+ match.setWinner(match.teams[1]);
17
+ break;
18
+ }
19
+ if (match.teams[1].players.every(playerIsNotReady)) {
20
+ match.setWinner(match.teams[0]);
21
+ break;
22
+ }
23
+ deck.shuffle();
24
+ match.setPrevHand(match.hands.at(-1) || null);
25
+ match.setCurrentHand(null);
26
+ yield match;
27
+ const hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
28
+ match.pushHand(hand);
29
+ while (!hand.finished()) {
30
+ const { value } = hand.getNextPlayer();
31
+ if (value && value.finished()) {
32
+ continue;
33
+ }
34
+ match.setCurrentHand(value);
35
+ yield match;
36
+ }
37
+ match.setCurrentHand(null);
38
+ const teams = match.addPoints(hand.points);
39
+ const winner = teams.find((team) => team.points.winner);
40
+ if (winner) {
41
+ match.setWinner(winner);
42
+ match.setCurrentHand(null);
43
+ break;
44
+ }
45
+ match.table.nextTurn();
46
+ }
47
+ yield match;
48
+ }
49
+ const handsGenerator = handsGeneratorSequence();
50
+ const match = {
51
+ winner: null,
52
+ matchPoint,
53
+ teams: teams,
54
+ hands: [],
55
+ table,
56
+ prevHand: null,
57
+ currentHand: null,
58
+ play() {
59
+ match.getNextTurn();
60
+ if (!match.currentHand) {
61
+ return null;
62
+ }
63
+ return match.currentHand.play(match.prevHand);
64
+ },
65
+ addPoints(points) {
66
+ match.teams[0].addPoints(matchPoint, points[0]);
67
+ match.teams[1].addPoints(matchPoint, points[1]);
68
+ return match.teams;
69
+ },
70
+ pushHand(hand) {
71
+ match.hands.push(hand);
72
+ },
73
+ setCurrentHand(hand) {
74
+ match.currentHand = hand;
75
+ return match.currentHand;
76
+ },
77
+ setPrevHand(hand) {
78
+ match.prevHand = hand;
79
+ return match.prevHand;
80
+ },
81
+ setWinner(winner) {
82
+ match.winner = winner;
83
+ },
84
+ getNextTurn() {
85
+ return handsGenerator.next();
86
+ },
87
+ };
88
+ return match;
89
+ }
90
+ exports.Match = Match;
@@ -1,22 +1,22 @@
1
- import { ECommand, EHandState } from "../../types";
2
- import { ICard } from "./Deck";
3
- import { IEnvido } from "./Envido";
4
- import { IHand } from "./Hand";
5
- import { IPlayer } from "./Player";
6
- import { IRound } from "./Round";
7
- import { ITeam } from "./Team";
8
- import { ITruco } from "./Truco";
9
- export interface IPlayInstance {
10
- teams: [ITeam, ITeam];
11
- handIdx: number;
12
- roundIdx: number;
13
- state: EHandState;
14
- truco: ITruco;
15
- envido: IEnvido;
16
- player: IPlayer | null;
17
- rounds: Array<IRound> | null;
18
- prevHand: IHand | null;
19
- use(idx: number, card: ICard): ICard | null;
20
- say(command: ECommand | number, player: IPlayer): ECommand | number | null;
21
- }
22
- export declare function PlayInstance(hand: IHand, prevHand: IHand | null, teams: [ITeam, ITeam]): IPlayInstance;
1
+ import { ECommand, EHandState } from "../../types";
2
+ import { ICard } from "./Deck";
3
+ import { IEnvido } from "./Envido";
4
+ import { IHand } from "./Hand";
5
+ import { IPlayer } from "./Player";
6
+ import { IRound } from "./Round";
7
+ import { ITeam } from "./Team";
8
+ import { ITruco } from "./Truco";
9
+ export interface IPlayInstance {
10
+ teams: [ITeam, ITeam];
11
+ handIdx: number;
12
+ roundIdx: number;
13
+ state: EHandState;
14
+ truco: ITruco;
15
+ envido: IEnvido;
16
+ player: IPlayer | null;
17
+ rounds: Array<IRound> | null;
18
+ prevHand: IHand | null;
19
+ use(idx: number, card: ICard): ICard | null;
20
+ say(command: ECommand | number, player: IPlayer): ECommand | number | null;
21
+ }
22
+ export declare function PlayInstance(hand: IHand, prevHand: IHand | null, teams: [ITeam, ITeam]): IPlayInstance;
@@ -1,44 +1,44 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlayInstance = void 0;
4
- const types_1 = require("../types");
5
- function PlayInstance(hand, prevHand, teams) {
6
- const instance = {
7
- state: hand.state,
8
- teams,
9
- truco: hand.truco,
10
- envido: hand.envido,
11
- handIdx: hand.idx,
12
- roundIdx: hand.rounds.length,
13
- player: hand.currentPlayer,
14
- rounds: hand.rounds,
15
- prevHand: prevHand && !hand.started && !hand.truco.waitingAnswer ? prevHand : null,
16
- use(idx, card) {
17
- return hand.use(idx, card);
18
- },
19
- say(command, player) {
20
- try {
21
- const fn = hand.say[command];
22
- if (fn) {
23
- if (!player.commands.includes(command)) {
24
- throw new Error(types_1.GAME_ERROR.INVALID_COMAND);
25
- }
26
- fn(player);
27
- }
28
- else {
29
- if (!player.envido.includes(command)) {
30
- throw new Error(types_1.GAME_ERROR.INVALID_ENVIDO_POINTS);
31
- }
32
- hand.sayEnvidoPoints(player, command);
33
- }
34
- return command;
35
- }
36
- catch (e) {
37
- console.error(e);
38
- return null;
39
- }
40
- },
41
- };
42
- return instance;
43
- }
44
- exports.PlayInstance = PlayInstance;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlayInstance = void 0;
4
+ const types_1 = require("../types");
5
+ function PlayInstance(hand, prevHand, teams) {
6
+ const instance = {
7
+ state: hand.state,
8
+ teams,
9
+ truco: hand.truco,
10
+ envido: hand.envido,
11
+ handIdx: hand.idx,
12
+ roundIdx: hand.rounds.length,
13
+ player: hand.currentPlayer,
14
+ rounds: hand.rounds,
15
+ prevHand: prevHand && !hand.started && !hand.truco.waitingAnswer ? prevHand : null,
16
+ use(idx, card) {
17
+ return hand.use(idx, card);
18
+ },
19
+ say(command, player) {
20
+ try {
21
+ const fn = hand.say[command];
22
+ if (fn) {
23
+ if (!player.commands.includes(command)) {
24
+ throw new Error(types_1.GAME_ERROR.INVALID_COMAND);
25
+ }
26
+ fn(player);
27
+ }
28
+ else {
29
+ if (!player.envido.includes(command)) {
30
+ throw new Error(types_1.GAME_ERROR.INVALID_ENVIDO_POINTS);
31
+ }
32
+ hand.sayEnvidoPoints(player, command);
33
+ }
34
+ return command;
35
+ }
36
+ catch (e) {
37
+ console.error(e);
38
+ return null;
39
+ }
40
+ },
41
+ };
42
+ return instance;
43
+ }
44
+ exports.PlayInstance = PlayInstance;
@@ -1,35 +1,35 @@
1
- import { ECommand } from "../../types";
2
- import { ICard } from "./Deck";
3
- export interface IPlayer {
4
- teamIdx: number;
5
- id: string;
6
- key: string;
7
- session?: string;
8
- hand: Array<ICard>;
9
- envido: Array<number>;
10
- _commands: Set<ECommand>;
11
- get commands(): Array<ECommand>;
12
- usedHand: Array<ICard>;
13
- prevHand: Array<ICard>;
14
- isTurn: boolean;
15
- hasFlor: boolean;
16
- isEnvidoTurn: boolean;
17
- isOwner: boolean;
18
- disabled: boolean;
19
- ready: boolean;
20
- resetCommands(): void;
21
- calculateEnvido(): Array<number>;
22
- setTurn(turn: boolean): void;
23
- setEnvidoTurn(turn: boolean): void;
24
- getPublicPlayer(): IPublicPlayer;
25
- setSession(session: string): void;
26
- enable(): void;
27
- disable(): void;
28
- setReady(ready: boolean): void;
29
- setHand(hand: Array<ICard>): Array<ICard>;
30
- useCard(idx: number, card: ICard): ICard | null;
31
- }
32
- export type IPublicPlayer = Pick<IPlayer, "id" | "key" | "disabled" | "ready" | "hand" | "envido" | "usedHand" | "prevHand" | "teamIdx" | "session" | "hasFlor" | "isTurn" | "isEnvidoTurn" | "isOwner"> & {
33
- commands: Array<ECommand>;
34
- };
35
- export declare function Player(key: string, id: string, teamIdx: number, isOwner?: boolean): IPlayer;
1
+ import { ECommand } from "../../types";
2
+ import { ICard } from "./Deck";
3
+ export interface IPlayer {
4
+ teamIdx: number;
5
+ id: string;
6
+ key: string;
7
+ session?: string;
8
+ hand: Array<ICard>;
9
+ envido: Array<number>;
10
+ _commands: Set<ECommand>;
11
+ get commands(): Array<ECommand>;
12
+ usedHand: Array<ICard>;
13
+ prevHand: Array<ICard>;
14
+ isTurn: boolean;
15
+ hasFlor: boolean;
16
+ isEnvidoTurn: boolean;
17
+ isOwner: boolean;
18
+ disabled: boolean;
19
+ ready: boolean;
20
+ resetCommands(): void;
21
+ calculateEnvido(): Array<number>;
22
+ setTurn(turn: boolean): void;
23
+ setEnvidoTurn(turn: boolean): void;
24
+ getPublicPlayer(): IPublicPlayer;
25
+ setSession(session: string): void;
26
+ enable(): void;
27
+ disable(): void;
28
+ setReady(ready: boolean): void;
29
+ setHand(hand: Array<ICard>): Array<ICard>;
30
+ useCard(idx: number, card: ICard): ICard | null;
31
+ }
32
+ export type IPublicPlayer = Pick<IPlayer, "id" | "key" | "disabled" | "ready" | "hand" | "envido" | "usedHand" | "prevHand" | "teamIdx" | "session" | "hasFlor" | "isTurn" | "isEnvidoTurn" | "isOwner"> & {
33
+ commands: Array<ECommand>;
34
+ };
35
+ export declare function Player(key: string, id: string, teamIdx: number, isOwner?: boolean): IPlayer;