Commit 6fd9668d authored by nanahira's avatar nanahira

put away resetDuelState

parent 22f6316f
...@@ -27,7 +27,11 @@ export class DuelRecord { ...@@ -27,7 +27,11 @@ export class DuelRecord {
endTime?: Date; endTime?: Date;
winPosition?: number; winPosition?: number;
winReason?: number; winReason?: number;
responses: Buffer[] = []; responsesWithPos: { pos: number; response: Buffer }[] = [];
// responses: Buffer[] = [];
get responses() {
return this.responsesWithPos.map((item) => item.response);
}
messages: YGOProMsgBase[] = []; messages: YGOProMsgBase[] = [];
toSwappedPlayers() { toSwappedPlayers() {
......
...@@ -1168,6 +1168,7 @@ export class Room { ...@@ -1168,6 +1168,7 @@ export class Room {
private registry: Record<string, string> = {}; private registry: Record<string, string> = {};
turnCount = 0; turnCount = 0;
turnIngamePos = 0; turnIngamePos = 0;
responsePos?: number;
get turnPos() { get turnPos() {
return this.getIngameDuelPosByDuelPos(this.turnIngamePos); return this.getIngameDuelPosByDuelPos(this.turnIngamePos);
} }
...@@ -1361,6 +1362,15 @@ export class Room { ...@@ -1361,6 +1362,15 @@ export class Room {
} }
} }
resetDuelState() {
this.turnCount = 0;
this.turnIngamePos = 0;
this.phase = undefined;
this.responsePos = undefined;
this.lastResponseRequestMsg = undefined;
this.isRetrying = false;
}
@RoomMethod({ allowInDuelStages: DuelStage.FirstGo }) @RoomMethod({ allowInDuelStages: DuelStage.FirstGo })
private async onDuelStart(client: Client, msg: YGOProCtosTpResult) { private async onDuelStart(client: Client, msg: YGOProCtosTpResult) {
// 检查是否是该玩家选先后手(duelPos 的第一个玩家) // 检查是否是该玩家选先后手(duelPos 的第一个玩家)
...@@ -1396,9 +1406,7 @@ export class Room { ...@@ -1396,9 +1406,7 @@ export class Room {
this.duelRecords.push(duelRecord); this.duelRecords.push(duelRecord);
this.duelStage = DuelStage.Dueling; this.duelStage = DuelStage.Dueling;
this.turnCount = 0; this.resetDuelState();
this.turnIngamePos = 0;
this.phase = undefined;
this.resetResponseRequestState(); this.resetResponseRequestState();
const [ const [
...@@ -1693,8 +1701,8 @@ export class Room { ...@@ -1693,8 +1701,8 @@ export class Room {
return; return;
} }
if (message instanceof YGOProMsgRetry && this.responsePos != null) { if (message instanceof YGOProMsgRetry && this.responsePos != null) {
if (this.lastDuelRecord.responses.length > 0) { if (this.lastDuelRecord.responsesWithPos.length > 0) {
this.lastDuelRecord.responses.pop(); this.lastDuelRecord.responsesWithPos.pop();
} }
this.isRetrying = true; this.isRetrying = true;
await this.sendWaitingToNonOperator( await this.sendWaitingToNonOperator(
...@@ -1786,7 +1794,6 @@ export class Room { ...@@ -1786,7 +1794,6 @@ export class Room {
}); });
private matchKilled = false; private matchKilled = false;
private responsePos?: number;
get responsePlayer() { get responsePlayer() {
if (this.responsePos == null) { if (this.responsePos == null) {
...@@ -1911,7 +1918,7 @@ export class Room { ...@@ -1911,7 +1918,7 @@ export class Room {
const responsePos = this.responsePos; const responsePos = this.responsePos;
const responseRequestMsg = this.lastResponseRequestMsg; const responseRequestMsg = this.lastResponseRequestMsg;
const response = Buffer.from(msg.response); const response = Buffer.from(msg.response);
this.lastDuelRecord.responses.push(response); this.lastDuelRecord.responsesWithPos.push({ pos: responsePos, response });
if (this.hasTimeLimit) { if (this.hasTimeLimit) {
this.clearResponseTimer(true); this.clearResponseTimer(true);
const msgType = this.isRetrying const msgType = this.isRetrying
......
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