texas-poker-core 1.2.3 → 1.2.6

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
@@ -10,9 +10,59 @@
10
10
  npm i texas-poker-core@latest
11
11
  ```
12
12
 
13
- # API 文档
14
-
15
- [点击跳转](https://www.wishufree.com/moment/share/213)
13
+ # 使用手册 Usage
14
+
15
+ ```ts
16
+ import { Texas } from 'texas-poker-core'
17
+
18
+ // 实例化Texas
19
+ const texas = new Texas({
20
+ // 大盲注
21
+ lowestBetAmount: 500,
22
+ // 允许的最大玩家数量
23
+ maximumCountOfPlayers: 7,
24
+ // 是否允许观战, 如果房间玩家达到上限时, 此字段决定玩家是否还可以加入房间
25
+ allowPlayersToWatch: true,
26
+ // room owner info
27
+ user: { id: 1, balance: 5000, name: 'ycr' },
28
+ thinkingTime: 5
29
+ })
30
+ const p2 = texas.createPlayer({ id: 2, name: 'yt', balance: 10000 })
31
+ const p3 = texas.createPlayer({ id: 3, name: 'wyz', balance: 10000 })
32
+ const p4 = texas.createPlayer({ id: 4, name: 'sen', balance: 10000 })
33
+ texas.room.joinMany(p2, p3, p4)
34
+
35
+ // 玩家行动前触发的回调函数, 包括允许的行动列表, 行动玩家的id, 以及允许的下注范围
36
+ texas.onPreAction((preAction) => {})
37
+ // 玩家行动后触发的回调函数
38
+ // 可在此函数中完成数据上报行为
39
+ texas.onAction((action) => {})
40
+ // 游戏阶段变化触发的回调函数
41
+ texas.onNextStage((stageInfo) => {})
42
+ // 游戏结束时触发的回调函数
43
+ texas.onGameEnd((gameEndInfo) => {
44
+ // 游戏结束后轮换庄家
45
+ texas.dealer.changeButtonToNextPlayer()
46
+ // 庄家变化后, 重新设置其他玩家的角色
47
+ texas.dealer.setOthers()
48
+ // 这里可以进行数据上报, 分配奖池, 更新用户的余额到数据库...
49
+
50
+ // 操作完成后重置对局信息
51
+ // 包括奖池, 底牌, 玩家手牌, 收回玩家的控制权...
52
+ texas.reset()
53
+ // 如果开启下一轮游戏, 只需再次调用`texas.start`即可
54
+ })
55
+ // 游戏进程中遇到错误触发的函数
56
+ texas.onError((texasError) => {})
57
+ // 房间初次创建时需调用, 确定各个玩家的角色
58
+ texas.ready()
59
+
60
+ // 开始游戏
61
+ // 大小盲默认下注, 可以通过texas.getDefaultBet获取默认下注信息
62
+ // 随后将控制权移交给小盲的下一位, 由具有行动权的玩家选择行动
63
+ // 会触发onPreAction回调, 可以在此方法中推送消息给客户端
64
+ texas.start()
65
+ ```
16
66
 
17
67
  # 发布记录
18
68
 
@@ -313,10 +363,20 @@ bufix
313
363
  修复 player.actionble 判断错误
314
364
 
315
365
  ## 1.2.1
316
- 完善texas.start逻辑
366
+
367
+ 完善 texas.start 逻辑
368
+
317
369
  ## 1.2.2
318
- 完善player.checkIfCanAct的逻辑
319
- ## 1.2.3
320
- 测试ncu
370
+
371
+ 完善 player.checkIfCanAct 的逻辑
372
+
321
373
  ## 1.2.3
322
- 测试ncu
374
+
375
+ 测试 ncu
376
+
377
+ ## 1.2.5
378
+
379
+ 补充使用文档
380
+
381
+ ## 1.2.6
382
+ 修复行动前下注金额错误计算逻辑
@@ -2,9 +2,13 @@
2
2
 
3
3
  require("core-js/modules/es.symbol.js");
4
4
  require("core-js/modules/es.symbol.description.js");
5
+ require("core-js/modules/es.symbol.async-iterator.js");
5
6
  require("core-js/modules/es.symbol.iterator.js");
6
7
  require("core-js/modules/es.symbol.to-primitive.js");
8
+ require("core-js/modules/es.symbol.to-string-tag.js");
7
9
  require("core-js/modules/es.date.to-primitive.js");
10
+ require("core-js/modules/es.json.to-string-tag.js");
11
+ require("core-js/modules/es.math.to-string-tag.js");
8
12
  require("core-js/modules/es.number.constructor.js");
9
13
  require("core-js/modules/es.object.get-prototype-of.js");
10
14
  require("core-js/modules/es.promise.js");
@@ -27,7 +31,7 @@ require("core-js/modules/esnext.weak-map.delete-all.js");
27
31
  require("core-js/modules/esnext.weak-set.add-all.js");
28
32
  require("core-js/modules/esnext.weak-set.delete-all.js");
29
33
  require("core-js/modules/web.dom-collections.iterator.js");
30
- var _error = _interopRequireDefault(require("../error"));
34
+ var _TexasError = _interopRequireDefault(require("../TexasError"));
31
35
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
32
36
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
33
37
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
@@ -114,7 +118,7 @@ var Controller = /*#__PURE__*/function () {
114
118
  * @param player
115
119
  */
116
120
  function transferControlTo(player) {
117
- if (_classPrivateFieldGet(_activePlayer, this) === player) this.reportError(new _error.default(2100, '无法重复获得控制权'));
121
+ if (_classPrivateFieldGet(_activePlayer, this) === player) this.reportError(new _TexasError.default(2100, '无法重复获得控制权'));
118
122
  _classPrivateFieldSet(_activePlayer, this, player);
119
123
  player === null || player === void 0 || player.getControl();
120
124
  }
@@ -281,7 +285,7 @@ var Controller = /*#__PURE__*/function () {
281
285
  _context.next = 11;
282
286
  break;
283
287
  case 10:
284
- this.reportError(new _error.default(2000, '游戏进程异常'));
288
+ this.reportError(new _TexasError.default(2000, '游戏进程异常'));
285
289
  case 11:
286
290
  case "end":
287
291
  return _context.stop();
@@ -348,7 +352,7 @@ var Controller = /*#__PURE__*/function () {
348
352
  key: "continue",
349
353
  value: function _continue() {
350
354
  var _classPrivateFieldGet8;
351
- if (_classPrivateFieldGet(_status, this) !== 'pause') this.reportError(new _error.default(2100, '游戏不是暂停状态,无法继续'));
355
+ if (_classPrivateFieldGet(_status, this) !== 'pause') this.reportError(new _TexasError.default(2100, '游戏不是暂停状态,无法继续'));
352
356
  _classPrivateFieldSet(_status, this, 'on');
353
357
  (_classPrivateFieldGet8 = _classPrivateFieldGet(_activePlayer, this)) === null || _classPrivateFieldGet8 === void 0 || _classPrivateFieldGet8.continue();
354
358
  this.startTimer();
@@ -368,7 +372,7 @@ var Controller = /*#__PURE__*/function () {
368
372
  }, {
369
373
  key: "end",
370
374
  value: function end() {
371
- if (this.status !== 'on') this.reportError(new _error.default(2100, '游戏不在进行中, 无法结束'));
375
+ if (this.status !== 'on') this.reportError(new _TexasError.default(2100, '游戏不在进行中, 无法结束'));
372
376
  this.clearTimer();
373
377
  _classPrivateFieldSet(_status, this, 'end');
374
378
  this.resetActivePlayer();
@@ -30,7 +30,7 @@ require("core-js/modules/esnext.weak-map.delete-all.js");
30
30
  require("core-js/modules/web.dom-collections.for-each.js");
31
31
  require("core-js/modules/web.dom-collections.iterator.js");
32
32
  var _Deck = _interopRequireDefault(require("../Deck"));
33
- var _error = _interopRequireDefault(require("../error"));
33
+ var _TexasError = _interopRequireDefault(require("../TexasError"));
34
34
  var _utils = require("../utils");
35
35
  var _constant = require("../Player/constant");
36
36
  var _core = require("../Deck/core");
@@ -125,7 +125,7 @@ var Dealer = /*#__PURE__*/function () {
125
125
  }, {
126
126
  key: "dealCards",
127
127
  value: function dealCards() {
128
- if (!_classPrivateFieldGet(_button, this)) this.reportError(new _error.default(2000, '庄家未指定, 无法发牌'));
128
+ if (!_classPrivateFieldGet(_button, this)) this.reportError(new _TexasError.default(2000, '庄家未指定, 无法发牌'));
129
129
  console.log('玩家信息:');
130
130
  console.log(this.map(function (player) {
131
131
  return _constant.roleMap.get(player.getRole()) + ': ' + player.toString();
@@ -270,7 +270,7 @@ var Dealer = /*#__PURE__*/function () {
270
270
  value: function reArrangeRoles() {
271
271
  if (!_classPrivateFieldGet(_button, this)) return;
272
272
  var roles = _constant.playerRoleSetMap.get(_classPrivateFieldGet(_count, this));
273
- if (!roles) this.reportError(new _error.default(2000, '不支持的玩家人数对局'));
273
+ if (!roles) this.reportError(new _TexasError.default(2000, '不支持的玩家人数对局'));
274
274
  this.loop(function (player, i) {
275
275
  player.setRole(roles[i]);
276
276
  }, _classPrivateFieldGet(_button, this));
@@ -314,7 +314,7 @@ var Dealer = /*#__PURE__*/function () {
314
314
  value: function changeButtonToNextPlayer() {
315
315
  var _classPrivateFieldGet5;
316
316
  var next = (_classPrivateFieldGet5 = _classPrivateFieldGet(_button, this)) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.getNextPlayer();
317
- if (!next) this.reportError(new _error.default(2000, '将庄家移交给不存在的玩家'));
317
+ if (!next) this.reportError(new _TexasError.default(2000, '将庄家移交给不存在的玩家'));
318
318
  this.setButton(next);
319
319
  }
320
320
 
@@ -353,10 +353,10 @@ var Dealer = /*#__PURE__*/function () {
353
353
  }, {
354
354
  key: "setOthers",
355
355
  value: function setOthers() {
356
- if (!_classPrivateFieldGet(_button, this)) this.reportError(new _error.default(2000, '未指定庄家, 无法设置其余玩家位置'));
356
+ if (!_classPrivateFieldGet(_button, this)) this.reportError(new _TexasError.default(2000, '未指定庄家, 无法设置其余玩家位置'));
357
357
  var count = _classPrivateFieldGet(_count, this);
358
358
  if (process.env.PROJECT_ENV === 'dev' && count === 1) return;
359
- if (count < 2 || count > 10) this.reportError(new _error.default(2000, "\u6682\u4E0D\u652F\u6301".concat(count, "\u4EBA\u7684\u5BF9\u5C40")));
359
+ if (count < 2 || count > 10) this.reportError(new _TexasError.default(2000, "\u6682\u4E0D\u652F\u6301".concat(count, "\u4EBA\u7684\u5BF9\u5C40")));
360
360
  var roles = _constant.playerRoleSetMap.get(count).slice(1);
361
361
  var role;
362
362
  var current = _classPrivateFieldGet(_button, this).getNextPlayer();
@@ -2,11 +2,15 @@
2
2
 
3
3
  require("core-js/modules/es.symbol.js");
4
4
  require("core-js/modules/es.symbol.description.js");
5
+ require("core-js/modules/es.symbol.async-iterator.js");
5
6
  require("core-js/modules/es.symbol.iterator.js");
6
7
  require("core-js/modules/es.symbol.to-primitive.js");
8
+ require("core-js/modules/es.symbol.to-string-tag.js");
7
9
  require("core-js/modules/es.array.from.js");
8
10
  require("core-js/modules/es.array.slice.js");
9
11
  require("core-js/modules/es.date.to-primitive.js");
12
+ require("core-js/modules/es.json.to-string-tag.js");
13
+ require("core-js/modules/es.math.to-string-tag.js");
10
14
  require("core-js/modules/es.number.constructor.js");
11
15
  require("core-js/modules/es.object.get-prototype-of.js");
12
16
  require("core-js/modules/es.promise.js");
@@ -34,8 +38,8 @@ require("core-js/modules/esnext.weak-map.delete-all.js");
34
38
  require("core-js/modules/esnext.weak-set.add-all.js");
35
39
  require("core-js/modules/esnext.weak-set.delete-all.js");
36
40
  require("core-js/modules/web.dom-collections.iterator.js");
37
- var _error = _interopRequireDefault(require("../error"));
38
41
  var _constant = require("./constant");
42
+ var _TexasError = _interopRequireDefault(require("../TexasError"));
39
43
  var _utils = require("../utils");
40
44
  var _config = require("../config");
41
45
  var _Player;
@@ -161,7 +165,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
161
165
  _classPrivateFieldInitSpec(this, _callbackOfAction, void 0);
162
166
  _defineProperty(this, "reportError", void 0);
163
167
  if (user.balance < lowestBetAmount) {
164
- reportError(new _error.default(2003, '筹码小于大盲注, 不可参与游戏'));
168
+ reportError(new _TexasError.default(2003, '筹码小于大盲注, 不可参与游戏'));
165
169
  }
166
170
  _classPrivateFieldSet(_pool, this, pool);
167
171
  _classPrivateFieldSet(_dealer, this, dealer);
@@ -207,6 +211,15 @@ var Player = exports.Player = /*#__PURE__*/function () {
207
211
  get: function get() {
208
212
  return _classPrivateFieldGet(_thinkingTime, this);
209
213
  }
214
+ }, {
215
+ key: "getRemainThinkTime",
216
+ value:
217
+ /**
218
+ * @description 获取剩余的行动思考时间
219
+ */
220
+ function getRemainThinkTime() {
221
+ return _classPrivateFieldGet(_thinkingTime, this) - _classPrivateFieldGet(_countDownTime, this);
222
+ }
210
223
  }, {
211
224
  key: "setNextPlayer",
212
225
  value: function setNextPlayer(player) {
@@ -248,9 +261,12 @@ var Player = exports.Player = /*#__PURE__*/function () {
248
261
  return _classPrivateFieldGet(_status, this);
249
262
  }
250
263
  }, {
251
- key: "getOnlineStatus",
252
- value: function getOnlineStatus() {
264
+ key: "onlineStatus",
265
+ get: function get() {
253
266
  return _classPrivateFieldGet(_onlineStatus, this);
267
+ },
268
+ set: function set(value) {
269
+ _classPrivateFieldSet(_onlineStatus, this, value);
254
270
  }
255
271
  }, {
256
272
  key: "onPreAction",
@@ -282,7 +298,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
282
298
  while (1) switch (_context.prev = _context.next) {
283
299
  case 0:
284
300
  this.checkIfCanAct();
285
- if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('check')) this.reportError(new _error.default(2003, '不可过牌'));
301
+ if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('check')) this.reportError(new _TexasError.default(2003, '不可过牌'));
286
302
  _classPrivateFieldSet(_action, this, {
287
303
  type: 'check'
288
304
  });
@@ -312,7 +328,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
312
328
  while (1) switch (_context2.prev = _context2.next) {
313
329
  case 0:
314
330
  this.checkIfCanAct();
315
- if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('fold')) this.reportError(new _error.default(2003, '不可弃牌'));
331
+ if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('fold')) this.reportError(new _TexasError.default(2003, '不可弃牌'));
316
332
  _classPrivateFieldSet(_action, this, {
317
333
  type: 'fold'
318
334
  });
@@ -346,12 +362,12 @@ var Player = exports.Player = /*#__PURE__*/function () {
346
362
  case 0:
347
363
  preFlopDefaultAction = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
348
364
  if (preFlopDefaultAction === false) this.checkIfCanAct();
349
- if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('bet') && !preFlopDefaultAction) this.reportError(new _error.default(2003, '不可下注'));
365
+ if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('bet') && !preFlopDefaultAction) this.reportError(new _TexasError.default(2003, '不可下注'));
350
366
  if (money > this.balance) {
351
- this.reportError(new _error.default(2003, '下注金额不可大于筹码总数'));
367
+ this.reportError(new _TexasError.default(2003, '下注金额不可大于筹码总数'));
352
368
  }
353
369
  if (money < _classPrivateFieldGet(_lowestBetAmount, this) && !preFlopDefaultAction) {
354
- this.reportError(new _error.default(2003, '下注金额不可小于大盲注'));
370
+ this.reportError(new _TexasError.default(2003, '下注金额不可小于大盲注'));
355
371
  }
356
372
  _classPrivateFieldSet(_action, this, {
357
373
  type: 'bet',
@@ -359,7 +375,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
359
375
  value: money
360
376
  }
361
377
  });
362
- _classPrivateFieldGet(_pool, this).add(this, money, _classPrivateFieldGet(_controller, this).stage);
378
+ _classPrivateFieldGet(_pool, this).add(this, money);
363
379
  console.log(_classPrivateFieldGet(_userInfo, this).name, '下注金额:', money, '剩余筹码:', this.balance);
364
380
  _classPrivateFieldGet(_dealer, this).addAction(this);
365
381
  _context3.next = 11;
@@ -394,12 +410,12 @@ var Player = exports.Player = /*#__PURE__*/function () {
394
410
  }).map(function (p) {
395
411
  return _classPrivateFieldGet(_currentStageTotalAmount, p);
396
412
  })));
397
- if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('raise')) this.reportError(new _error.default(2003, '不可加注'));
413
+ if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('raise')) this.reportError(new _TexasError.default(2003, '不可加注'));
398
414
  if (money > this.balance) {
399
- this.reportError(new _error.default(2003, '加注金额不可大于余额'));
415
+ this.reportError(new _TexasError.default(2003, '加注金额不可大于余额'));
400
416
  }
401
417
  if (money < _classPrivateFieldGet(_lowestBetAmount, this)) {
402
- this.reportError(new _error.default(2003, '加注金额不可小于大盲注'));
418
+ this.reportError(new _TexasError.default(2003, '加注金额不可小于大盲注'));
403
419
  }
404
420
  if (!(money + _classPrivateFieldGet(_currentStageTotalAmount, this) <= maxBetAmount)) {
405
421
  _context4.next = 12;
@@ -409,14 +425,14 @@ var Player = exports.Player = /*#__PURE__*/function () {
409
425
  _context4.next = 10;
410
426
  break;
411
427
  }
412
- this.reportError(new _error.default(2003, '必须加注更多的金额'));
428
+ this.reportError(new _TexasError.default(2003, '必须加注更多的金额'));
413
429
  _context4.next = 12;
414
430
  break;
415
431
  case 10:
416
432
  _context4.next = 12;
417
433
  return this.call();
418
434
  case 12:
419
- _classPrivateFieldGet(_pool, this).add(this, money, _classPrivateFieldGet(_controller, this).stage);
435
+ _classPrivateFieldGet(_pool, this).add(this, money);
420
436
  _classPrivateFieldSet(_action, this, {
421
437
  type: 'raise',
422
438
  payload: {
@@ -450,14 +466,14 @@ var Player = exports.Player = /*#__PURE__*/function () {
450
466
  while (1) switch (_context5.prev = _context5.next) {
451
467
  case 0:
452
468
  this.checkIfCanAct();
453
- if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('call')) this.reportError(new _error.default(2003, '不可跟注'));
469
+ if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('call')) this.reportError(new _TexasError.default(2003, '不可跟注'));
454
470
 
455
471
  // 其他玩家的最大下注金额
456
472
  maxBetAmount = this.getOthersMaxBetAmountAtCurrentStage();
457
473
  moneyShouldPay = maxBetAmount - _classPrivateFieldGet(_currentStageTotalAmount, this);
458
- if (moneyShouldPay <= 0) this.reportError(new _error.default(2003, "\u6570\u636E\u5F02\u5E38, \u8BF7\u624B\u52A8\u4E0B\u6CE8, try to call: ".concat(moneyShouldPay, ", balance: ").concat(this.balance, ", maxBet: ").concat(maxBetAmount)));
474
+ if (moneyShouldPay <= 0) this.reportError(new _TexasError.default(2003, "\u6570\u636E\u5F02\u5E38, \u8BF7\u624B\u52A8\u4E0B\u6CE8, try to call: ".concat(moneyShouldPay, ", balance: ").concat(this.balance, ", maxBet: ").concat(maxBetAmount)));
459
475
  if (moneyShouldPay > this.balance) {
460
- this.reportError(new _error.default(2003, '跟注金额不可大于筹码总数'));
476
+ this.reportError(new _TexasError.default(2003, '跟注金额不可大于筹码总数'));
461
477
  }
462
478
  _classPrivateFieldSet(_action, this, {
463
479
  type: 'call',
@@ -465,7 +481,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
465
481
  value: moneyShouldPay
466
482
  }
467
483
  });
468
- _classPrivateFieldGet(_pool, this).add(this, moneyShouldPay, _classPrivateFieldGet(_controller, this).stage);
484
+ _classPrivateFieldGet(_pool, this).add(this, moneyShouldPay);
469
485
  _classPrivateFieldGet(_dealer, this).addAction(this);
470
486
  _context5.next = 11;
471
487
  return (_classPrivateFieldGet6 = _classPrivateFieldGet(_callbackOfAction, this)) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.call(this, this);
@@ -494,14 +510,14 @@ var Player = exports.Player = /*#__PURE__*/function () {
494
510
  case 0:
495
511
  this.checkIfCanAct();
496
512
  if (!_assertClassBrand(_Player_brand, this, _getAllowedActions).call(this).includes('allIn')) {
497
- this.reportError(new _error.default(2003, '不可全押'));
513
+ this.reportError(new _TexasError.default(2003, '不可全押'));
498
514
  }
499
515
 
500
516
  // 其他玩家持有筹码的最大值, 全押金额不可超过该值
501
517
  maxAllInAmount = this.getMaxAllInAmount();
502
518
  moneyShouldPay = Math.min(Math.max(maxAllInAmount - _classPrivateFieldGet(_currentStageTotalAmount, this), _classPrivateFieldGet(_lowestBetAmount, this)), this.balance);
503
- if (moneyShouldPay <= 0) this.reportError(new _error.default(2003, "\u6570\u636E\u5F02\u5E38,\u8BF7\u624B\u52A8\u4E0B\u6CE8, try to allIn: ".concat(moneyShouldPay, "; balance: ").concat(this.balance)));
504
- _classPrivateFieldGet(_pool, this).add(this, moneyShouldPay, _classPrivateFieldGet(_controller, this).stage);
519
+ if (moneyShouldPay <= 0) this.reportError(new _TexasError.default(2003, "\u6570\u636E\u5F02\u5E38,\u8BF7\u624B\u52A8\u4E0B\u6CE8, try to allIn: ".concat(moneyShouldPay, "; balance: ").concat(this.balance)));
520
+ _classPrivateFieldGet(_pool, this).add(this, moneyShouldPay);
505
521
  _classPrivateFieldSet(_action, this, {
506
522
  type: 'allIn',
507
523
  payload: {
@@ -643,8 +659,8 @@ var Player = exports.Player = /*#__PURE__*/function () {
643
659
  }, {
644
660
  key: "checkIfCanAct",
645
661
  value: function checkIfCanAct() {
646
- if (_classPrivateFieldGet(_controller, this).status !== 'on') this.reportError(new _error.default(2003, '游戏不在进行中, 不可行动'));
647
- if (_classPrivateFieldGet(_status, this) !== 'active') this.reportError(new _error.default(2003, '没有控制权, 无法行动'));
662
+ if (_classPrivateFieldGet(_controller, this).status !== 'on') this.reportError(new _TexasError.default(2003, '游戏不在进行中, 不可行动'));
663
+ if (_classPrivateFieldGet(_status, this) !== 'active') this.reportError(new _TexasError.default(2003, '没有控制权, 无法行动'));
648
664
  }
649
665
  }, {
650
666
  key: "toString",
@@ -667,28 +683,14 @@ var Player = exports.Player = /*#__PURE__*/function () {
667
683
  value: function getHandPokes() {
668
684
  return _classPrivateFieldGet(_handPokes, this);
669
685
  }
670
-
671
- // TODO: 需要先写到数据库
672
686
  }, {
673
687
  key: "earn",
674
- value: function () {
675
- var _earn = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(money) {
676
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
677
- while (1) switch (_context7.prev = _context7.next) {
678
- case 0:
679
- this.balance += money;
680
- console.log(_classPrivateFieldGet(_userInfo, this).name, '分得奖池金额:', money);
681
- case 2:
682
- case "end":
683
- return _context7.stop();
684
- }
685
- }, _callee7, this);
686
- }));
687
- function earn(_x3) {
688
- return _earn.apply(this, arguments);
689
- }
690
- return earn;
691
- }() // 游戏推进到下个阶段后, 需要将此字段清空
688
+ value: function earn(money) {
689
+ this.balance += money;
690
+ console.log(_classPrivateFieldGet(_userInfo, this).name, '分得奖池金额:', money);
691
+ }
692
+
693
+ // 游戏推进到下个阶段后, 需要将此字段清空
692
694
  }, {
693
695
  key: "resetCurrentStageTotalAmount",
694
696
  value: function resetCurrentStageTotalAmount() {
@@ -727,7 +729,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
727
729
  var nextPlayerToGetController = this.returnNextPlayerIf(function (player) {
728
730
  return player.getStatus() === 'waiting';
729
731
  });
730
- if (!nextPlayerToGetController) this.reportError(new _error.default(2000, '游戏发生异常, 将控制权移交给不存在的玩家'));
732
+ if (!nextPlayerToGetController) this.reportError(new _TexasError.default(2000, '游戏发生异常, 将控制权移交给不存在的玩家'));
731
733
  _classPrivateFieldGet(_controller, this).transferControlTo(nextPlayerToGetController);
732
734
  }
733
735
  }, {
@@ -759,6 +761,13 @@ var Player = exports.Player = /*#__PURE__*/function () {
759
761
  this.takeDefaultAction();
760
762
  return;
761
763
  }
764
+ // 如果当前玩家是离线状态, 延时一秒后直接采取默认行为
765
+ if (_classPrivateFieldGet(_onlineStatus, this) === 'offline') {
766
+ setTimeout(function () {
767
+ _this3.takeDefaultAction();
768
+ }, 1000);
769
+ return;
770
+ }
762
771
  if (!_classPrivateFieldGet(_timer, this)) _classPrivateFieldSet(_timer, this, setInterval(function () {
763
772
  var _this$countDownTime, _this$countDownTime2;
764
773
  if (_classPrivateFieldGet(_countDownTime, _this3) === 0 && _classPrivateFieldGet(_timer, _this3)) {
@@ -786,15 +795,29 @@ var Player = exports.Player = /*#__PURE__*/function () {
786
795
  }
787
796
  this.clearTimer();
788
797
  }
798
+
799
+ /**
800
+ * @description 获取行动前的min~max 下注金额范围
801
+ */
802
+ }, {
803
+ key: "getRestrict",
804
+ value: function getRestrict() {
805
+ var max = Math.min(this.getMaxAllInAmount() - _classPrivateFieldGet(_currentStageTotalAmount, this), this.balance);
806
+
807
+ // 计算出跟注的金额
808
+ var moneyShouldCall = this.getOthersMaxBetAmountAtCurrentStage() - _classPrivateFieldGet(_currentStageTotalAmount, this);
809
+ // 如果跟注金额小于0, 则使用盲注金额
810
+ var min = moneyShouldCall <= 0 ? Math.min(_classPrivateFieldGet(_lowestBetAmount, this), this.balance) : moneyShouldCall;
811
+ return {
812
+ min: min,
813
+ max: max
814
+ };
815
+ }
789
816
  }, {
790
817
  key: "getControl",
791
818
  value: function getControl() {
792
819
  var _classPrivateFieldGet8;
793
- // 如果余额不够, 则只能下注剩余余额
794
- var max = Math.max(this.getMaxAllInAmount() - _classPrivateFieldGet(_currentStageTotalAmount, this), this.balance);
795
- // 最低为大盲注
796
- var min = Math.max(this.getOthersMaxBetAmountAtCurrentStage() - _classPrivateFieldGet(_currentStageTotalAmount, this), Math.min(_classPrivateFieldGet(_lowestBetAmount, this), this.balance));
797
-
820
+ // 如果余额不够, 则只能下注剩余余额(all-in)
798
821
  // 最大值是好计算的
799
822
  // 最小值就是跟注的金额
800
823
  var allowedActions = _assertClassBrand(_Player_brand, this, _getAllowedActions).call(this);
@@ -803,10 +826,7 @@ var Player = exports.Player = /*#__PURE__*/function () {
803
826
  (_classPrivateFieldGet8 = _classPrivateFieldGet(_callback, this)) === null || _classPrivateFieldGet8 === void 0 || _classPrivateFieldGet8.call(this, {
804
827
  allowedActions: allowedActions,
805
828
  userId: _classPrivateFieldGet(_userInfo, this).id,
806
- restrict: {
807
- min: min,
808
- max: max
809
- }
829
+ restrict: this.getRestrict()
810
830
  });
811
831
  _classPrivateFieldSet(_status, this, 'active');
812
832
  this.continue();
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.js");
4
+ require("core-js/modules/es.symbol.description.js");
5
+ require("core-js/modules/es.symbol.iterator.js");
6
+ require("core-js/modules/es.array.from.js");
7
+ require("core-js/modules/es.array.iterator.js");
8
+ require("core-js/modules/es.function.name.js");
9
+ require("core-js/modules/es.regexp.exec.js");
10
+ require("core-js/modules/es.regexp.to-string.js");
11
+ require("core-js/modules/es.string.iterator.js");
12
+ require("core-js/modules/web.dom-collections.iterator.js");
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.default = void 0;
17
+ require("core-js/modules/es.array.includes.js");
18
+ require("core-js/modules/es.array.map.js");
19
+ require("core-js/modules/es.array.slice.js");
20
+ require("core-js/modules/es.array.sort.js");
21
+ require("core-js/modules/es.object.to-string.js");
22
+ require("core-js/modules/es.string.includes.js");
23
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
24
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
26
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
27
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
28
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
29
+ /**
30
+ * @description 分配奖池时, 会出现3个人分配2000奖池, 导致除不尽的情况
31
+ * 系统会将无法整数分配的奖池, 随机分配给玩家, 比如说 666 667 667
32
+ */
33
+ var allocatePoolByInt = function allocatePoolByInt(players, totalAmount) {
34
+ var count = players.length;
35
+ var restAmount = totalAmount % count;
36
+ // 整除后分配的金额
37
+ var minAmount = Math.floor(totalAmount / count);
38
+ // 哪些玩家需要额外分得1积分
39
+ var playerIdsToReciveRestAmount = _toConsumableArray(players).sort(function () {
40
+ return 0.5 - Math.random();
41
+ }).slice(0, restAmount).map(function (player) {
42
+ return player.id;
43
+ });
44
+ return players.map(function (player) {
45
+ return {
46
+ player: player,
47
+ amount: playerIdsToReciveRestAmount.includes(player.id) ? minAmount + 1 : minAmount
48
+ };
49
+ });
50
+ };
51
+ var _default = exports.default = allocatePoolByInt;