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 +1 -3
- package/dist/events.js +0 -1
- package/dist/lib/classes/Deck.js +12 -7
- package/dist/lib/classes/Table.d.ts +1 -2
- package/dist/lib/classes/Table.js +0 -1
- package/dist/lib/constants.js +1 -1
- package/dist/lib/utils.d.ts +2 -2
- package/dist/lib/utils.js +13 -5
- package/dist/types.d.ts +4 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
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,
|
|
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";
|
package/dist/lib/classes/Deck.js
CHANGED
|
@@ -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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 {
|
|
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;
|
package/dist/lib/constants.js
CHANGED
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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(
|
|
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(
|
|
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 (
|
|
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 (((
|
|
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 && ((
|
|
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
|
-
|
|
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["
|
|
56
|
+
EHandState["DISPLAY_PREVIOUS_HAND"] = "DISPLAY_PREVIOUS_HAND";
|
|
57
57
|
EHandState["FINISHED"] = "FINISHED";
|
|
58
58
|
})(EHandState || (EHandState = {}));
|
|
59
59
|
export var GAME_ERROR;
|