trucoshi 7.2.1 → 7.4.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/dist/events.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EMatchState } from "@trucoshi/prisma";
2
2
  import { SocketError } from "./server";
3
- import { IAccountDetails, IChatMessage, ILobbyOptions, IMatchDetails, IMatchPreviousHand, IPlayerRanking, IPublicChatRoom, IPublicMatch, IPublicMatchInfo, IUserData, IWaitingPlayData, IWaitingSayData } from "./types";
3
+ import { IAccountDetails, IChatMessage, ILobbyOptions, IMatchDetails, IPlayerRanking, IPublicChatRoom, IPublicMatch, IPublicMatchInfo, IUserData, IWaitingPlayData, IWaitingSayData } from "./types";
4
4
  import { User } from "lightning-accounts";
5
5
  export type IEventCallback<T = {}> = (args: {
6
6
  success: boolean;
@@ -11,7 +11,6 @@ export declare enum EServerEvent {
11
11
  NEW_MESSAGE = "NEW_MESSAGE",
12
12
  SET_SESSION = "SET_SESSION",
13
13
  REFRESH_IDENTITY = "REFRESH_IDENTITY",
14
- PREVIOUS_HAND = "PREVIOUS_HAND",
15
14
  UPDATE_MATCH = "UPDATE_MATCH",
16
15
  MATCH_DELETED = "MATCH_DELETED",
17
16
  WAITING_PLAY = "WAITING_PLAY",
@@ -22,7 +21,6 @@ export declare enum EServerEvent {
22
21
  }
23
22
  export interface ServerToClientEvents {
24
23
  [EServerEvent.PONG]: (serverTime: number, clientTime: number) => void;
25
- [EServerEvent.PREVIOUS_HAND]: (value: IMatchPreviousHand, callback: () => void) => void;
26
24
  [EServerEvent.UPDATE_CHAT]: (room: IPublicChatRoom) => void;
27
25
  [EServerEvent.NEW_MESSAGE]: (roomId: string, message?: IChatMessage) => void;
28
26
  [EServerEvent.UPDATE_ACTIVE_MATCHES]: (activeMatches: IPublicMatchInfo[]) => void;
package/dist/events.js CHANGED
@@ -4,7 +4,6 @@ export var EServerEvent;
4
4
  EServerEvent["NEW_MESSAGE"] = "NEW_MESSAGE";
5
5
  EServerEvent["SET_SESSION"] = "SET_SESSION";
6
6
  EServerEvent["REFRESH_IDENTITY"] = "REFRESH_IDENTITY";
7
- EServerEvent["PREVIOUS_HAND"] = "PREVIOUS_HAND";
8
7
  EServerEvent["UPDATE_MATCH"] = "UPDATE_MATCH";
9
8
  EServerEvent["MATCH_DELETED"] = "MATCH_DELETED";
10
9
  EServerEvent["WAITING_PLAY"] = "WAITING_PLAY";
@@ -37,8 +37,7 @@ export function Deck() {
37
37
  export const getAllCards = () => Object.keys(CARDS);
38
38
  export function dealCards(table, deck) {
39
39
  const cheat_lots_of_flowers = process.env.APP_CHEAT_LOTS_OF_FLOWERS_FOR_TESTING === "1";
40
- const cheat_cards = process.env.APP_CHEAT_CARDS &&
41
- JSON.parse(process.env.APP_CHEAT_CARDS);
40
+ const cheat_cards = process.env.APP_CHEAT_CARDS || "";
42
41
  const playerHands = [];
43
42
  const players = table.getPlayersForehandFirst();
44
43
  for (let i = 0; i < 3; i++) {
@@ -47,11 +46,17 @@ export function dealCards(table, deck) {
47
46
  }
48
47
  }
49
48
  if (cheat_cards) {
50
- deck.shuffle(players[0].idx);
51
- for (const [key, player] of players.entries()) {
52
- playerHands[player.idx] = cheat_cards[key]
53
- ? cheat_cards[key].map((c) => deck.pick(c) || deck.takeCard())
54
- : deck.takeThree();
49
+ try {
50
+ const new_cards = JSON.parse(cheat_cards);
51
+ deck.shuffle(players[0].idx);
52
+ for (const [key, player] of players.entries()) {
53
+ playerHands[player.idx] = new_cards[key]
54
+ ? new_cards[key].map((c) => deck.pick(c) || deck.takeCard())
55
+ : deck.takeThree();
56
+ }
57
+ }
58
+ catch (_a) {
59
+ //noop
55
60
  }
56
61
  }
57
62
  if (cheat_lots_of_flowers) {
@@ -1,9 +1,8 @@
1
- import { IPlayedCard, IPlayer } from "../../types";
1
+ import { IPlayer } from "../../types";
2
2
  export interface ITable<TPlayer extends {
3
3
  key: string;
4
4
  } = IPlayer> {
5
5
  forehandIdx: number;
6
- cards: Array<Array<IPlayedCard>>;
7
6
  players: Array<TPlayer>;
8
7
  nextHand(): TPlayer;
9
8
  getPlayerByPosition(idx?: number, forehandFirst?: boolean): TPlayer;
@@ -1,7 +1,6 @@
1
1
  export function Table(players) {
2
2
  const table = {
3
3
  players,
4
- cards: [],
5
4
  forehandIdx: 0,
6
5
  nextHand() {
7
6
  if (table.forehandIdx < table.players.length - 1) {
@@ -1,6 +1,6 @@
1
1
  export const PLAYER_ABANDON_TIMEOUT = 1000 * 60;
2
2
  export const PLAYER_TURN_TIMEOUT = 1000 * 30;
3
- export const PREVIOUS_HAND_ACK_TIMEOUT = 1000 * 5;
3
+ export const PREVIOUS_HAND_ACK_TIMEOUT = 1000 * 10;
4
4
  export const CARDS = {
5
5
  "1e": 13,
6
6
  "1b": 12,
@@ -1,6 +1,6 @@
1
- import { IRound } from "../truco";
1
+ import { IHand } from "../truco";
2
2
  import { ICard } from "../types";
3
3
  export declare function getMaxNumberIndex<T = number>(array: Array<T>): number;
4
4
  export declare function getMinNumberIndex<T = number>(array: Array<T>): number;
5
5
  export declare function getCardValue(card: ICard): number;
6
- export declare function checkHandWinner(rounds: Array<IRound>, forehandTeamIdx: 0 | 1): null | 0 | 1;
6
+ export declare function checkHandWinner(hand: IHand, forehandTeamIdx: 0 | 1): null | 0 | 1;
package/dist/lib/utils.js CHANGED
@@ -12,13 +12,17 @@ export function getMinNumberIndex(array) {
12
12
  export function getCardValue(card) {
13
13
  return CARDS[card] !== undefined ? CARDS[card] : -2;
14
14
  }
15
- export function checkHandWinner(rounds, forehandTeamIdx) {
16
- var _a, _b, _c;
15
+ export function checkHandWinner(hand, forehandTeamIdx) {
16
+ var _a, _b, _c, _d;
17
17
  const roundsWon = {
18
18
  0: 0,
19
19
  1: 0,
20
20
  ties: 0,
21
21
  };
22
+ const rounds = hand.rounds;
23
+ if (hand.flor.winner && hand.flor.state === 5) {
24
+ return hand.flor.winner.id;
25
+ }
22
26
  for (let i = 0; i < rounds.length; i++) {
23
27
  const round = rounds[i];
24
28
  if (round.tie) {
@@ -27,17 +31,21 @@ export function checkHandWinner(rounds, forehandTeamIdx) {
27
31
  roundsWon.ties = roundsWon.ties + 1;
28
32
  continue;
29
33
  }
30
- if (((_a = round.winner) === null || _a === void 0 ? void 0 : _a.teamIdx) === 0) {
34
+ if (round.unbeatable) {
35
+ roundsWon[(_a = round.winner) === null || _a === void 0 ? void 0 : _a.teamIdx] += 1;
36
+ continue;
37
+ }
38
+ if (((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx) === 0) {
31
39
  roundsWon[0] += 1;
32
40
  }
33
- if (((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx) === 1) {
41
+ if (((_c = round.winner) === null || _c === void 0 ? void 0 : _c.teamIdx) === 1) {
34
42
  roundsWon[1] += 1;
35
43
  }
36
44
  }
37
45
  if (roundsWon[0] > 2 && roundsWon[1] > 2) {
38
46
  return forehandTeamIdx;
39
47
  }
40
- if (rounds.length > 2 && roundsWon.ties > 0 && ((_c = rounds[0]) === null || _c === void 0 ? void 0 : _c.winner)) {
48
+ if (rounds.length > 2 && roundsWon.ties > 0 && ((_d = rounds[0]) === null || _d === void 0 ? void 0 : _d.winner)) {
41
49
  return rounds[0].winner.teamIdx;
42
50
  }
43
51
  if (roundsWon[0] >= 2 && roundsWon[1] < 2) {
package/dist/types.d.ts CHANGED
@@ -78,6 +78,7 @@ export interface IPublicMatch {
78
78
  state: EMatchState;
79
79
  handState: EHandState | null;
80
80
  florBattle: IMatchFlorBattle | null;
81
+ previousHand: IMatchPreviousHand | null;
81
82
  winner: ITeam | null;
82
83
  matchSessionId: string;
83
84
  forehandIdx: number;
@@ -89,6 +90,7 @@ export interface IPublicMatch {
89
90
  rounds: IPlayedCard[][];
90
91
  lastCard?: ICard | null;
91
92
  lastCommand?: ECommand | number | null;
93
+ awardedSatsPerPlayer?: number;
92
94
  }
93
95
  export interface IPublicMatchInfo {
94
96
  ownerId: string;
@@ -162,7 +164,7 @@ export declare enum EHandState {
162
164
  WAITING_ENVIDO_POINTS_ANSWER = "WAITING_ENVIDO_POINTS_ANSWER",
163
165
  WAITING_FLOR_ANSWER = "WAITING_FLOR_ANSWER",
164
166
  DISPLAY_FLOR_BATTLE = "DISPLAY_FLOR_BATTLE",
165
- BEFORE_FINISHED = "BEFORE_FINISHED",
167
+ DISPLAY_PREVIOUS_HAND = "DISPLAY_PREVIOUS_HAND",
166
168
  FINISHED = "FINISHED"
167
169
  }
168
170
  export type ECommand = ESayCommand | EEnvidoCommand | EAnswerCommand | EEnvidoAnswerCommand | ETrucoCommand | EFlorCommand;
@@ -339,6 +341,7 @@ export interface ITeam {
339
341
  name: string;
340
342
  players: Array<IPlayer>;
341
343
  points: ITeamPoints;
344
+ get activePlayers(): IPlayer[];
342
345
  setPlayers(players: IPlayer[]): ITeam;
343
346
  pointsToWin(matchPoint: number): number;
344
347
  getPublicTeam(playerSession?: string): IPublicTeam;
package/dist/types.js CHANGED
@@ -53,7 +53,7 @@ export var EHandState;
53
53
  EHandState["WAITING_ENVIDO_POINTS_ANSWER"] = "WAITING_ENVIDO_POINTS_ANSWER";
54
54
  EHandState["WAITING_FLOR_ANSWER"] = "WAITING_FLOR_ANSWER";
55
55
  EHandState["DISPLAY_FLOR_BATTLE"] = "DISPLAY_FLOR_BATTLE";
56
- EHandState["BEFORE_FINISHED"] = "BEFORE_FINISHED";
56
+ EHandState["DISPLAY_PREVIOUS_HAND"] = "DISPLAY_PREVIOUS_HAND";
57
57
  EHandState["FINISHED"] = "FINISHED";
58
58
  })(EHandState || (EHandState = {}));
59
59
  export var GAME_ERROR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trucoshi",
3
- "version": "7.2.1",
3
+ "version": "7.4.1",
4
4
  "description": "Lightning Truco Server",
5
5
  "main": "dist/types.js",
6
6
  "license": "GPL-3.0",