From 3f02d3a3e965b1ceabfef6d8a3da5ba1b8f5b25d Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 24 Feb 2021 20:45:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=93=E7=AE=97=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=A0=87=E5=87=86=E5=92=8C=E5=90=84=E5=80=BC?= =?UTF-8?q?=E7=9A=84=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/commands/GameResultCommand.ts | 44 ++++++++++++------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/rooms/commands/GameResultCommand.ts b/src/rooms/commands/GameResultCommand.ts index 58b8ca3..b40b71d 100644 --- a/src/rooms/commands/GameResultCommand.ts +++ b/src/rooms/commands/GameResultCommand.ts @@ -40,11 +40,16 @@ class GameResult{ export class GameResultCommand extends Command { async execute() { + let teamSet = new Set() + for (let [, player] of this.state.players) { + teamSet.add(player.team) + } + const teamCount = teamSet.size // 计算最终结果 - let hp: number[] = [0, 0]; - let ap: number[] = [0, 0]; - let petAp: number[] = [0, 0]; - let score: number[] = [0, 0]; + let hp: number[] = new Array(teamCount).fill(0); + let ap: number[] = new Array(teamCount).fill(0); + let petAp: number[] = new Array(teamCount).fill(0); + let score: number[] = new Array(teamCount).fill(0); let results: Map = new Map(); const fc = global.$cfg.get(BaseConst.FORMULA); for (let [, player] of this.state.players) { @@ -64,20 +69,14 @@ export class GameResultCommand extends Command { * @type {number} */ let winner = 0; - if (hp[0] > hp[1]) { - winner = 0; - } else if (hp[0] < hp[1]) { - winner = 1; + if (Math.max.apply(this, hp) > Math.min.apply(this, hp)) { + winner = hp.indexOf(Math.max.apply(this, hp)) } else { - if (ap[0] > ap[1]) { - winner = 0; - } else if (ap[0] < ap[1]){ - winner = 1; + if (Math.max.apply(this, ap) > Math.min.apply(this, ap)) { + winner = ap.indexOf(Math.max.apply(this, ap)) } else { - if (petAp[0] >= petAp[1]) { - winner = 0; - } else if (petAp[0] < petAp[1]) { - winner = 1; + if (Math.max.apply(this, petAp) > Math.min.apply(this, petAp)) { + winner = petAp.indexOf(Math.max.apply(this, petAp)) } } } @@ -93,19 +92,18 @@ export class GameResultCommand extends Command { let resultMap: Map = new Map(); let scoreMap: Map = new Map(); for (let [, player] of this.state.players) { - let otherTeam = 1 - player.team; let result = results.get(player); if (winner == player.team) { - if (score[player.team] >= score[otherTeam]) { - result.scoreChange = 100/(1+Math.pow(10, ((score[player.team]-score[otherTeam])/2500))); + if (score[player.team] == Math.max.apply(this, score)) { + result.scoreChange = 100/(1+Math.pow(10, ((score[player.team]- Math.min.apply(this, score))/2500))); } else { - result.scoreChange = 100-100/(1+Math.pow(10, ((score[otherTeam]-score[player.team])/2500))); + result.scoreChange = 100-100/(1+Math.pow(10, ((Math.max.apply(this, score)-score[player.team])/2500))); } } else { - if (score[player.team] >= score[otherTeam]) { - result.scoreChange = -(80-80/(1+Math.pow(10, ((score[player.team]-score[otherTeam])/2500)))); + if (score[player.team] == Math.max.apply(this, score)) { + result.scoreChange = -(80-80/(1+Math.pow(10, ((score[player.team]-Math.min.apply(this, score))/2500)))); } else { - result.scoreChange = -(80/(1+Math.pow(10, ((score[otherTeam]-score[player.team])/2500)))); + result.scoreChange = -(80/(1+Math.pow(10, ((Math.max.apply(this, score)-score[player.team])/2500)))); } } let s = 0;