Send Elo rating in rated battles (#5595)

This commit is contained in:
TheJetOU 2019-07-11 10:38:49 +03:00 committed by Guangcong Luo
parent aea0d09cac
commit ade29349c6
5 changed files with 16 additions and 10 deletions

View File

@ -638,8 +638,10 @@ class Ladder extends LadderStore {
Rooms.createBattle(ready1.formatid, { Rooms.createBattle(ready1.formatid, {
p1: user1, p1: user1,
p1team: ready1.team, p1team: ready1.team,
p1rating: ready1.rating,
p2: user2, p2: user2,
p2team: ready2.team, p2team: ready2.team,
p2rating: ready2.rating,
rated: Math.min(ready1.rating, ready2.rating), rated: Math.min(ready1.rating, ready2.rating),
}); });
} }

View File

@ -505,11 +505,11 @@ class RoomBattle extends RoomGames.RoomGame {
this.listen(); this.listen();
this.addPlayer(options.p1, options.p1team || ''); this.addPlayer(options.p1, options.p1team || '', options.p1rating);
this.addPlayer(options.p2, options.p2team || ''); this.addPlayer(options.p2, options.p2team || '', options.p2rating);
if (this.playerCap > 2) { if (this.playerCap > 2) {
this.addPlayer(options.p3, options.p3team || ''); this.addPlayer(options.p3, options.p3team || '', options.p3rating);
this.addPlayer(options.p4, options.p4team || ''); this.addPlayer(options.p4, options.p4team || '', options.p4rating);
} }
this.timer = new RoomBattleTimer(this); this.timer = new RoomBattleTimer(this);
if (Config.forcetimer) this.timer.start(); if (Config.forcetimer) this.timer.start();
@ -960,8 +960,9 @@ class RoomBattle extends RoomGames.RoomGame {
* *
* @param {User | null} user * @param {User | null} user
* @param {string?} team * @param {string?} team
* @param {number} rating
*/ */
addPlayer(user, team) { addPlayer(user, team, rating = 0) {
// TypeScript bug: no `T extends RoomGamePlayer` // TypeScript bug: no `T extends RoomGamePlayer`
const player = /** @type {RoomBattlePlayer} */ (super.addPlayer(user)); const player = /** @type {RoomBattlePlayer} */ (super.addPlayer(user));
if (!player) return null; if (!player) return null;
@ -973,8 +974,9 @@ class RoomBattle extends RoomGames.RoomGame {
name: player.name, name: player.name,
avatar: user ? '' + user.avatar : '', avatar: user ? '' + user.avatar : '',
team: team, team: team,
rating: Math.round(rating),
}; };
this.stream.write(`>player ${slot} ` + JSON.stringify(options)); this.stream.write(`>player ${slot} ${JSON.stringify(options)}`);
} }
if (user) this.room.auth[user.userid] = Users.PLAYER_SYMBOL; if (user) this.room.auth[user.userid] = Users.PLAYER_SYMBOL;

View File

@ -11,8 +11,8 @@ Receiving messages
The beginning of a battle will look something like this: The beginning of a battle will look something like this:
|player|p1|Anonycat|60 |player|p1|Anonycat|60|1200
|player|p2|Anonybird|113 |player|p2|Anonybird|113|1300
|teamsize|p1|4 |teamsize|p1|4
|teamsize|p2|5 |teamsize|p2|5
|gametype|doubles |gametype|doubles
@ -39,7 +39,7 @@ The beginning of a battle will look something like this:
| |
|start |start
`|player|PLAYER|USERNAME|AVATAR` `|player|PLAYER|USERNAME|AVATAR|RATING`
> Player details. > Player details.
> >
@ -48,6 +48,7 @@ The beginning of a battle will look something like this:
> - `USERNAME` is the username > - `USERNAME` is the username
> - `AVATAR` is the player's avatar identifier (usually a number, but other > - `AVATAR` is the player's avatar identifier (usually a number, but other
> values can be used for custom avatars) > values can be used for custom avatars)
> - `RATING` is the player's Elo rating in the format they're playing. This will only be displayed in rated battles and when the player is first introduced otherwise it's blank
`|teamsize|PLAYER|NUMBER` `|teamsize|PLAYER|NUMBER`

View File

@ -3005,7 +3005,7 @@ export class Battle extends Dex.ModdedDex {
} }
if (!didSomething) return; if (!didSomething) return;
this.inputLog.push(`>player ${slot} ` + JSON.stringify(options)); this.inputLog.push(`>player ${slot} ` + JSON.stringify(options));
this.add('player', side.id, side.name, side.avatar); this.add('player', side.id, side.name, side.avatar, options.rating || '');
this.start(); this.start();
} }

View File

@ -1208,6 +1208,7 @@ interface TypeInfo extends Readonly<TypeData> {
interface PlayerOptions { interface PlayerOptions {
name?: string; name?: string;
avatar?: string; avatar?: string;
rating?: number;
team?: PokemonSet[] | string | null; team?: PokemonSet[] | string | null;
seed?: PRNGSeed; seed?: PRNGSeed;
} }