diff --git a/src/rooms/commands/PartResultCommand.ts b/src/rooms/commands/PartResultCommand.ts index e2155ba..8d8bc21 100644 --- a/src/rooms/commands/PartResultCommand.ts +++ b/src/rooms/commands/PartResultCommand.ts @@ -7,25 +7,75 @@ 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() { 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) { - if (player.team == 0) { - team0.push(player); - } else { - team1.unshift(player); - } - } + // 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]);