86 lines
2.6 KiB
TypeScript
86 lines
2.6 KiB
TypeScript
import {Command} from "@colyseus/command";
|
|
import {CardGameState} from "../schema/CardGameState";
|
|
import {DrawCommand} from "./DrawCommand";
|
|
import {GameStateConst} from "../../constants/GameStateConst";
|
|
import {singleton} from "../../common/Singleton";
|
|
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<CardGameState, {}> {
|
|
|
|
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]);
|
|
|
|
|
|
|
|
return [new Wait().setPayload(time*1000) ,new NextTurnCommand()];
|
|
}
|
|
|
|
}
|