Don't update the timer when an updated request is sent (#11251)

* Don't add time if there is a request update

* Ups

* Change prevRequest to updatedRequest

* Fix tests

* Refactor

* Fix tests
This commit is contained in:
André Bastos Dias 2025-07-13 22:38:58 +01:00 committed by GitHub
parent 14f8677565
commit 3b7b1d2864
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View File

@ -803,7 +803,7 @@ export class RoomBattle extends RoomGame<RoomBattlePlayer> {
}; };
this.requestCount++; this.requestCount++;
player?.sendRoom(`|request|${requestJSON}`); player?.sendRoom(`|request|${requestJSON}`);
this.timer.nextRequest(player); if (!request.update) this.timer.nextRequest(player);
break; break;
} }
player?.sendRoom(lines[2]); player?.sendRoom(lines[2]);

View File

@ -122,6 +122,7 @@ export interface SwitchRequest {
forceSwitch: boolean[]; forceSwitch: boolean[];
side: SideRequestData; side: SideRequestData;
noCancel?: boolean; noCancel?: boolean;
update?: boolean;
} }
export interface TeamPreviewRequest { export interface TeamPreviewRequest {
wait?: undefined; wait?: undefined;
@ -139,6 +140,7 @@ export interface MoveRequest {
side: SideRequestData; side: SideRequestData;
ally?: SideRequestData; ally?: SideRequestData;
noCancel?: boolean; noCancel?: boolean;
update?: boolean;
} }
export interface WaitRequest { export interface WaitRequest {
wait: true; wait: true;
@ -483,7 +485,8 @@ export class Side {
this.battle.send('sideupdate', `${this.id}\n${sideUpdate}`); this.battle.send('sideupdate', `${this.id}\n${sideUpdate}`);
} }
emitRequest(update: ChoiceRequest = this.activeRequest!) { emitRequest(update: ChoiceRequest = this.activeRequest!, updatedRequest = false) {
if (updatedRequest) (this.activeRequest as MoveRequest | SwitchRequest).update = true;
this.battle.send('sideupdate', `${this.id}\n|request|${JSON.stringify(update)}`); this.battle.send('sideupdate', `${this.id}\n|request|${JSON.stringify(update)}`);
this.activeRequest = update; this.activeRequest = update;
} }
@ -495,7 +498,7 @@ export class Side {
const updated = update ? this.updateRequestForPokemon(update.pokemon, update.update) : null; const updated = update ? this.updateRequestForPokemon(update.pokemon, update.update) : null;
const type = `[${updated ? 'Unavailable' : 'Invalid'} choice]`; const type = `[${updated ? 'Unavailable' : 'Invalid'} choice]`;
this.battle.send('sideupdate', `${this.id}\n|error|${type} ${message}`); this.battle.send('sideupdate', `${this.id}\n|error|${type} ${message}`);
if (updated) this.emitRequest(); if (updated) this.emitRequest(this.activeRequest!, true);
if (this.battle.strictChoices) throw new Error(`${type} ${message}`); if (this.battle.strictChoices) throw new Error(`${type} ${message}`);
return false; return false;
} }

View File

@ -358,7 +358,11 @@ describe('Choices', () => {
battle.p1.chooseMove(1); battle.p1.chooseMove(1);
assert(buffer.length >= 2); assert(buffer.length >= 2);
assert(buffer.some(message => message.startsWith('p1\n|error|[Unavailable choice]'))); assert(buffer.some(message => message.startsWith('p1\n|error|[Unavailable choice]')));
assert(buffer.some(message => message.startsWith('p1\n|request|') && JSON.parse(message.slice(12)).active[0].moves[0].disabled)); const message = buffer.find(message => message.startsWith('p1\n|request|'));
assert(message);
const request = JSON.parse(message.slice(12));
assert(request.active[0].moves[0].disabled);
assert(request.update);
}); });
it('should send meaningful feedback to players if they try to switch a trapped Pokémon out', () => { it('should send meaningful feedback to players if they try to switch a trapped Pokémon out', () => {
@ -376,7 +380,11 @@ describe('Choices', () => {
battle.p1.chooseSwitch(2); battle.p1.chooseSwitch(2);
assert(buffer.length >= 2); assert(buffer.length >= 2);
assert(buffer.some(message => message.startsWith('p1\n|error|[Unavailable choice]'))); assert(buffer.some(message => message.startsWith('p1\n|error|[Unavailable choice]')));
assert(buffer.some(message => message.startsWith('p1\n|request|') && JSON.parse(message.slice(12)).active[0].trapped)); const message = buffer.find(message => message.startsWith('p1\n|request|'));
assert(message);
const request = JSON.parse(message.slice(12));
assert(request.active[0].trapped);
assert(request.update);
}); });
}); });