Skip to content

Commit ccfb08d

Browse files
committed
✨ feat: 更新和棋CD
1 parent 39a108e commit ccfb08d

File tree

8 files changed

+376
-300
lines changed

8 files changed

+376
-300
lines changed

game/backend/src/games/chessflip.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PlayerRole, RoomPlayer, RoomStatus } from "tiaoom";
22
import { GameRoom, IGameCommand } from ".";
3-
import { sleep } from "@/utils";
3+
import { shortTime, sleep } from "@/utils";
44

55
/*
66
象棋翻棋(暗棋)
@@ -645,6 +645,16 @@ class ChessflipGameRoom extends GameRoom {
645645

646646
case 'request-draw': {
647647
if (this.room.status !== RoomStatus.playing) break;
648+
const senderPlayer = this.getPlayerById(sender.id);
649+
if (senderPlayer?.attributes?.lastRequestedDraw) {
650+
const elapsed = Date.now() - senderPlayer.attributes.lastRequestedDraw;
651+
if (elapsed < 5 * 60 * 1000) {
652+
this.sayTo(`你刚刚发送过和棋请求,请等待 ${shortTime(Math.ceil((5 * 60 * 1000 - elapsed)))} 后再请求和棋。`, sender);
653+
break;
654+
}
655+
}
656+
this.setPlayerAttributes(sender.id, { lastRequestedDraw: Date.now() });
657+
648658
this.say(`${sender.name} 请求和棋。`);
649659
const other = this.room.validPlayers.find(p => p.id !== sender.id)!;
650660
this.commandTo('request-draw', { player: sender }, other);

0 commit comments

Comments
 (0)