trucoshi 7.2.0 → 7.3.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.
@@ -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) {
@@ -51,7 +51,12 @@ function Rng() {
51
51
  * @param {number} nonce - the nonce
52
52
  * @returns {string} combined string
53
53
  */
54
- combine: (clientSeed, serverSeed, bitcoinHash, nonce) => clientSeed + serverSeed + bitcoinHash + nonce,
54
+ combine: (clientSeed, serverSeed, bitcoinHash, nonce) => {
55
+ if (bitcoinHash) {
56
+ return clientSeed + serverSeed + bitcoinHash + nonce;
57
+ }
58
+ return clientSeed + serverSeed + nonce;
59
+ },
55
60
  /**
56
61
  * Generates a sha512 hash from a string
57
62
  *
@@ -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 * 3;
4
4
  export const CARDS = {
5
5
  "1e": 13,
6
6
  "1b": 12,
package/dist/lib/utils.js CHANGED
@@ -13,7 +13,7 @@ export function getCardValue(card) {
13
13
  return CARDS[card] !== undefined ? CARDS[card] : -2;
14
14
  }
15
15
  export function checkHandWinner(rounds, forehandTeamIdx) {
16
- var _a, _b, _c;
16
+ var _a, _b, _c, _d;
17
17
  const roundsWon = {
18
18
  0: 0,
19
19
  1: 0,
@@ -27,17 +27,21 @@ export function checkHandWinner(rounds, forehandTeamIdx) {
27
27
  roundsWon.ties = roundsWon.ties + 1;
28
28
  continue;
29
29
  }
30
- if (((_a = round.winner) === null || _a === void 0 ? void 0 : _a.teamIdx) === 0) {
30
+ if (round.unbeatable) {
31
+ roundsWon[(_a = round.winner) === null || _a === void 0 ? void 0 : _a.teamIdx] += 1;
32
+ continue;
33
+ }
34
+ if (((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx) === 0) {
31
35
  roundsWon[0] += 1;
32
36
  }
33
- if (((_b = round.winner) === null || _b === void 0 ? void 0 : _b.teamIdx) === 1) {
37
+ if (((_c = round.winner) === null || _c === void 0 ? void 0 : _c.teamIdx) === 1) {
34
38
  roundsWon[1] += 1;
35
39
  }
36
40
  }
37
41
  if (roundsWon[0] > 2 && roundsWon[1] > 2) {
38
42
  return forehandTeamIdx;
39
43
  }
40
- if (rounds.length > 2 && roundsWon.ties > 0 && ((_c = rounds[0]) === null || _c === void 0 ? void 0 : _c.winner)) {
44
+ if (rounds.length > 2 && roundsWon.ties > 0 && ((_d = rounds[0]) === null || _d === void 0 ? void 0 : _d.winner)) {
41
45
  return rounds[0].winner.teamIdx;
42
46
  }
43
47
  if (roundsWon[0] >= 2 && roundsWon[1] < 2) {
package/dist/types.d.ts CHANGED
@@ -89,6 +89,7 @@ export interface IPublicMatch {
89
89
  rounds: IPlayedCard[][];
90
90
  lastCard?: ICard | null;
91
91
  lastCommand?: ECommand | number | null;
92
+ awardedSatsPerPlayer?: number;
92
93
  }
93
94
  export interface IPublicMatchInfo {
94
95
  ownerId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trucoshi",
3
- "version": "7.2.0",
3
+ "version": "7.3.1",
4
4
  "description": "Lightning Truco Server",
5
5
  "main": "dist/types.js",
6
6
  "license": "GPL-3.0",