Commit f7c5bf94 authored by nanahira's avatar nanahira

refa to responseRequestMsg

parent d06bf381
Pipeline #43201 passed with stages
in 1 minute and 27 seconds
...@@ -81,10 +81,10 @@ export class Client { ...@@ -81,10 +81,10 @@ export class Client {
return this; return this;
} }
disconnected = false; disconnected?: Date;
disconnect(): undefined { disconnect(): undefined {
this.disconnected = true; this.disconnected = new Date();
this.disconnectSubject.next(); this.disconnectSubject.next();
this.disconnectSubject.complete(); this.disconnectSubject.complete();
this._disconnect().then(); this._disconnect().then();
......
...@@ -960,18 +960,20 @@ export class Room { ...@@ -960,18 +960,20 @@ export class Room {
turnCount = 0; turnCount = 0;
turnIngamePos = 0; turnIngamePos = 0;
phase = undefined; phase = undefined;
private timerState = new TimerState(); timerState = new TimerState();
private lastResponseRequestMsgType = 0; lastResponseRequestMsg?: YGOProMsgResponseBase;
isRetrying = false;
private get hasTimeLimit() { private get hasTimeLimit() {
return this.hostinfo.time_limit > 0; return this.hostinfo.time_limit > 0;
} }
private resetDuelTimerState() { private resetResponseRequestState() {
const initialTime = this.hasTimeLimit const initialTime = this.hasTimeLimit
? Math.max(0, this.hostinfo.time_limit) * 1000 ? Math.max(0, this.hostinfo.time_limit) * 1000
: 0; : 0;
this.timerState.reset(initialTime); this.timerState.reset(initialTime);
this.lastResponseRequestMsgType = 0; this.lastResponseRequestMsg = undefined;
this.isRetrying = false;
} }
private clearResponseTimer(settleElapsed = false) { private clearResponseTimer(settleElapsed = false) {
...@@ -1225,7 +1227,7 @@ export class Room { ...@@ -1225,7 +1227,7 @@ export class Room {
this.turnCount = 0; this.turnCount = 0;
this.turnIngamePos = 0; this.turnIngamePos = 0;
this.phase = undefined; this.phase = undefined;
this.resetDuelTimerState(); this.resetResponseRequestState();
await this.dispatchGameMsg(watcherMsg.msg); await this.dispatchGameMsg(watcherMsg.msg);
await this.ctx.dispatch( await this.ctx.dispatch(
...@@ -1427,7 +1429,8 @@ export class Room { ...@@ -1427,7 +1429,8 @@ export class Room {
} }
if (message instanceof YGOProMsgResponseBase) { if (message instanceof YGOProMsgResponseBase) {
this.lastResponseRequestMsgType = getMessageIdentifier(message); this.lastResponseRequestMsg = message;
this.isRetrying = false;
this.responsePos = this.getIngameDuelPosByDuelPos( this.responsePos = this.getIngameDuelPosByDuelPos(
message.responsePlayer(), message.responsePlayer(),
); );
...@@ -1439,7 +1442,7 @@ export class Room { ...@@ -1439,7 +1442,7 @@ export class Room {
if (this.lastDuelRecord.responses.length > 0) { if (this.lastDuelRecord.responses.length > 0) {
this.lastDuelRecord.responses.pop(); this.lastDuelRecord.responses.pop();
} }
this.lastResponseRequestMsgType = OcgcoreCommonConstants.MSG_RETRY; this.isRetrying = true;
await this.sendWaitingToNonOperator( await this.sendWaitingToNonOperator(
this.getIngameDuelPosByDuelPos(this.responsePos), this.getIngameDuelPosByDuelPos(this.responsePos),
); );
...@@ -1448,7 +1451,7 @@ export class Room { ...@@ -1448,7 +1451,7 @@ export class Room {
} }
if ( if (
this.responsePos != null && this.responsePos != null &&
this.lastResponseRequestMsgType === 0 && !this.lastResponseRequestMsg &&
!(message instanceof YGOProMsgResponseBase) !(message instanceof YGOProMsgResponseBase)
) { ) {
this.responsePos = undefined; this.responsePos = undefined;
...@@ -1622,14 +1625,20 @@ export class Room { ...@@ -1622,14 +1625,20 @@ export class Room {
return; return;
} }
const responsePos = this.responsePos; const responsePos = this.responsePos;
const responseRequestMsgType = this.lastResponseRequestMsgType; const responseRequestMsg = this.lastResponseRequestMsg;
const response = Buffer.from(msg.response); const response = Buffer.from(msg.response);
this.lastDuelRecord.responses.push(response); this.lastDuelRecord.responses.push(response);
if (this.hasTimeLimit) { if (this.hasTimeLimit) {
this.clearResponseTimer(true); this.clearResponseTimer(true);
this.increaseResponseTime(responsePos, responseRequestMsgType, response); const msgType = this.isRetrying
} ? OcgcoreCommonConstants.MSG_RETRY
this.lastResponseRequestMsgType = 0; : responseRequestMsg
? getMessageIdentifier(responseRequestMsg)
: 0;
this.increaseResponseTime(responsePos, msgType, response);
}
this.lastResponseRequestMsg = undefined;
this.isRetrying = false;
await this.ocgcore.setResponse(msg.response); await this.ocgcore.setResponse(msg.response);
return this.advance(); return this.advance();
} }
......
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