Skip to content

Commit 272b102

Browse files
committed
🐞 fix: 修正玩家掉线导致游戏重置问题
1 parent 81dafcb commit 272b102

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/models/room.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export class Room extends EventEmitter implements IRoom {
174174
requireAllReadyToStart: boolean = true;
175175
attrs?: Record<string, any>;
176176
players: RoomPlayer[] = [];
177+
_isPlaying: boolean = false;
177178

178179
/**
179180
* 有效玩家列表(非观众)
@@ -211,7 +212,8 @@ export class Room extends EventEmitter implements IRoom {
211212
*/
212213
get status(): RoomStatus {
213214
if (!this.isReady) return RoomStatus.waiting;
214-
if (this.validPlayers.every((target) => target.status === PlayerStatus.playing)) return RoomStatus.playing;
215+
const onlinePlayers = this.validPlayers.filter(p => p.status != PlayerStatus.offline);
216+
if (onlinePlayers.every((target) => target.status === PlayerStatus.playing) || this._isPlaying) return RoomStatus.playing;
215217
return RoomStatus.ready;
216218
}
217219

@@ -398,6 +400,7 @@ export class Room extends EventEmitter implements IRoom {
398400
player.emit('status', PlayerStatus.playing);
399401
});
400402
this.emit("update", this);
403+
this._isPlaying = true;
401404
return this.emit("start", this);
402405
}
403406

@@ -411,6 +414,7 @@ export class Room extends EventEmitter implements IRoom {
411414
player.emit('status', PlayerStatus.unready);
412415
});
413416
this.emit("update", this);
417+
this._isPlaying = false;
414418
return this.emit("end", this);
415419
}
416420

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tiaoom",
3-
"version": "0.0.49",
3+
"version": "0.0.50",
44
"description": "",
55
"main": "./src/index.cjs",
66
"module": "./src/index.mjs",

0 commit comments

Comments
 (0)