Commit 12308caa authored by nanahira's avatar nanahira

timer

parent c5815aaa
...@@ -934,7 +934,6 @@ export class Room { ...@@ -934,7 +934,6 @@ export class Room {
phase = undefined; phase = undefined;
private timerState = new TimerState(); private timerState = new TimerState();
private lastResponseRequestMsgType = 0; private lastResponseRequestMsgType = 0;
private pendingResponseRequestMsgType = 0;
private get hasTimeLimit() { private get hasTimeLimit() {
return this.hostinfo.time_limit > 0; return this.hostinfo.time_limit > 0;
} }
...@@ -945,7 +944,6 @@ export class Room { ...@@ -945,7 +944,6 @@ export class Room {
: 0; : 0;
this.timerState.reset(initialTime); this.timerState.reset(initialTime);
this.lastResponseRequestMsgType = 0; this.lastResponseRequestMsgType = 0;
this.pendingResponseRequestMsgType = 0;
} }
private clearResponseTimer(settleElapsed = false) { private clearResponseTimer(settleElapsed = false) {
...@@ -960,9 +958,6 @@ export class Room { ...@@ -960,9 +958,6 @@ export class Room {
) { ) {
this.timerState.leftMs[options.timedOutPlayer] = 0; this.timerState.leftMs[options.timedOutPlayer] = 0;
} }
this.pendingResponse = undefined;
this.pendingResponsePos = undefined;
this.pendingResponseRequestMsgType = 0;
this.responsePos = undefined; this.responsePos = undefined;
} }
...@@ -1334,6 +1329,20 @@ export class Room { ...@@ -1334,6 +1329,20 @@ export class Room {
]); ]);
} }
private async sendWaitingToNonOperator(ingameDuelPos: number) {
const operatingPlayer = this.getOperatingPlayer(ingameDuelPos);
const noOps = this.playingPlayers.filter((p) => p !== operatingPlayer);
await Promise.all(
noOps.map((p) =>
p.send(
new YGOProStocGameMsg().fromPartial({
msg: new YGOProMsgWaiting(),
}),
),
),
);
}
private async routeGameMsg(message: YGOProMsgBase) { private async routeGameMsg(message: YGOProMsgBase) {
if (!message) { if (!message) {
return; return;
...@@ -1370,10 +1379,37 @@ export class Room { ...@@ -1370,10 +1379,37 @@ export class Room {
} }
}), }),
); );
if (isUpdateMessage(message) || shouldRefreshFirst) { if (!isUpdateMessage(message) && !shouldRefreshFirst) {
await this.refreshForMessage(message);
}
if (message instanceof YGOProMsgResponseBase) {
this.lastResponseRequestMsgType = getMessageIdentifier(message);
this.responsePos = this.getIngameDuelPosByDuelPos(
message.responsePlayer(),
);
await this.sendWaitingToNonOperator(message.responsePlayer());
await this.setResponseTimer(this.responsePos);
return;
}
if (message instanceof YGOProMsgRetry && this.responsePos != null) {
if (this.lastDuelRecord.responses.length > 0) {
this.lastDuelRecord.responses.pop();
}
this.lastResponseRequestMsgType = OcgcoreCommonConstants.MSG_RETRY;
await this.sendWaitingToNonOperator(
this.getIngameDuelPosByDuelPos(this.responsePos),
);
await this.setResponseTimer(this.responsePos);
return; return;
} }
await this.refreshForMessage(message); if (
this.responsePos != null &&
this.lastResponseRequestMsgType === 0 &&
!(message instanceof YGOProMsgResponseBase)
) {
this.responsePos = undefined;
}
} }
private async handleGameMsg(message: YGOProMsgBase, route = false) { private async handleGameMsg(message: YGOProMsgBase, route = false) {
...@@ -1422,61 +1458,6 @@ export class Room { ...@@ -1422,61 +1458,6 @@ export class Room {
} }
return next(); return next();
}) })
.middleware(
YGOProMsgBase,
async (message, next) => {
if (this.pendingResponse) {
const resp = this.pendingResponse;
const responsePos = this.pendingResponsePos;
this.pendingResponse = undefined;
this.pendingResponsePos = undefined;
this.pendingResponseRequestMsgType = 0;
if (message instanceof YGOProMsgRetry) {
if (responsePos != null) {
this.responsePos = responsePos;
this.lastResponseRequestMsgType =
OcgcoreCommonConstants.MSG_RETRY;
await this.setResponseTimer(responsePos);
}
} else {
this.lastDuelRecord.responses.push(resp);
}
}
return next();
},
true,
)
.middleware(
YGOProMsgResponseBase,
async (message, next) => {
const op = this.getOperatingPlayer(message.responsePlayer());
const noOps = this.playingPlayers.filter((p) => p !== op);
await Promise.all(
noOps.map((p) =>
p.send(
new YGOProStocGameMsg().fromPartial({
msg: new YGOProMsgWaiting(),
}),
),
),
);
return next();
},
true,
)
.middleware(
YGOProMsgResponseBase,
async (message, next) => {
this.lastResponseRequestMsgType = getMessageIdentifier(message);
this.responsePos = this.getIngameDuelPosByDuelPos(
message.responsePlayer(),
);
await this.setResponseTimer(this.responsePos);
return next();
},
true,
)
.middleware(YGOProMsgRetry, async (message, next) => { .middleware(YGOProMsgRetry, async (message, next) => {
if (this.responsePos != null) { if (this.responsePos != null) {
const op = this.getOperatingPlayer( const op = this.getOperatingPlayer(
...@@ -1491,8 +1472,6 @@ export class Room { ...@@ -1491,8 +1472,6 @@ export class Room {
return next(); return next();
}); });
private pendingResponse?: Buffer;
private pendingResponsePos?: number;
private responsePos?: number; private responsePos?: number;
private async advance() { private async advance() {
...@@ -1591,18 +1570,14 @@ export class Room { ...@@ -1591,18 +1570,14 @@ export class Room {
return; return;
} }
const responsePos = this.responsePos; const responsePos = this.responsePos;
this.pendingResponsePos = responsePos; const responseRequestMsgType = this.lastResponseRequestMsgType;
this.pendingResponseRequestMsgType = this.lastResponseRequestMsgType; const response = Buffer.from(msg.response);
this.pendingResponse = Buffer.from(msg.response); this.lastDuelRecord.responses.push(response);
if (this.hasTimeLimit) { if (this.hasTimeLimit) {
this.clearResponseTimer(true); this.clearResponseTimer(true);
this.increaseResponseTime( this.increaseResponseTime(responsePos, responseRequestMsgType, response);
responsePos,
this.pendingResponseRequestMsgType,
this.pendingResponse,
);
} }
this.responsePos = undefined; this.lastResponseRequestMsgType = 0;
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