texas-poker-core 1.1.21 → 1.1.24

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/README.md CHANGED
@@ -183,4 +183,10 @@ api change
183
183
  ## 1.1.20
184
184
  调整api
185
185
  ## 1.1.21
186
- 增加一些事件监听方法
186
+ 增加一些事件监听方法
187
+ ## 1.1.22
188
+ change api
189
+ ## 1.1.23
190
+ change api
191
+ ## 1.1.24
192
+ 修复onAction的回调参数
@@ -81,6 +81,7 @@ var _lowestBetAmount = /*#__PURE__*/new WeakMap();
81
81
  var _currentStageTotalAmount = /*#__PURE__*/new WeakMap();
82
82
  var _lastPlayer = /*#__PURE__*/new WeakMap();
83
83
  var _nextPlayer = /*#__PURE__*/new WeakMap();
84
+ var _shouldTakeDefaultAction = /*#__PURE__*/new WeakMap();
84
85
  var _timer = /*#__PURE__*/new WeakMap();
85
86
  var _dealer = /*#__PURE__*/new WeakMap();
86
87
  var _pool = /*#__PURE__*/new WeakMap();
@@ -106,7 +107,9 @@ var Player = exports.Player = /*#__PURE__*/function () {
106
107
  pool = _ref.pool,
107
108
  isOwner = _ref.isOwner,
108
109
  _ref$thinkingTime = _ref.thinkingTime,
109
- thinkingTime = _ref$thinkingTime === void 0 ? 30 : _ref$thinkingTime;
110
+ thinkingTime = _ref$thinkingTime === void 0 ? _config.defaultThinkingTime : _ref$thinkingTime,
111
+ _ref$shouldTakeDefaul = _ref.shouldTakeDefaultAction,
112
+ shouldTakeDefaultAction = _ref$shouldTakeDefaul === void 0 ? true : _ref$shouldTakeDefaul;
110
113
  _classCallCheck(this, Player);
111
114
  _classPrivateMethodInitSpec(this, _Player_brand);
112
115
  /**
@@ -140,6 +143,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
140
143
  */
141
144
  _classPrivateFieldInitSpec(this, _lastPlayer, null);
142
145
  _classPrivateFieldInitSpec(this, _nextPlayer, null);
146
+ _classPrivateFieldInitSpec(this, _shouldTakeDefaultAction, void 0);
143
147
  _classPrivateFieldInitSpec(this, _timer, null);
144
148
  _classPrivateFieldInitSpec(this, _dealer, void 0);
145
149
  _classPrivateFieldInitSpec(this, _pool, void 0);
@@ -165,6 +169,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
165
169
  _classPrivateFieldSet(_dealer, this, dealer);
166
170
  _classPrivateFieldSet(_isOwner, this, isOwner);
167
171
  _classPrivateFieldSet(_thinkingTime, this, thinkingTime);
172
+ _classPrivateFieldSet(_shouldTakeDefaultAction, this, shouldTakeDefaultAction);
168
173
  _classPrivateFieldSet(_controller, this, controller);
169
174
  _classPrivateFieldSet(_pool, this, pool || new _Pool.default());
170
175
  }
@@ -260,8 +265,8 @@ var Player = exports.Player = /*#__PURE__*/function () {
260
265
  _classPrivateFieldSet(_action, this, {
261
266
  type: 'check'
262
267
  });
263
- (_classPrivateFieldGet2 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet2 === void 0 || _classPrivateFieldGet2.call(this, _classPrivateFieldGet(_action, this));
264
268
  _classPrivateFieldGet(_dealer, this).addAction(this);
269
+ (_classPrivateFieldGet2 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet2 === void 0 || _classPrivateFieldGet2.call(this, this);
265
270
  console.log(_classPrivateFieldGet(_userInfo, this).name, '过牌');
266
271
  this.transferControl();
267
272
  }
@@ -273,9 +278,9 @@ var Player = exports.Player = /*#__PURE__*/function () {
273
278
  _classPrivateFieldSet(_action, this, {
274
279
  type: 'fold'
275
280
  });
276
- (_classPrivateFieldGet3 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet3 === void 0 || _classPrivateFieldGet3.call(this, _classPrivateFieldGet(_action, this));
277
281
  _classPrivateFieldSet(_status, this, 'out');
278
282
  _classPrivateFieldGet(_dealer, this).addAction(this);
283
+ (_classPrivateFieldGet3 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet3 === void 0 || _classPrivateFieldGet3.call(this, this);
279
284
  console.log(_classPrivateFieldGet(_userInfo, this).name, '弃牌');
280
285
  this.transferControl();
281
286
  }
@@ -299,10 +304,11 @@ var Player = exports.Player = /*#__PURE__*/function () {
299
304
  value: money
300
305
  }
301
306
  });
302
- (_classPrivateFieldGet4 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet4 === void 0 || _classPrivateFieldGet4.call(this, _classPrivateFieldGet(_action, this));
303
307
  _classPrivateFieldSet(_balance, this, _classPrivateFieldGet(_balance, this) - money);
304
308
  _classPrivateFieldSet(_currentStageTotalAmount, this, _classPrivateFieldGet(_currentStageTotalAmount, this) + money);
305
309
  console.log(_classPrivateFieldGet(_userInfo, this).name, '下注金额:', money, '剩余筹码:', _classPrivateFieldGet(_balance, this));
310
+ // 默认下注行为不触发
311
+ if (!preFlopDefaultAction) (_classPrivateFieldGet4 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet4 === void 0 || _classPrivateFieldGet4.call(this, this);
306
312
  _classPrivateFieldGet(_pool, this).add(this, money, _classPrivateFieldGet(_controller, this).stage);
307
313
  if (!preFlopDefaultAction) this.transferControl();
308
314
  return money;
@@ -334,9 +340,9 @@ var Player = exports.Player = /*#__PURE__*/function () {
334
340
  value: money
335
341
  }
336
342
  });
337
- (_classPrivateFieldGet5 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet5 === void 0 || _classPrivateFieldGet5.call(this, _classPrivateFieldGet(_action, this));
338
343
  _classPrivateFieldSet(_balance, this, _classPrivateFieldGet(_balance, this) - money);
339
344
  _classPrivateFieldSet(_currentStageTotalAmount, this, _classPrivateFieldGet(_currentStageTotalAmount, this) + money);
345
+ (_classPrivateFieldGet5 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet5 === void 0 || _classPrivateFieldGet5.call(this, this);
340
346
  console.log(_classPrivateFieldGet(_userInfo, this).name, '加注', money);
341
347
  _classPrivateFieldGet(_pool, this).add(this, money, _classPrivateFieldGet(_controller, this).stage);
342
348
  this.transferControl();
@@ -362,9 +368,9 @@ var Player = exports.Player = /*#__PURE__*/function () {
362
368
  value: moneyShouldPay
363
369
  }
364
370
  });
365
- (_classPrivateFieldGet6 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet6 === void 0 || _classPrivateFieldGet6.call(this, _classPrivateFieldGet(_action, this));
366
371
  _classPrivateFieldSet(_balance, this, _classPrivateFieldGet(_balance, this) - moneyShouldPay);
367
372
  _classPrivateFieldSet(_currentStageTotalAmount, this, _classPrivateFieldGet(_currentStageTotalAmount, this) + moneyShouldPay);
373
+ (_classPrivateFieldGet6 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet6 === void 0 || _classPrivateFieldGet6.call(this, this);
368
374
  console.log(_classPrivateFieldGet(_userInfo, this).name, '跟注:', moneyShouldPay);
369
375
  _classPrivateFieldGet(_pool, this).add(this, moneyShouldPay, _classPrivateFieldGet(_controller, this).stage);
370
376
  this.transferControl();
@@ -393,10 +399,10 @@ var Player = exports.Player = /*#__PURE__*/function () {
393
399
  value: moneyShouldPay
394
400
  }
395
401
  });
396
- (_classPrivateFieldGet7 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call(this, _classPrivateFieldGet(_action, this));
397
402
  _classPrivateFieldSet(_currentStageTotalAmount, this, _classPrivateFieldGet(_currentStageTotalAmount, this) + moneyShouldPay);
398
403
  _classPrivateFieldSet(_balance, this, _classPrivateFieldGet(_balance, this) - moneyShouldPay);
399
404
  _classPrivateFieldSet(_status, this, 'allIn');
405
+ (_classPrivateFieldGet7 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call(this, this);
400
406
  console.log(_classPrivateFieldGet(_userInfo, this).name, '全押:', moneyShouldPay, '剩余筹码: ', _classPrivateFieldGet(_balance, this));
401
407
  _classPrivateFieldGet(_pool, this).add(this, moneyShouldPay, _classPrivateFieldGet(_controller, this).stage);
402
408
  this.transferControl();
@@ -635,7 +641,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
635
641
  this.takeDefaultAction();
636
642
  return;
637
643
  }
638
- if (_config.shouldTakeDefaultAction) {
644
+ if (_classPrivateFieldGet(_shouldTakeDefaultAction, this)) {
639
645
  _classPrivateFieldSet(_timer, this, setInterval(function () {
640
646
  var _this$countDownTime, _this$countDownTime2;
641
647
  if (_classPrivateFieldGet(_countDownTime, _this4) === 0 && _classPrivateFieldGet(_timer, _this4)) {
@@ -707,10 +713,10 @@ function _getAllowedActions() {
707
713
 
708
714
  // 上个玩家弃牌了, 需要知道最近采取行动的玩家
709
715
  if (((_classPrivateFieldGet9 = _classPrivateFieldGet(_action, lastPlayer)) === null || _classPrivateFieldGet9 === void 0 ? void 0 : _classPrivateFieldGet9.type) === 'fold') {
710
- var player = _toConsumableArray(_classPrivateFieldGet(_dealer, _this5).actionHistory).reverse().find(function (player) {
716
+ var _player = _toConsumableArray(_classPrivateFieldGet(_dealer, _this5).actionHistory).reverse().find(function (player) {
711
717
  return player.getStatus() !== 'out';
712
718
  });
713
- return _helper(player);
719
+ return _helper(_player);
714
720
  }
715
721
  if (_classPrivateFieldGet(_action, lastPlayer).type === 'check') return ['allIn', 'bet', 'check', 'fold'];
716
722
 
@@ -3,9 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.shouldTakeDefaultAction = exports.defaultThinkingTime = void 0;
6
+ exports.defaultThinkingTime = void 0;
7
7
  // 默认思考事件
8
- var defaultThinkingTime = exports.defaultThinkingTime = 30;
9
-
10
- // 超时后服务器是否采取默认的行为
11
- var shouldTakeDefaultAction = exports.shouldTakeDefaultAction = false;
8
+ var defaultThinkingTime = exports.defaultThinkingTime = 30;
package/dist/index.js CHANGED
@@ -23,6 +23,8 @@ var _exportNames = {
23
23
  ActionType: true,
24
24
  Role: true,
25
25
  Action: true,
26
+ ActionWithPayload: true,
27
+ ActionWithOutPayload: true,
26
28
  roleMap: true,
27
29
  actionMap: true,
28
30
  Stage: true,
@@ -45,6 +47,18 @@ Object.defineProperty(exports, "ActionType", {
45
47
  return _Player.ActionType;
46
48
  }
47
49
  });
50
+ Object.defineProperty(exports, "ActionWithOutPayload", {
51
+ enumerable: true,
52
+ get: function get() {
53
+ return _Player.ActionWithOutPayload;
54
+ }
55
+ });
56
+ Object.defineProperty(exports, "ActionWithPayload", {
57
+ enumerable: true,
58
+ get: function get() {
59
+ return _Player.ActionWithPayload;
60
+ }
61
+ });
48
62
  Object.defineProperty(exports, "ControllerStatus", {
49
63
  enumerable: true,
50
64
  get: function get() {
package/dist/main.js CHANGED
@@ -33,10 +33,12 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
33
33
  // 是否允许观战
34
34
 
35
35
  var initialGame = exports.initialGame = function initialGame(_ref) {
36
- var lowestBetAmount = _ref.lowestBetAmount,
37
- maximumCountOfPlayers = _ref.maximumCountOfPlayers,
36
+ var user = _ref.user,
37
+ thinkingTime = _ref.thinkingTime,
38
+ lowestBetAmount = _ref.lowestBetAmount,
38
39
  allowPlayersToWatch = _ref.allowPlayersToWatch,
39
- user = _ref.user;
40
+ maximumCountOfPlayers = _ref.maximumCountOfPlayers,
41
+ shouldTakeDefaultAction = _ref.shouldTakeDefaultAction;
40
42
  var dealer = new _Dealer.default(lowestBetAmount);
41
43
  var controller = new _Controller.default(dealer);
42
44
  var pool = new _Pool.default();
@@ -45,10 +47,11 @@ var initialGame = exports.initialGame = function initialGame(_ref) {
45
47
  lowestBetAmount: lowestBetAmount,
46
48
  controller: controller,
47
49
  dealer: dealer,
48
- pool: pool
50
+ pool: pool,
51
+ shouldTakeDefaultAction: shouldTakeDefaultAction,
52
+ thinkingTime: thinkingTime
49
53
  });
50
54
  var room = new _Room.default(dealer, owner, controller, allowPlayersToWatch, maximumCountOfPlayers);
51
- var callbackOfEnd;
52
55
  return {
53
56
  room: room,
54
57
  pool: pool,
@@ -83,7 +86,7 @@ var initialGame = exports.initialGame = function initialGame(_ref) {
83
86
  });
84
87
  },
85
88
  onGameEnd: function onGameEnd(callback) {
86
- callbackOfEnd = callback;
89
+ this.controller.onGameEnd(callback);
87
90
  },
88
91
  onNextStage: function onNextStage(callback) {
89
92
  controller.onNextStage(callback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "texas-poker-core",
3
- "version": "1.1.21",
3
+ "version": "1.1.24",
4
4
  "description": "德州扑克核心功能",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -5,10 +5,10 @@ import Controller from '../Controller';
5
5
  import { Poke } from '../Deck/constant';
6
6
  type PlayerStatus = 'allIn' | 'active' | 'waiting' | 'out';
7
7
  type OnlineStatus = 'online' | 'offline' | 'quit';
8
- interface ActionWithOutPayload {
8
+ export interface ActionWithOutPayload {
9
9
  type: Extract<ActionType, 'check' | 'fold'>;
10
10
  }
11
- interface ActionWithPayload {
11
+ export interface ActionWithPayload {
12
12
  type: Exclude<ActionType, 'check' | 'fold'>;
13
13
  payload: {
14
14
  value: number;
@@ -32,14 +32,14 @@ export interface User {
32
32
  */
33
33
  avatar?: string;
34
34
  }
35
- export type CallbackOfAction = (action: Action) => void;
35
+ export type CallbackOfAction = (player: Player) => void;
36
36
  export type Role = 'button' | 'small-blind' | 'big-blind' | `under-the-gun${number | ''}` | `middle-position${number | ''}` | 'hi-jack' | 'cut-off';
37
37
  /**
38
38
  * 玩家
39
39
  */
40
40
  export declare class Player {
41
41
  #private;
42
- constructor({ lowestBetAmount, user, lastPlayer, nextPlayer, controller, dealer, pool, isOwner, thinkingTime }: {
42
+ constructor({ lowestBetAmount, user, lastPlayer, nextPlayer, controller, dealer, pool, isOwner, thinkingTime, shouldTakeDefaultAction }: {
43
43
  lowestBetAmount: number;
44
44
  role?: Role;
45
45
  user: User;
@@ -51,6 +51,7 @@ export declare class Player {
51
51
  pool?: Pool;
52
52
  isOwner?: boolean;
53
53
  thinkingTime?: number;
54
+ shouldTakeDefaultAction?: boolean;
54
55
  });
55
56
  setNextPlayer(player: Player | null): void;
56
57
  setPresentation(presentation: string): void;
@@ -1,2 +1 @@
1
1
  export declare const defaultThinkingTime = 30;
2
- export declare const shouldTakeDefaultAction = false;
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { initialGame } from './main';
2
2
  export { initialGame };
3
- export { default as Player, User, ActionType, Role, Action } from './Player';
3
+ export { default as Player, User, ActionType, Role, Action, ActionWithPayload, ActionWithOutPayload } from './Player';
4
4
  export { roleMap, actionMap } from './Player/constant';
5
5
  export { Stage, ControllerStatus } from './Controller';
6
6
  export { default as Dealer } from './Dealer';
package/types/main.d.ts CHANGED
@@ -9,6 +9,11 @@ interface CreateRoomInputArgs {
9
9
  maximumCountOfPlayers: number;
10
10
  allowPlayersToWatch: boolean;
11
11
  user: User;
12
+ /**
13
+ * 是否需要在超时 采取默认行动
14
+ */
15
+ shouldTakeDefaultAction?: boolean;
16
+ thinkingTime?: number;
12
17
  }
13
18
  export interface PreAction {
14
19
  userId: number;
@@ -18,7 +23,7 @@ export interface PreAction {
18
23
  max: number;
19
24
  };
20
25
  }
21
- declare const initialGame: ({ lowestBetAmount, maximumCountOfPlayers, allowPlayersToWatch, user }: CreateRoomInputArgs) => {
26
+ declare const initialGame: ({ user, thinkingTime, lowestBetAmount, allowPlayersToWatch, maximumCountOfPlayers, shouldTakeDefaultAction }: CreateRoomInputArgs) => {
22
27
  room: Room;
23
28
  pool: Pool;
24
29
  dealer: Dealer;