trucoshi 0.3.5 → 0.3.51
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.
|
@@ -4,23 +4,25 @@ import { IPlayInstance } from "./Play";
|
|
|
4
4
|
import { IPlayer } from "./Player";
|
|
5
5
|
import { ITeam } from "./Team";
|
|
6
6
|
export type IWinnerCallback = (winner: ITeam, teams: [ITeam, ITeam]) => Promise<void>;
|
|
7
|
-
export type ITurnCallback = (play: IPlayInstance
|
|
7
|
+
export type ITurnCallback = (play: IPlayInstance) => Promise<void>;
|
|
8
8
|
export type ITrucoCallback = (play: IPlayInstance) => Promise<void>;
|
|
9
|
+
export type IHandFinishedCallback = (hand: IHand | null) => Promise<void>;
|
|
9
10
|
export type IEnvidoCallback = (play: IPlayInstance, pointsRound: boolean) => Promise<void>;
|
|
10
11
|
export interface IGameLoop {
|
|
11
12
|
_onTruco: ITrucoCallback;
|
|
12
13
|
_onTurn: ITurnCallback;
|
|
13
14
|
_onWinner: IWinnerCallback;
|
|
14
15
|
_onEnvido: IEnvidoCallback;
|
|
16
|
+
_onHandFinished: IHandFinishedCallback;
|
|
15
17
|
currentPlayer: IPlayer | null;
|
|
16
18
|
currentHand: IHand | null;
|
|
17
|
-
lastCheckedHand: number | null;
|
|
18
19
|
teams: Array<ITeam>;
|
|
19
20
|
winner: ITeam | null;
|
|
20
21
|
onTurn: (callback: ITurnCallback) => IGameLoop;
|
|
21
22
|
onWinner: (callback: IWinnerCallback) => IGameLoop;
|
|
22
23
|
onTruco: (callback: ITrucoCallback) => IGameLoop;
|
|
23
24
|
onEnvido: (callback: IEnvidoCallback) => IGameLoop;
|
|
25
|
+
onHandFinished: (callback: IHandFinishedCallback) => IGameLoop;
|
|
24
26
|
begin: () => Promise<void>;
|
|
25
27
|
}
|
|
26
28
|
export declare const GameLoop: (match: IMatch) => IGameLoop;
|
|
@@ -17,11 +17,15 @@ const GameLoop = (match) => {
|
|
|
17
17
|
_onTruco: () => Promise.resolve(),
|
|
18
18
|
_onTurn: () => Promise.resolve(),
|
|
19
19
|
_onWinner: () => Promise.resolve(),
|
|
20
|
+
_onHandFinished: () => Promise.resolve(),
|
|
20
21
|
teams: [],
|
|
21
22
|
winner: null,
|
|
22
23
|
currentPlayer: null,
|
|
23
24
|
currentHand: null,
|
|
24
|
-
|
|
25
|
+
onHandFinished: (callback) => {
|
|
26
|
+
gameloop._onHandFinished = callback;
|
|
27
|
+
return gameloop;
|
|
28
|
+
},
|
|
25
29
|
onTruco: (callback) => {
|
|
26
30
|
gameloop._onTruco = callback;
|
|
27
31
|
return gameloop;
|
|
@@ -39,13 +43,21 @@ const GameLoop = (match) => {
|
|
|
39
43
|
return gameloop;
|
|
40
44
|
},
|
|
41
45
|
begin() {
|
|
42
|
-
var _a, _b;
|
|
43
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
47
|
gameloop.teams = match.teams;
|
|
45
48
|
while (!match.winner) {
|
|
46
49
|
const play = match.play();
|
|
47
50
|
gameloop.currentHand = match.currentHand;
|
|
48
|
-
if (!play
|
|
51
|
+
if (!play) {
|
|
52
|
+
try {
|
|
53
|
+
yield gameloop._onHandFinished(match.prevHand);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error("GAME LOOP ERROR - ON HAND FINISHED");
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!play.player) {
|
|
49
61
|
continue;
|
|
50
62
|
}
|
|
51
63
|
gameloop.currentPlayer = play.player;
|
|
@@ -83,10 +95,7 @@ const GameLoop = (match) => {
|
|
|
83
95
|
if (play.state === types_1.EHandState.WAITING_PLAY) {
|
|
84
96
|
try {
|
|
85
97
|
play.player.setTurn(true);
|
|
86
|
-
|
|
87
|
-
((_b = gameloop.currentHand) === null || _b === void 0 ? void 0 : _b.rounds[0].cards.length) === 0;
|
|
88
|
-
gameloop.lastCheckedHand = play.prevHand ? play.prevHand.idx : null;
|
|
89
|
-
yield gameloop._onTurn(play, newHandJustStarted);
|
|
98
|
+
yield gameloop._onTurn(play);
|
|
90
99
|
play.player.setTurn(false);
|
|
91
100
|
}
|
|
92
101
|
catch (e) {
|
|
@@ -21,8 +21,10 @@ function Match(table, teams = [], matchPoint = 9) {
|
|
|
21
21
|
break;
|
|
22
22
|
}
|
|
23
23
|
deck.shuffle();
|
|
24
|
-
const hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
|
|
25
24
|
match.setPrevHand(match.hands.at(-1) || null);
|
|
25
|
+
match.setCurrentHand(null);
|
|
26
|
+
yield match;
|
|
27
|
+
const hand = match.setCurrentHand((0, Hand_1.Hand)(match, deck, match.hands.length + 1));
|
|
26
28
|
match.pushHand(hand);
|
|
27
29
|
while (!hand.finished()) {
|
|
28
30
|
const { value } = hand.getNextPlayer();
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Player = void 0;
|
|
4
|
-
const types_1 = require("../../types");
|
|
5
|
-
const filterEnvidoCommands = (command) => Object.values(types_1.EEnvidoCommand).includes(command) ||
|
|
6
|
-
Object.values(types_1.EAnswerCommand).includes(command) ||
|
|
7
|
-
Object.values(types_1.EEnvidoAnswerCommand).includes(command);
|
|
8
|
-
const filterNotEnvidoCommands = (command) => !Object.values(types_1.EEnvidoCommand).includes(command) &&
|
|
9
|
-
!Object.values(types_1.EEnvidoAnswerCommand).includes(command);
|
|
10
4
|
function Player(key, id, teamIdx, isOwner = false) {
|
|
11
5
|
const player = {
|
|
12
6
|
key,
|
|
@@ -74,15 +68,9 @@ function Player(key, id, teamIdx, isOwner = false) {
|
|
|
74
68
|
const hand = player.hand.map((c) => {
|
|
75
69
|
let num = c.charAt(0);
|
|
76
70
|
const palo = c.charAt(1);
|
|
77
|
-
if (num === "p") {
|
|
71
|
+
if (num === "p" || num === "c" || num === "r") {
|
|
78
72
|
num = "10";
|
|
79
73
|
}
|
|
80
|
-
if (num === "c") {
|
|
81
|
-
num = "11";
|
|
82
|
-
}
|
|
83
|
-
if (num === "r") {
|
|
84
|
-
num = "12";
|
|
85
|
-
}
|
|
86
74
|
if (flor === null || flor === palo) {
|
|
87
75
|
flor = palo;
|
|
88
76
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -34,15 +34,17 @@ export interface IChatMessage {
|
|
|
34
34
|
};
|
|
35
35
|
system?: boolean;
|
|
36
36
|
command?: boolean;
|
|
37
|
+
card?: boolean;
|
|
37
38
|
content: string;
|
|
38
39
|
}
|
|
39
40
|
export interface IChatRoom {
|
|
40
41
|
id: string;
|
|
41
42
|
messages: Array<IChatMessage>;
|
|
42
43
|
send(user: IChatMessage["user"], message: string): void;
|
|
43
|
-
|
|
44
|
+
card(user: IChatMessage["user"], command: ICard): void;
|
|
44
45
|
command(team: 0 | 1, command: ECommand | number): void;
|
|
45
|
-
|
|
46
|
+
system(message: string): void;
|
|
47
|
+
emit(message?: IChatMessage): void;
|
|
46
48
|
}
|
|
47
49
|
export declare enum EChatSystem {
|
|
48
50
|
TEAM_0 = 0,
|
|
@@ -139,7 +141,7 @@ export interface ServerToClientEvents {
|
|
|
139
141
|
[EServerEvent.PONG]: (msg: string) => void;
|
|
140
142
|
[EServerEvent.WAITING_POSSIBLE_SAY]: (match: IPublicMatch, callback: (data: IWaitingSayData) => void) => void;
|
|
141
143
|
[EServerEvent.PREVIOUS_HAND]: (value: IMatchPreviousHand, callback: () => void) => void;
|
|
142
|
-
[EServerEvent.UPDATE_CHAT]: (room: IPublicChatRoom) => void;
|
|
144
|
+
[EServerEvent.UPDATE_CHAT]: (room: IPublicChatRoom, message?: IChatMessage) => void;
|
|
143
145
|
[EServerEvent.UPDATE_MATCH]: (match: IPublicMatch) => void;
|
|
144
146
|
[EServerEvent.PLAYER_USED_CARD]: (match: IPublicMatch, card: IPlayedCard) => void;
|
|
145
147
|
[EServerEvent.PLAYER_SAID_COMMAND]: (match: IPublicMatch, command: ISaidCommand) => void;
|