diff --git a/configs/compound_tbl.json b/configs/compound_tbl.json index 2a86c77..8710c36 100644 --- a/configs/compound_tbl.json +++ b/configs/compound_tbl.json @@ -1 +1 @@ -[{"id":99001,"type_id":1,"value":6},{"id":99002,"type_id":1,"value":2},{"id":99003,"type_id":2,"value":20},{"id":99004,"type_id":1,"value":2},{"id":99005,"type_id":1,"value":3},{"id":99006,"type_id":1,"value":4},{"id":99007,"type_id":1,"value":12},{"id":99008,"type_id":2,"value":8},{"id":99009,"type_id":2,"value":8},{"id":99010,"type_id":2,"value":15},{"id":99011,"type_id":2,"value":20},{"id":99012,"type_id":2,"value":5},{"id":99013,"type_id":1,"value":5}] \ No newline at end of file +[{"id":99001,"type_id":1,"value":6},{"id":99002,"type_id":1,"value":2},{"id":99003,"type_id":2,"value":20},{"id":99004,"type_id":1,"value":2},{"id":99005,"type_id":1,"value":3},{"id":99006,"type_id":1,"value":4},{"id":99007,"type_id":1,"value":12},{"id":99008,"type_id":2,"value":8},{"id":99009,"type_id":2,"value":8},{"id":99010,"type_id":2,"value":15},{"id":99011,"type_id":2,"value":20},{"id":99012,"type_id":2,"value":5},{"id":99013,"type_id":1,"value":5},{"id":99014,"type_id":2,"value":5}] diff --git a/src/cfg/GameEnv.ts b/src/cfg/GameEnv.ts index 9634ca1..06146ac 100644 --- a/src/cfg/GameEnv.ts +++ b/src/cfg/GameEnv.ts @@ -28,6 +28,8 @@ export class GameEnv { public roundExtTime: number; // 玩家随从上限 public maxPlayerPetCount: number; + // 结算显示时间 + public resultShowTime: number; public init(data: Map) { this.initCardNum = data.get(BaseConst.INIT_CARD_NUM).value; @@ -43,5 +45,6 @@ export class GameEnv { this.maxExtTime = data.get(BaseConst.MAX_EXT_TIME).value; this.roundExtTime = data.get(BaseConst.ROUND_EXT_TIME).value; this.maxPlayerPetCount = data.get(BaseConst.MAX_PLAYER_PET_COUNT).value; + this.resultShowTime = data.get(BaseConst.ROUND_SHOW_TIME).value; } } diff --git a/src/constants/BaseConst.ts b/src/constants/BaseConst.ts index 227bb86..94fabe5 100644 --- a/src/constants/BaseConst.ts +++ b/src/constants/BaseConst.ts @@ -25,6 +25,8 @@ export class BaseConst { public static readonly ROUND_EXT_TIME = 99012; // 玩家随从上限 public static readonly MAX_PLAYER_PET_COUNT = 99013; + // 结算时间 + public static readonly ROUND_SHOW_TIME = 99014; public static readonly COMPOUND = "compound"; diff --git a/src/global.d.ts b/src/global.d.ts index ed7553c..4b2e91a 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,3 +1,4 @@ + export {}; declare global { @@ -13,6 +14,7 @@ declare global { * GeneralRoom 扩展方法 */ import {Client, Room} from "colyseus"; +import {PetInfoMsg} from "./message/PetInfo"; declare module "colyseus" { interface Room { /** @@ -27,13 +29,33 @@ declare module "colyseus" { * @param client * @param data */ - sSelectHero(client: Client, data?: any); + sSelectHero(client: Client, data?: any):void; /** * 广播英雄选择结果 * @param data */ - bSelectHero(data?: any); + bSelectHero(data?: any):void; + + /** + * 下发抽牌信息 + * @param client + * @param data + */ + sDrawCard(client: Client, data?: any):void; + + /** + * 广播游戏中的结算结果 + * @param data + */ + bPartResult(data?: any): void; + + /** + * 增加一个随从 + * @param data + */ + bAddPet(data?: PetInfoMsg): void; + } } diff --git a/src/message/IMsg.ts b/src/message/IMsg.ts new file mode 100644 index 0000000..9c43b6c --- /dev/null +++ b/src/message/IMsg.ts @@ -0,0 +1,7 @@ + + +export interface IMsg { + errcode: number; + errmsg?: string; + data?: any +} diff --git a/src/message/PetInfo.ts b/src/message/PetInfo.ts new file mode 100644 index 0000000..e7cd318 --- /dev/null +++ b/src/message/PetInfo.ts @@ -0,0 +1,25 @@ +import {IMsg} from "./IMsg"; + +/** + * 英雄, 随从信息 + */ +export class PetInfoMsg implements IMsg { + data: any; + errcode: number; + errmsg: string; + + constructor(data?: { + id: number + isHero: boolean, + ap: number, + extAp: number, + harmReduce?: number, + skills: number[], + extSkills: number[] + }) { + this.errcode = 0; + this.data = data; + } + + +} diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 2eccc3e..2be95e8 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -23,6 +23,7 @@ export class GeneralRoom extends Room { let cs = new CardGameState(); this.setState(cs); this.battleMan.init(cs); + this.clock.start(); this.state.gameSate = 0; this.onMessage("play_ready_c2s", (client, message) => { console.log('play_ready from ', client.sessionId, message); diff --git a/src/rooms/MSender.ts b/src/rooms/MSender.ts index ce9dd90..15a9fba 100644 --- a/src/rooms/MSender.ts +++ b/src/rooms/MSender.ts @@ -1,16 +1,41 @@ -import { Room } from "colyseus"; +import {Client, Room} from "colyseus"; +import {IMsg} from "../message/IMsg"; +import {PetInfoMsg} from "../message/PetInfo"; -const room = Room.prototype; -room.bUserJoin = function (data, options?: any) { - this.broadcast("player_join", data, options); -} - -room.sSelectHero = function (client, data) { - this.send(client, 'select_hero_s2c', data); -} - -room.bSelectHero = function(data) { - this.broadcast("select_hero_s2c", data); -} +Object.defineProperties(Room.prototype, { + bUserJoin: { + value: function (data?: any, options?: any) { + this.broadcast("player_join", data, options); + }, + writable: true + }, + sSelectHero: { + value: function (client: Client, data?: any) { + this.send(client, 'select_hero_s2c', data); + }, + writable: true + }, + bSelectHero: { + value: function (data?: any) { + this.broadcast("select_hero_s2c", data); + }, + writable: true + }, + sDrawCard: { + value: function (client: Client, data?: any) { + this.send(client, 'draw_card_s2c', data); + } + }, + bPartResult: { + value: function (data?: any) { + this.send("", data); + } + }, + bAddPet: { + value: function (data?: PetInfoMsg) { + this.broadcast("pet_info_s2c", data); + } + } +}); diff --git a/src/rooms/commands/BeginGameCommand.ts b/src/rooms/commands/BeginGameCommand.ts index 0426a3c..02c65a5 100644 --- a/src/rooms/commands/BeginGameCommand.ts +++ b/src/rooms/commands/BeginGameCommand.ts @@ -18,7 +18,7 @@ export class BeginGameCommand extends Command { for (let client of this.room.clients) { let player = this.state.players.get(client.sessionId); let cards = gameUtil.drawCard(this.state.cardQueue, player, singleton(GameEnv).initCardNum); - client.send('draw_card_s2c', cards); + this.room.sDrawCard(client, cards); } this.state.gameState = GameStateConst.STATE_CHANGE_CARD; } diff --git a/src/rooms/commands/ChangeCardCommand.ts b/src/rooms/commands/ChangeCardCommand.ts index 9a062c1..dbc4ba9 100644 --- a/src/rooms/commands/ChangeCardCommand.ts +++ b/src/rooms/commands/ChangeCardCommand.ts @@ -39,7 +39,7 @@ export class ChangeCardCommand extends Command { + + execute() { + this.state.gameState = GameStateConst.STATE_GAME_OVER; + } + +} diff --git a/src/rooms/commands/GiveUpCommand.ts b/src/rooms/commands/GiveUpCommand.ts index 999d111..1f3c7a1 100644 --- a/src/rooms/commands/GiveUpCommand.ts +++ b/src/rooms/commands/GiveUpCommand.ts @@ -2,6 +2,7 @@ import {Command} from "@colyseus/command"; import {CardGameState} from "../schema/CardGameState"; import {NextTurnCommand} from "./NextTurnCommand"; import {Client} from "colyseus"; +import {TurnEndCommand} from "./TurnEndCommand"; /** * 放弃吃牌 @@ -11,7 +12,7 @@ export class GiveUpCommand extends Command { this.state.giveUpCount += 1; this.room.broadcast('give_up_eat_s2c', {player: client.sessionId}); if (this.state.giveUpCount >= this.room.maxClients - 1) { - return [new NextTurnCommand()]; + return [new TurnEndCommand()]; } } } diff --git a/src/rooms/commands/NextSubCommand.ts b/src/rooms/commands/NextSubCommand.ts index 78bb45e..928546c 100644 --- a/src/rooms/commands/NextSubCommand.ts +++ b/src/rooms/commands/NextSubCommand.ts @@ -1,6 +1,5 @@ import { Command } from "@colyseus/command"; import { CardGameState } from "../schema/CardGameState"; -import {NextTurnCommand} from "./NextTurnCommand"; import {GameStateConst} from "../../constants/GameStateConst"; /** diff --git a/src/rooms/commands/NextTurnCommand.ts b/src/rooms/commands/NextTurnCommand.ts index 44826cf..434e3c9 100644 --- a/src/rooms/commands/NextTurnCommand.ts +++ b/src/rooms/commands/NextTurnCommand.ts @@ -2,6 +2,9 @@ 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 {PartResultCommand} from "./PartResultCommand"; /** * 下一轮 @@ -10,8 +13,12 @@ export class NextTurnCommand extends Command { execute() { this.state.gameState = GameStateConst.STATE_BEGIN_DRAW; - this.state.subTurn = ''; const sessionIds = [...this.state.players.keys()]; + // 如果上一轮是最后一个玩家, 则round + 1; + if (this.state.currentTurn + && sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) { + this.state.round += 1; + } this.state.currentTurn = (this.state.currentTurn) ? sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length] : sessionIds[0]; diff --git a/src/rooms/commands/PartResultCommand.ts b/src/rooms/commands/PartResultCommand.ts index abc4c9c..2441567 100644 --- a/src/rooms/commands/PartResultCommand.ts +++ b/src/rooms/commands/PartResultCommand.ts @@ -2,6 +2,10 @@ 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"; /** * 游戏中的结算轮 @@ -11,6 +15,18 @@ export class PartResultCommand extends Command { execute() { this.state.gameState = GameStateConst.STATE_ROUND_RESULT; + const time = singleton(GameEnv).resultShowTime || 1; + let team1 = []; + let team2 = []; + for (let [sessionId, player] of this.state.players) { + if (player.team == 0) { + team1.push(player); + } else { + team2.push(player); + } + } + + return [new Wait().setPayload(time*1000) ,new NextTurnCommand()]; } } diff --git a/src/rooms/commands/SelectPetCommand.ts b/src/rooms/commands/SelectPetCommand.ts index 2b1daaa..0d011c0 100644 --- a/src/rooms/commands/SelectPetCommand.ts +++ b/src/rooms/commands/SelectPetCommand.ts @@ -2,6 +2,7 @@ import { Command } from "@colyseus/command"; import { CardGameState } from "../schema/CardGameState"; import {Client} from "colyseus"; import {NextTurnCommand} from "./NextTurnCommand"; +import {TurnEndCommand} from "./TurnEndCommand"; /** * 选择随从或者法术 @@ -31,7 +32,7 @@ export class SelectPetCommand extends Command { + + execute() { + // @ts-ignore + const sessionIds = [...this.state.players.keys()]; + if (this.state.currentTurn + && sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) { + // 每n轮结束的时候结算一次 + const roundNum = singleton(GameEnv).duelRoundNum; + const totalRound = roundNum * singleton(GameEnv).maxDuelNum; + if (this.state.round % roundNum == (roundNum - 1)) { + if (this.state.round >= totalRound - 1) { + return [new GameResultCommand()]; + } else { + return [new PartResultCommand()]; + } + } + } + + return [new NextTurnCommand()] + } + +} diff --git a/src/rooms/commands/Wait.ts b/src/rooms/commands/Wait.ts index 33e23cc..9e751fd 100644 --- a/src/rooms/commands/Wait.ts +++ b/src/rooms/commands/Wait.ts @@ -2,6 +2,6 @@ import { Command } from "@colyseus/command"; export class Wait extends Command { async execute(number: number) { - await this.delay(100); + await this.delay(number); } } diff --git a/src/utils/game.util.ts b/src/utils/game.util.ts index 0f45822..311b56f 100644 --- a/src/utils/game.util.ts +++ b/src/utils/game.util.ts @@ -161,7 +161,17 @@ let gameUtil = { } return true; - + }, + /** + * 结算时计算总的ap + * @param player + */ + calcTotalAp(player: Player) { + let result = player.ap; + for (let [pid, pet] of player.pets) { + result += pet.ap; + } + return result; } }