From a5485094053de2416e13ae3d2b93a45032f287c7 Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 4 Dec 2020 19:41:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=93=E7=AE=97=E7=9A=84?= =?UTF-8?q?=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()]; }