Commit 405b1fc9 authored by nanahira's avatar nanahira

add post watch

parent 96c55e12
Pipeline #43199 failed with stages
in 30 seconds
......@@ -10,6 +10,9 @@ export const TRANSLATIONS = {
blank_room_name: 'Blank room name is unallowed, please fill in something.',
replay_hint_part1: 'Sending the replay of the duel number ',
replay_hint_part2: '.',
watch_join: 'joined as spectator.',
quit_watch: 'quited spectating',
left_game: 'quited game',
},
'zh-CN': {
update_required: '请更新你的客户端版本',
......@@ -21,5 +24,8 @@ export const TRANSLATIONS = {
blank_room_name: '房间名不能为空,请在主机密码处填写房间名',
replay_hint_part1: '正在发送第',
replay_hint_part2: '局决斗的录像。',
watch_join: '加入了观战',
quit_watch: '退出了观战',
left_game: '离开了游戏',
},
};
......@@ -2,8 +2,10 @@ import { createAppContext } from 'nfkit';
import { ClientVersionCheck } from './client-version-check';
import { ContextState } from '../app';
import { Welcome } from './welcome';
import { PlayerStatusNotify } from './player-status-notify';
export const FeatsModule = createAppContext<ContextState>()
.provide(ClientVersionCheck)
.provide(Welcome)
.provide(PlayerStatusNotify)
.define();
......@@ -19,7 +19,7 @@ export class DuelRecord {
date = new Date();
winPosition?: number;
responses: Buffer[] = [];
messages: YGOProMsgBase[] = [];
watchMessages: YGOProMsgBase[] = [];
private toReplayDeck(deck: YGOProDeck | null | undefined) {
if (!deck) {
......
......@@ -295,11 +295,25 @@ export class Room {
return this.getDuelPosPlayers(swappedDuelPos);
}
private sendPostWatchMessages(client: Client) {
client.send(new YGOProStocDuelStart());
if (this.duelStage === DuelStage.Siding) {
client.send(new YGOProStocWaitingSide());
} else if (this.duelStage === DuelStage.Dueling) {
this.lastDuelRecord?.watchMessages.forEach((message) => {
client.send(
new YGOProStocGameMsg().fromPartial({ msg: message.observerView() }),
);
});
}
}
async join(client: Client) {
client.roomName = this.name;
client.isHost = !this.allPlayers.length;
const firstEmptyPlayerSlot = this.players.findIndex((p) => !p);
const isPlayer = firstEmptyPlayerSlot >= 0;
const isPlayer =
firstEmptyPlayerSlot >= 0 && this.duelStage === DuelStage.Begin;
if (isPlayer) {
this.players[firstEmptyPlayerSlot] = client;
......@@ -319,16 +333,20 @@ export class Room {
client.send(p.prepareChangePacket());
}
});
if (this.watchers.size) {
if (this.watchers.size && this.duelStage === DuelStage.Begin) {
client.send(this.watcherSizeMessage);
}
// send to other players
this.allPlayers
.filter((p) => p !== client)
.forEach((p) => {
p.send(client.prepareEnterPacket());
});
if (isPlayer) {
this.allPlayers
.filter((p) => p !== client)
.forEach((p) => {
p.send(client.prepareEnterPacket());
});
} else if (this.watchers.size && this.duelStage === DuelStage.Begin) {
client.send(this.watcherSizeMessage);
}
await this.ctx.dispatch(new OnRoomJoin(this), client);
......@@ -338,6 +356,11 @@ export class Room {
} else {
await this.ctx.dispatch(new OnRoomJoinObserver(this), client);
}
if (this.duelStage !== DuelStage.Begin) {
this.sendPostWatchMessages(client);
}
return undefined;
}
......@@ -1471,7 +1494,7 @@ export class Room {
.middleware(YGOProMsgBase, async (message, next) => {
// record messages for replay
if (!(message instanceof YGOProMsgResponseBase)) {
this.lastDuelRecord.messages.push(message);
this.lastDuelRecord.watchMessages.push(message);
}
return next();
})
......
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