游戏结束后, 广播游戏结果信息
This commit is contained in:
parent
24dd6d5acc
commit
3649442db2
@ -23,7 +23,7 @@ const server = http.createServer(app);
|
|||||||
const gameServer = new Server({
|
const gameServer = new Server({
|
||||||
server,
|
server,
|
||||||
// driver: new MongooseDriver('mongodb://127.0.0.1/card-development'),
|
// 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
|
// register your room handlers
|
||||||
|
@ -6,6 +6,7 @@ import {Pet} from "../schema/Pet";
|
|||||||
import {singleton} from "../../common/Singleton";
|
import {singleton} from "../../common/Singleton";
|
||||||
import {GameEnv} from "../../cfg/GameEnv";
|
import {GameEnv} from "../../cfg/GameEnv";
|
||||||
import {debugRoom, error} from "../../common/Debug";
|
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<CardGameState, {}> {
|
export class GameResultCommand extends Command<CardGameState, {}> {
|
||||||
|
|
||||||
async execute() {
|
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.state.updateGameState(GameStateConst.STATE_GAME_OVER);
|
||||||
this.resetAllState();
|
this.resetAllState();
|
||||||
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
||||||
|
@ -20,6 +20,10 @@ export class PlayReadyCommand extends Command<CardGameState, {
|
|||||||
readyCount++;
|
readyCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (readyCount == 1) {
|
||||||
|
// 第一个点击确认后, 开始计时, 超时就加入机器人
|
||||||
|
|
||||||
|
}
|
||||||
// 如果所有人的状态都为已准备状态, 则开始发牌
|
// 如果所有人的状态都为已准备状态, 则开始发牌
|
||||||
if (readyCount >= this.room.maxClients) {
|
if (readyCount >= this.room.maxClients) {
|
||||||
// 比大小, 确定先手
|
// 比大小, 确定先手
|
||||||
|
Loading…
x
Reference in New Issue
Block a user