fix: refresh auto time error

This commit is contained in:
wzdwc
2021-03-28 14:20:14 +08:00
parent 3c07b45b29
commit 10bc48eee2
10 changed files with 88 additions and 80 deletions
+19 -3
View File
@@ -47,6 +47,12 @@ export enum EGameStatus {
*/
const ACTION_TIME = 30 * 1000;
/**
* Delay add time
* @type {number}
*/
const DELAY_ADD_TIME = 60 * 1000;
/**
* Class representing a poker game
*/
@@ -63,6 +69,7 @@ export class PokerGame {
private readonly actionRoundComplete: () => void;
private readonly gameOverCallBack: () => void;
private readonly autoActionCallBack: (actionType: string, userId: string) => void;
public actionEndTime: number = 0;
// hasStraddle = false;
public slidePots: number [] = [];
public prevSize: number;
@@ -101,6 +108,9 @@ export class PokerGame {
this.setBlind();
// UTG
this.currPlayer = this.playerLink.getNode(3);
// first round
this.startActionRound();
this.actionEndTime = Date.now() + ACTION_TIME;
}
/**
@@ -331,7 +341,7 @@ export class PokerGame {
console.log('come in delay round --------2', this.actionTimeDelayCount);
this.actionTimeDelayCount --;
clearTimeout(this.actionTimeOut);
this.startActionRound(60 * 1000);
this.startActionRound(DELAY_ADD_TIME);
return ;
}
const userId = this.currPlayer.node.userId || '';
@@ -410,6 +420,7 @@ export class PokerGame {
console.log('preSize', this.prevSize);
this.currPlayer = this.currPlayer.next;
// action time out, auto action fold
this.actionEndTime = Date.now() + ACTION_TIME;
this.startActionRound();
// this.actionTimeOut = setTimeout(() => {
// const actionType = 'fold';
@@ -501,6 +512,12 @@ export class PokerGame {
this.gameOver();
}, 300);
}
// action round complete, start auto action interval
if (this.status < EGameStatus.GAME_SHOWDOWN && this.playerSize > 1) {
this.actionEndTime = Date.now() + ACTION_TIME;
this.sendCard();
this.startActionRound();
}
this.actionRoundComplete();
}
@@ -640,8 +657,7 @@ export class PokerGame {
if (this.currPlayer.node.delayCount > 0) {
this.currPlayer.node.delayCount --;
this.actionTimeDelayCount ++;
console.log('come in delay round --------', this.actionTimeDelayCount);
this.actionEndTime += DELAY_ADD_TIME;
}
console.log('come in delay round --------', this.actionTimeDelayCount);
}
}
+7 -4
View File
@@ -82,14 +82,15 @@ class GameController extends BaseSocketController {
if (roomInfo.game) {
console.log('come in', roomInfo.game.status);
if (roomInfo.game.status < 6 && roomInfo.game.playerSize > 1) {
roomInfo.game.sendCard();
roomInfo.game.startActionRound();
// roomInfo.game.sendCard();
// roomInfo.game.startActionRound();
// has allindeal slide pot
if (roomInfo.game.allInPlayers.length > 0) {
slidePots = roomInfo.game.slidePots;
}
await this.adapter('online', 'actionComplete', {
slidePots,
actionEndTime: roomInfo.game.actionEndTime,
commonCard: roomInfo.game.commonCard,
});
}
@@ -171,7 +172,7 @@ class GameController extends BaseSocketController {
},
});
roomInfo.game.play();
roomInfo.game.startActionRound();
// roomInfo.game.startActionRound();
console.log('hand card', roomInfo.game.allPlayer);
// update counter, pot, status
await this.updateGameInfo();
@@ -418,7 +419,9 @@ class GameController extends BaseSocketController {
roomInfo.game.delayActionTime();
console.log('delayTime', roomInfo.game && roomInfo.game.currPlayer.node,
userInfo);
await this.adapter('online', 'delayTime', {});
await this.adapter('online', 'delayTime', {
actionEndTime: roomInfo.game.actionEndTime,
});
}
} catch (e) {
console.log(e);
+1
View File
@@ -113,6 +113,7 @@ export default function join(): any {
userId: roomInfo.game?.currPlayer.node.userId,
},
smallBlind: roomInfo.config.smallBlind,
actionEndTime: roomInfo.game?.actionEndTime || 0,
};
const game = ctx.helper.parseMsg('gameInfo', {
data: gameInfo,
+1
View File
@@ -74,6 +74,7 @@ export default class BaseSocketController extends Controller {
pot: roomInfo.game.pot,
prevSize: roomInfo.game.prevSize,
sitList: roomInfo.sit,
actionEndTime: roomInfo.game.actionEndTime,
currPlayer: {
userId: roomInfo.game.currPlayer.node.userId,
},