trucoshi 0.2.10 → 0.2.11

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.
@@ -43,12 +43,22 @@ const GameLoop = (match) => {
43
43
  }
44
44
  gameloop.currentPlayer = play.player;
45
45
  if (play.state === types_1.EHandState.WAITING_FOR_TRUCO_ANSWER) {
46
- yield gameloop._onTruco(play);
46
+ try {
47
+ yield gameloop._onTruco(play);
48
+ }
49
+ catch (e) {
50
+ console.error("GAME LOOP ERROR", e);
51
+ }
47
52
  continue;
48
53
  }
49
54
  if (play.state === types_1.EHandState.WAITING_PLAY) {
50
55
  play.player.setTurn(true);
51
- yield gameloop._onTurn(play);
56
+ try {
57
+ yield gameloop._onTurn(play);
58
+ }
59
+ catch (e) {
60
+ console.error("GAME LOOP ERROR", e);
61
+ }
52
62
  play.player.setTurn(false);
53
63
  continue;
54
64
  }
@@ -49,10 +49,6 @@ function Hand(match, deck, idx) {
49
49
  }
50
50
  yield hand;
51
51
  }
52
- if (match.teams[0].isTeamDisabled() && match.teams[1].isTeamDisabled()) {
53
- hand.setState(types_1.EHandState.FINISHED);
54
- break;
55
- }
56
52
  let winnerTeamIdx = (0, utils_1.checkHandWinner)(hand.rounds, forehandTeamIdx);
57
53
  if (match.teams[0].isTeamDisabled()) {
58
54
  winnerTeamIdx = 1;
@@ -72,6 +68,9 @@ function Hand(match, deck, idx) {
72
68
  const commands = {
73
69
  [types_1.ESayCommand.MAZO]: (player) => {
74
70
  hand.disablePlayer(player);
71
+ if (match.teams.every((team) => team.isTeamDisabled())) {
72
+ hand.setState(types_1.EHandState.FINISHED);
73
+ }
75
74
  hand.nextTurn();
76
75
  },
77
76
  [types_1.ESayCommand.TRUCO]: (player) => {
@@ -20,7 +20,9 @@ function PlayInstance(hand, teams) {
20
20
  return command;
21
21
  },
22
22
  };
23
- teams.forEach((team) => team.players.forEach((player) => player._commands.add(types_1.ESayCommand.MAZO)));
23
+ if (!hand.truco.waitingAnswer) {
24
+ teams.forEach((team) => team.players.forEach((player) => player._commands.add(types_1.ESayCommand.MAZO)));
25
+ }
24
26
  return instance;
25
27
  }
26
28
  exports.PlayInstance = PlayInstance;
@@ -3,6 +3,7 @@ import { ITeam } from "./Team";
3
3
  export interface ITruco {
4
4
  state: 1 | 2 | 3 | 4;
5
5
  teamIdx: 0 | 1 | null;
6
+ waitingAnswer: boolean;
6
7
  answer: boolean | null;
7
8
  turn: number;
8
9
  teams: [ITeam, ITeam];
@@ -28,6 +28,7 @@ function Truco(teams) {
28
28
  teams,
29
29
  teamIdx: null,
30
30
  answer: null,
31
+ waitingAnswer: false,
31
32
  currentPlayer: null,
32
33
  generator: trucoAnswerGeneratorSequence(),
33
34
  players: [],
@@ -38,6 +39,7 @@ function Truco(teams) {
38
39
  const playerTeamIdx = player.teamIdx;
39
40
  const teamIdx = truco.teamIdx;
40
41
  if (teamIdx === null || teamIdx !== playerTeamIdx) {
42
+ truco.waitingAnswer = true;
41
43
  truco.state++;
42
44
  const opponentIdx = Number(!playerTeamIdx);
43
45
  truco.teamIdx = playerTeamIdx;
@@ -93,6 +95,7 @@ function Truco(teams) {
93
95
  });
94
96
  }
95
97
  if (answer !== null) {
98
+ truco.waitingAnswer = false;
96
99
  truco.teamIdx = Number(!player.teamIdx);
97
100
  truco.answer = answer;
98
101
  callback();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trucoshi",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "main": "dist/index.js",
5
5
  "license": "GPL-3.0",
6
6
  "scripts": {