|
|
@ -15,18 +15,18 @@ export class PongService { |
|
|
|
private readonly usersService: UsersService |
|
|
|
) {} |
|
|
|
|
|
|
|
async updateStats (player: User, i: number, result: Result): Promise<void> { |
|
|
|
async updateStats (player: User, i: number, result: Result, maxScore: number): Promise<void> { |
|
|
|
player.matchs++ |
|
|
|
if (result.score[i] > result.score[Math.abs(i - 1)]) player.wins++ |
|
|
|
if (result.score[i] === maxScore) player.wins++ |
|
|
|
else player.looses++ |
|
|
|
player.winrate = (100 * player.wins) / player.matchs |
|
|
|
player.rank = (await this.usersService.getRank(player.ftId)) + 1 |
|
|
|
} |
|
|
|
|
|
|
|
async updatePlayer (i: number, result: Result): Promise<void> { |
|
|
|
async updatePlayer (i: number, result: Result, maxScore: number): Promise<void> { |
|
|
|
const player: User | null = result.players[i] |
|
|
|
if (player == null) return |
|
|
|
if (result.ranked) await this.updateStats(player, i, result) |
|
|
|
if (result.ranked) await this.updateStats(player, i, result, maxScore) |
|
|
|
player.results.push(result) |
|
|
|
player.status = 'online' |
|
|
|
await this.usersService.save(player) |
|
|
@ -38,7 +38,7 @@ export class PongService { |
|
|
|
await this.usersService.save(player) |
|
|
|
} |
|
|
|
|
|
|
|
async saveResult (players: Player[], ranked: boolean): Promise<void> { |
|
|
|
async saveResult (players: Player[], ranked: boolean, maxScore: number): Promise<void> { |
|
|
|
const result = new Result() |
|
|
|
const ply = new Array<User | null>() |
|
|
|
ply.push(await this.usersService.findUserByName(players[0].name)) |
|
|
@ -47,8 +47,8 @@ export class PongService { |
|
|
|
result.players = ply |
|
|
|
result.score = [players[0].score, players[1].score] |
|
|
|
await this.resultsRepository.save(result) |
|
|
|
await this.updatePlayer(0, result) |
|
|
|
await this.updatePlayer(1, result) |
|
|
|
await this.updatePlayer(0, result, maxScore) |
|
|
|
await this.updatePlayer(1, result, maxScore) |
|
|
|
} |
|
|
|
|
|
|
|
async getHistory ( |
|
|
|