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