From a5485094053de2416e13ae3d2b93a45032f287c7 Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 4 Dec 2020 19:41:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=93=E7=AE=97?= =?UTF-8?q?=E7=9A=84=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/commands/PartResultCommand.ts | 61 +++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/src/rooms/commands/PartResultCommand.ts b/src/rooms/commands/PartResultCommand.ts index e2155ba..3f2ed69 100644 --- a/src/rooms/commands/PartResultCommand.ts +++ b/src/rooms/commands/PartResultCommand.ts @@ -7,11 +7,58 @@ import {GameEnv} from "../../cfg/GameEnv"; import {NextTurnCommand} from "./NextTurnCommand"; import {Wait} from "./Wait"; import {PlayerStateConst} from "../../constants/PlayerStateConst"; +import {Player} from "../schema/Player"; +import gameUtil from "../../utils/game.util"; /** * 游戏中的结算轮 * TODO:: */ + +export enum CompareEnum { + ALLDEAD = 0, // 不用考虑 + P0DEAD = 1, + P1DEAD = 2, + P0WIN = 3, + P1WIN = 4, + DRAW = 5 +} + +const comparePlayer = function (p0: Player, p1: Player): CompareEnum { + let s0 = gameUtil.calcTotalAp(p0); + let s1 = gameUtil.calcTotalAp(p1); + if (p0.state == PlayerStateConst.PLAYER_DEAD) { + if (p1.state == PlayerStateConst.PLAYER_DEAD) { + return CompareEnum.ALLDEAD; + } else { + return CompareEnum.P0DEAD; + } + } else { + if (p1.state == PlayerStateConst.PLAYER_DEAD) { + return CompareEnum.P1DEAD + } else { + if (s0 > s1) { + let val = s0 - s1; + p1.hp -= val; + if (p1.hp <= 0) { + p1.hp = 0; + p1.state = PlayerStateConst.PLAYER_DEAD; + } + return CompareEnum.P0WIN + } else if (s0 < s1) { + let val = s1 - s0; + p0.hp -= val; + if (p0.hp <= 0) { + p0.hp = 0; + p0.state = PlayerStateConst.PLAYER_DEAD; + } + return CompareEnum.P1WIN; + } else { + return CompareEnum.DRAW; + } + } + } +} export class PartResultCommand extends Command { execute() { @@ -20,14 +67,20 @@ export class PartResultCommand extends Command { let team0 = []; let team1 = []; for (let [sessionId, player] of this.state.players) { + let score = gameUtil.calcTotalAp(player); if (player.team == 0) { - team0.push(player); + team0.push(score); } else { - team1.unshift(player); + team1.unshift(score); + } + } + let r0 = comparePlayer(team0[0], team1[0]); + let r1 = comparePlayer(team0[1], team1[1]); + if (r0 == CompareEnum.P0DEAD) { + if (r1 != CompareEnum.P1WIN) { + let result } } - - return [new Wait().setPayload(time*1000) ,new NextTurnCommand()]; } From 1db9931fcc548170d0ef35021f84db5d33bd209a Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 4 Dec 2020 19:47:39 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9A=82=E6=97=B6=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/commands/PartResultCommand.ts | 33 +++++++++++-------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/rooms/commands/PartResultCommand.ts b/src/rooms/commands/PartResultCommand.ts index 3f2ed69..a340d38 100644 --- a/src/rooms/commands/PartResultCommand.ts +++ b/src/rooms/commands/PartResultCommand.ts @@ -63,24 +63,21 @@ export class PartResultCommand extends Command { execute() { this.state.gameState = GameStateConst.STATE_ROUND_RESULT; - const time = singleton(GameEnv).resultShowTime || 1; - let team0 = []; - let team1 = []; - for (let [sessionId, player] of this.state.players) { - let score = gameUtil.calcTotalAp(player); - if (player.team == 0) { - team0.push(score); - } else { - team1.unshift(score); - } - } - let r0 = comparePlayer(team0[0], team1[0]); - let r1 = comparePlayer(team0[1], team1[1]); - if (r0 == CompareEnum.P0DEAD) { - if (r1 != CompareEnum.P1WIN) { - let result - } - } + // const time = singleton(GameEnv).resultShowTime || 1; + // let team0 = []; + // let team1 = []; + // for (let [sessionId, player] of this.state.players) { + // let score = gameUtil.calcTotalAp(player); + // if (player.team == 0) { + // team0.push(score); + // } else { + // team1.unshift(score); + // } + // } + // let r0 = comparePlayer(team0[0], team1[0]); + // let r1 = comparePlayer(team0[1], team1[1]); + + return [new Wait().setPayload(time*1000) ,new NextTurnCommand()]; } From 7f26c7b2538bf898fcbd8d7225bc6a488c192535 Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 4 Dec 2020 19:48:13 +0800 Subject: [PATCH 3/3] 2 --- src/rooms/commands/PartResultCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rooms/commands/PartResultCommand.ts b/src/rooms/commands/PartResultCommand.ts index a340d38..8d8bc21 100644 --- a/src/rooms/commands/PartResultCommand.ts +++ b/src/rooms/commands/PartResultCommand.ts @@ -63,7 +63,7 @@ export class PartResultCommand extends Command { execute() { this.state.gameState = GameStateConst.STATE_ROUND_RESULT; - // const time = singleton(GameEnv).resultShowTime || 1; + const time = singleton(GameEnv).resultShowTime || 1; // let team0 = []; // let team1 = []; // for (let [sessionId, player] of this.state.players) {