trucoshi 5.5.2 → 6.0.0

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
@@ -8,6 +8,7 @@ export type IEventCallback<T = {}> = (args: {
8
8
  } & T) => void;
9
9
  export declare enum EServerEvent {
10
10
  PONG = "PONG",
11
+ NEW_MESSAGE = "NEW_MESSAGE",
11
12
  SET_SESSION = "SET_SESSION",
12
13
  REFRESH_IDENTITY = "REFRESH_IDENTITY",
13
14
  PREVIOUS_HAND = "PREVIOUS_HAND",
@@ -22,7 +23,8 @@ export declare enum EServerEvent {
22
23
  export interface ServerToClientEvents {
23
24
  [EServerEvent.PONG]: (serverTime: number, clientTime: number) => void;
24
25
  [EServerEvent.PREVIOUS_HAND]: (value: IMatchPreviousHand, callback: () => void) => void;
25
- [EServerEvent.UPDATE_CHAT]: (room: IPublicChatRoom, message?: IChatMessage) => void;
26
+ [EServerEvent.UPDATE_CHAT]: (room: IPublicChatRoom) => void;
27
+ [EServerEvent.NEW_MESSAGE]: (roomId: string, message?: IChatMessage) => void;
26
28
  [EServerEvent.UPDATE_ACTIVE_MATCHES]: (activeMatches: IPublicMatchInfo[]) => void;
27
29
  [EServerEvent.UPDATE_MATCH]: (match: IPublicMatch, callback?: () => void) => void;
28
30
  [EServerEvent.KICK_PLAYER]: (match: IPublicMatch, session: string, reason?: string) => void;
@@ -45,6 +47,7 @@ export declare enum EClientEvent {
45
47
  START_MATCH = "START_MATCH",
46
48
  SET_PLAYER_READY = "SET_PLAYER_READY",
47
49
  FETCH_MATCH = "FETCH_MATCH",
50
+ FETCH_CHAT_ROOM = "FETCH_CHAT_ROOM",
48
51
  KICK_PLAYER = "KICK_PLAYER",
49
52
  CHAT = "CHAT",
50
53
  PING = "PING",
@@ -77,6 +80,7 @@ export interface ClientToServerEvents {
77
80
  [EClientEvent.FETCH_MATCH]: (matchSessionId: string, callback: IEventCallback<{
78
81
  match: IPublicMatch | null;
79
82
  }>) => void;
83
+ [EClientEvent.FETCH_CHAT_ROOM]: (roomId: string) => void;
80
84
  [EClientEvent.FETCH_MATCH_DETAILS]: (matchId: number, callback: IEventCallback<{
81
85
  match: IMatchDetails | null;
82
86
  }>) => void;
package/dist/events.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export var EServerEvent;
2
2
  (function (EServerEvent) {
3
3
  EServerEvent["PONG"] = "PONG";
4
+ EServerEvent["NEW_MESSAGE"] = "NEW_MESSAGE";
4
5
  EServerEvent["SET_SESSION"] = "SET_SESSION";
5
6
  EServerEvent["REFRESH_IDENTITY"] = "REFRESH_IDENTITY";
6
7
  EServerEvent["PREVIOUS_HAND"] = "PREVIOUS_HAND";
@@ -26,6 +27,7 @@ export var EClientEvent;
26
27
  EClientEvent["START_MATCH"] = "START_MATCH";
27
28
  EClientEvent["SET_PLAYER_READY"] = "SET_PLAYER_READY";
28
29
  EClientEvent["FETCH_MATCH"] = "FETCH_MATCH";
30
+ EClientEvent["FETCH_CHAT_ROOM"] = "FETCH_CHAT_ROOM";
29
31
  EClientEvent["KICK_PLAYER"] = "KICK_PLAYER";
30
32
  EClientEvent["CHAT"] = "CHAT";
31
33
  EClientEvent["PING"] = "PING";
@@ -0,0 +1,11 @@
1
+ import { ICard, IDeck, IPlayedCard, IPlayer, IPublicPlayer } from "../../types";
2
+ import { ITable } from "./Table";
3
+ export declare function Deck(): IDeck;
4
+ export declare const getAllCards: () => ("rb" | "1e" | "1b" | "7e" | "7o" | "3e" | "3o" | "3b" | "3c" | "2e" | "2o" | "2b" | "2c" | "1o" | "1c" | "re" | "ro" | "rc" | "ce" | "co" | "cb" | "cc" | "pe" | "po" | "pb" | "pc" | "7b" | "7c" | "6e" | "6o" | "6b" | "6c" | "5e" | "5o" | "5b" | "5c" | "4e" | "4o" | "4b" | "4c")[];
5
+ export declare function dealCards<TPlayer extends {
6
+ key: string;
7
+ idx: number;
8
+ setHand(h: Array<ICard>): void;
9
+ } = IPlayer>(table: ITable<TPlayer>, deck: IDeck): void;
10
+ export declare function shuffleArray<T = unknown>(array: Array<T>, getRandom?: (max: number) => number): T[];
11
+ export declare function PlayedCard(player: IPlayer | IPublicPlayer, card: ICard, burn?: boolean): IPlayedCard;
@@ -0,0 +1,61 @@
1
+ import { BURNT_CARD, CARDS } from "../../types";
2
+ import { Random } from "./Random";
3
+ export function Deck() {
4
+ const deck = {
5
+ cards: getAllCards(),
6
+ random: Random(),
7
+ usedCards: [],
8
+ takeCard() {
9
+ const card = deck.cards.shift();
10
+ deck.usedCards.push(card);
11
+ return card;
12
+ },
13
+ takeThree() {
14
+ return [deck.takeCard(), deck.takeCard(), deck.takeCard()];
15
+ },
16
+ shuffle(dealer) {
17
+ deck.cards = getAllCards();
18
+ deck.usedCards = [];
19
+ deck.cards = shuffleArray(deck.cards, (max) => deck.random.pick(dealer, max - 1));
20
+ if (deck.cards.length !== 40) {
21
+ throw new Error("This is not good");
22
+ }
23
+ return deck;
24
+ },
25
+ };
26
+ return deck;
27
+ }
28
+ export const getAllCards = () => Object.keys(CARDS);
29
+ export function dealCards(table, deck) {
30
+ const playerHands = [];
31
+ for (let i = 0; i < 3; i++) {
32
+ for (const player of table.getPlayersForehandFirst()) {
33
+ playerHands[player.idx] = [...(playerHands[player.idx] || []), deck.takeCard()];
34
+ }
35
+ }
36
+ for (const [key, player] of table.players.entries()) {
37
+ player.setHand(playerHands[key]);
38
+ }
39
+ }
40
+ const defaultGetRandom = (max) => Math.floor(Math.random() * max);
41
+ export function shuffleArray(array, getRandom = defaultGetRandom) {
42
+ let currentIndex = array.length, randomIndex;
43
+ while (currentIndex != 0) {
44
+ randomIndex = getRandom(currentIndex);
45
+ currentIndex--;
46
+ [array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
47
+ }
48
+ return array;
49
+ }
50
+ export function PlayedCard(player, card, burn) {
51
+ const pc = {
52
+ player,
53
+ card,
54
+ key: card + player.idx,
55
+ };
56
+ if (burn) {
57
+ pc.card = BURNT_CARD;
58
+ pc.key = Math.floor(Math.random() * 100).toString();
59
+ }
60
+ return pc;
61
+ }
@@ -1,3 +1,3 @@
1
- export * from "../../truco/Deck";
1
+ export * from "./Deck";
2
2
  export * from "./Table";
3
3
  export * from "./Random";
@@ -1,3 +1,3 @@
1
- export * from "../../truco/Deck";
1
+ export * from "./Deck";
2
2
  export * from "./Table";
3
3
  export * from "./Random";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trucoshi",
3
- "version": "5.5.2",
3
+ "version": "6.0.0",
4
4
  "description": "Lightning Truco Server",
5
5
  "main": "dist/types.js",
6
6
  "license": "GPL-3.0",
@@ -76,7 +76,7 @@
76
76
  "dotenv-cli": "^7.3.0",
77
77
  "form-data": "^4.0.0",
78
78
  "jsonwebtoken": "^9.0.2",
79
- "lightning-accounts": "3.0.0",
79
+ "lightning-accounts": "^4.1.0",
80
80
  "node-forge": "^1.3.1",
81
81
  "path-scurry": "^1.9.2",
82
82
  "pino": "^9.3.2",