From 3649442db2c8eb6e0f2fed3e6579c8870fb89c00 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 14 Dec 2020 11:36:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F=E7=BB=93=E6=9D=9F=E5=90=8E,?= =?UTF-8?q?=20=E5=B9=BF=E6=92=AD=E6=B8=B8=E6=88=8F=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 +- src/rooms/commands/GameResultCommand.ts | 45 ++++++++++++++++++++++++- src/rooms/commands/PlayReadyCommand.ts | 4 +++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4fc5072..0b246b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,7 @@ const server = http.createServer(app); const gameServer = new Server({ server, // driver: new MongooseDriver('mongodb://127.0.0.1/card-development'), - driver: new MongooseDriver('mongodb://192.168.100.24/card-development'), + // driver: new MongooseDriver('mongodb://192.168.100.24/card-development2'), }); // register your room handlers diff --git a/src/rooms/commands/GameResultCommand.ts b/src/rooms/commands/GameResultCommand.ts index f823bc8..4e072d3 100644 --- a/src/rooms/commands/GameResultCommand.ts +++ b/src/rooms/commands/GameResultCommand.ts @@ -6,6 +6,7 @@ import {Pet} from "../schema/Pet"; import {singleton} from "../../common/Singleton"; import {GameEnv} from "../../cfg/GameEnv"; import {debugRoom, error} from "../../common/Debug"; +import gameUtil from "../../utils/game.util"; /** * 游戏结束 @@ -13,7 +14,49 @@ import {debugRoom, error} from "../../common/Debug"; export class GameResultCommand extends Command { async execute() { - this.room.bGameResult({}); + // 计算最终结果 + let hp0 = 0; + let hp1 = 0; + let ap0 = 0; + let ap1 = 0; + let resultArr = []; + for (let [, player] of this.state.players) { + let data = { + id: player.id, + team: player.team, + hp: player.hp, + alive: player.state != PlayerStateConst.PLAYER_DEAD, + ap: gameUtil.calcTotalAp(player) + }; + resultArr.push(data); + if (player.team == 0) { + hp0 += player.hp; + if (player.state != PlayerStateConst.PLAYER_DEAD) { + ap0 += data.ap; + } + } + if (player.team == 1) { + hp1 += player.hp; + if (player.state != PlayerStateConst.PLAYER_DEAD) { + ap1 += data.ap; + } + } + } + let winner = 0; + if (hp0 > hp1) { + winner = 0; + } else if (hp0 < hp1) { + winner = 1; + } else { + if (ap0 >= ap1) { + winner = 0; + } else { + winner = 1; + } + } + let resultData = {winner: winner, results: resultArr}; + + this.room.bGameResult(resultData); this.state.updateGameState(GameStateConst.STATE_GAME_OVER); this.resetAllState(); //启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private diff --git a/src/rooms/commands/PlayReadyCommand.ts b/src/rooms/commands/PlayReadyCommand.ts index 1e54b78..ebaabab 100644 --- a/src/rooms/commands/PlayReadyCommand.ts +++ b/src/rooms/commands/PlayReadyCommand.ts @@ -20,6 +20,10 @@ export class PlayReadyCommand extends Command= this.room.maxClients) { // 比大小, 确定先手