Commit d06bf381 authored by nanahira's avatar nanahira

add player status notify

parent 405b1fc9
Pipeline #43200 passed with stages
in 39 seconds
import { ChatColor, NetPlayerType } from 'ygopro-msg-encode';
import { Context } from '../app';
import { OnRoomJoinObserver } from '../room/room-event/on-room-join-observer';
import { OnRoomLeave } from '../room/room-event/on-room-leave';
export class PlayerStatusNotify {
constructor(private ctx: Context) {
// 观战者加入
this.ctx.middleware(OnRoomJoinObserver, async (event, client, next) => {
const room = event.room;
await room.sendChat(`${client.name} #{watch_join}`, ChatColor.LIGHTBLUE);
return next();
});
// 离开房间(根据 pos 判断是观战者还是玩家)
this.ctx.middleware(OnRoomLeave, async (event, client, next) => {
const room = event.room;
if (client.pos === NetPlayerType.OBSERVER) {
// 观战者离开
await room.sendChat(`${client.name} #{quit_watch}`, ChatColor.LIGHTBLUE);
} else {
// 玩家离开
await room.sendChat(`${client.name} #{left_game}`, ChatColor.LIGHTBLUE);
}
return next();
});
}
}
...@@ -173,7 +173,7 @@ export class Room { ...@@ -173,7 +173,7 @@ export class Room {
private async cleanPlayers(sendDuelEnd = false) { private async cleanPlayers(sendDuelEnd = false) {
await Promise.all([ await Promise.all([
...this.allPlayers.map(async (p) => { ...this.playingPlayers.map(async (p) => {
await this.kick(p, sendDuelEnd); await this.kick(p, sendDuelEnd);
if (p.pos < NetPlayerType.OBSERVER) { if (p.pos < NetPlayerType.OBSERVER) {
this.players[p.pos] = undefined; this.players[p.pos] = undefined;
...@@ -496,6 +496,16 @@ export class Room { ...@@ -496,6 +496,16 @@ export class Room {
if (nextHost) { if (nextHost) {
nextHost.isHost = true; nextHost.isHost = true;
await nextHost.sendTypeChange(); await nextHost.sendTypeChange();
// 如果游戏还在准备阶段,重置新房主的准备状态
if (this.duelStage === DuelStage.Begin && nextHost.deck) {
nextHost.deck = undefined;
// 发送 PlayerChange NOTREADY 给所有人
await Promise.all(
this.allPlayers.map((p) =>
p.send(nextHost.prepareChangePacket(PlayerChangeState.NOTREADY)),
),
);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment