diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 2f398d5..737c2ec 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -42,7 +42,7 @@ export class GeneralRoom extends Room { this.onMessage("select_pet_c2s", (client, message) => { console.log('select_pet from ', client.sessionId, message); - this.dispatcher.dispatch(new SelectPetCommand(), {client, cardId: message.cardId}); + this.dispatcher.dispatch(new SelectPetCommand(), {client, cardId: message.cardId, playerId: message.player, pos: message.pos, effCards: message.effCards }); }); this.onMessage("select_hero_c2s", (client, message) => { diff --git a/src/rooms/commands/BeginGameCommand.ts b/src/rooms/commands/BeginGameCommand.ts index 86e7863..0426a3c 100644 --- a/src/rooms/commands/BeginGameCommand.ts +++ b/src/rooms/commands/BeginGameCommand.ts @@ -6,7 +6,11 @@ import gameUtil from "../../utils/game.util"; import {singleton} from "../../common/Singleton"; import {GameEnv} from "../../cfg/GameEnv"; - +/** + * 开始游戏 + * 1. 生成卡组 + * 2. 将游戏状态改为 STATE_CHANGE_CARD + */ export class BeginGameCommand extends Command { execute() { diff --git a/src/rooms/commands/ChangeCardCommand.ts b/src/rooms/commands/ChangeCardCommand.ts index 20eaa2a..1539fd2 100644 --- a/src/rooms/commands/ChangeCardCommand.ts +++ b/src/rooms/commands/ChangeCardCommand.ts @@ -8,6 +8,9 @@ import {singleton} from "../../common/Singleton"; import {GameEnv} from "../../cfg/GameEnv"; import {GameStateConst} from "../../constants/GameStateConst"; +/** + * 开局换卡 + */ export class ChangeCardCommand extends Command { validate({ client, cards } = this.payload) { const player = this.state.players.get(client.sessionId); diff --git a/src/rooms/commands/DiscardCommand.ts b/src/rooms/commands/DiscardCommand.ts index 8fc9b50..7715509 100644 --- a/src/rooms/commands/DiscardCommand.ts +++ b/src/rooms/commands/DiscardCommand.ts @@ -29,11 +29,19 @@ export class DiscardCommand extends Command { execute() { let sessionId = this.state.currentTurn; diff --git a/src/rooms/commands/EatCardCommand.ts b/src/rooms/commands/EatCardCommand.ts index 8e4300f..db9b2ba 100644 --- a/src/rooms/commands/EatCardCommand.ts +++ b/src/rooms/commands/EatCardCommand.ts @@ -3,7 +3,9 @@ import {CardGameState} from "../schema/CardGameState"; import {Client} from "colyseus"; import gameUtil from "../../utils/game.util"; - +/** + * 吃牌 + */ export class EatCardCommand extends Command { execute({ client, cards, target } = this.payload) { const player = this.state.players.get(client.sessionId); diff --git a/src/rooms/commands/NextSubCommand.ts b/src/rooms/commands/NextSubCommand.ts index 405ba85..80bfb0d 100644 --- a/src/rooms/commands/NextSubCommand.ts +++ b/src/rooms/commands/NextSubCommand.ts @@ -1,11 +1,15 @@ import { Command } from "@colyseus/command"; import { CardGameState } from "../schema/CardGameState"; import {NextTurnCommand} from "./NextTurnCommand"; +import {GameStateConst} from "../../constants/GameStateConst"; +/** + * 下一个吃牌轮 + */ export class NextSubCommand extends Command { execute() { - this.state.gameState = 3; + this.state.gameState = GameStateConst.STATE_BEGIN_EAT; const sessionIds = [...this.state.players.keys()]; let nextSubTurn = this.state.subTurn ? sessionIds[(sessionIds.indexOf(this.state.subTurn) + 1) % sessionIds.length] diff --git a/src/rooms/commands/NextTurnCommand.ts b/src/rooms/commands/NextTurnCommand.ts index f72af1e..5a5aea5 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"; +/** + * 下一轮 + */ export class NextTurnCommand extends Command { execute() { diff --git a/src/rooms/commands/OnJoinCommand.ts b/src/rooms/commands/OnJoinCommand.ts index 85d80e7..05e77b8 100644 --- a/src/rooms/commands/OnJoinCommand.ts +++ b/src/rooms/commands/OnJoinCommand.ts @@ -3,6 +3,9 @@ import {CardGameState} from "../schema/CardGameState"; import {Player} from "../schema/Player"; import {Client} from "colyseus"; +/** + * 玩家成功加入房间 + */ export class OnJoinCommand extends Command { diff --git a/src/rooms/commands/PlayReadyCommand.ts b/src/rooms/commands/PlayReadyCommand.ts index 9e1f529..6b80588 100644 --- a/src/rooms/commands/PlayReadyCommand.ts +++ b/src/rooms/commands/PlayReadyCommand.ts @@ -1,14 +1,12 @@ import {Command} from "@colyseus/command"; import {CardGameState} from "../schema/CardGameState"; import {Client} from "colyseus"; -import gameUtil from "../../utils/game.util"; -import {GeneralRoom} from "../GeneralRoom"; -import {singleton} from "../../common/Singleton"; -import {GameEnv} from "../../cfg/GameEnv"; import {PlayerStateConst} from "../../constants/PlayerStateConst"; import {GameStateConst} from "../../constants/GameStateConst"; -import {PrepareCommand} from "./PrepareCommand"; +/** + * 玩家已准备 + */ export class PlayReadyCommand extends Command { diff --git a/src/rooms/commands/PrepareCommand.ts b/src/rooms/commands/PrepareCommand.ts index 62810a9..62c0f60 100644 --- a/src/rooms/commands/PrepareCommand.ts +++ b/src/rooms/commands/PrepareCommand.ts @@ -3,7 +3,9 @@ import {CardGameState} from "../schema/CardGameState"; import {GameStateConst} from "../../constants/GameStateConst"; import {BeginGameCommand} from "./BeginGameCommand"; - +/** + * 开局随机发牌比大小, 确定先手 + */ export class PrepareCommand extends Command { execute() { diff --git a/src/rooms/commands/SelectHeroCommand.ts b/src/rooms/commands/SelectHeroCommand.ts index 32fd974..cea1f86 100644 --- a/src/rooms/commands/SelectHeroCommand.ts +++ b/src/rooms/commands/SelectHeroCommand.ts @@ -4,6 +4,9 @@ import {Client} from "colyseus"; import {PlayerStateConst} from "../../constants/PlayerStateConst"; import {BeginGameCommand} from "./BeginGameCommand"; +/** + * 选择英雄 + */ export class SelectHeroCommand extends Command { execute({ client, heroId } = this.payload) { let player = this.state.players.get(client.sessionId); diff --git a/src/rooms/commands/SelectPetCommand.ts b/src/rooms/commands/SelectPetCommand.ts index e4b5d9b..2b1daaa 100644 --- a/src/rooms/commands/SelectPetCommand.ts +++ b/src/rooms/commands/SelectPetCommand.ts @@ -3,8 +3,16 @@ import { CardGameState } from "../schema/CardGameState"; import {Client} from "colyseus"; import {NextTurnCommand} from "./NextTurnCommand"; -export class SelectPetCommand extends Command { - execute({client, cardId}: {client: Client, cardId: string}) { +/** + * 选择随从或者法术 + */ +export class SelectPetCommand extends Command { + execute({client, cardId, playerId, pos, effCards}: {client: Client, cardId: string, playerId: string, pos: number, effCards: string[]}) { let sessionId = this.state.currentTurn; let player = this.state.players.get(sessionId); let ap = 0; diff --git a/src/rooms/schema/Pet.ts b/src/rooms/schema/Pet.ts index 24e8639..47189ed 100644 --- a/src/rooms/schema/Pet.ts +++ b/src/rooms/schema/Pet.ts @@ -13,6 +13,9 @@ export class Pet extends Schema { @type("string") type: string; + @type("string") + id: string; + constructor() { super(); diff --git a/src/utils/game.util.ts b/src/utils/game.util.ts index 2fa48f1..b2fac43 100644 --- a/src/utils/game.util.ts +++ b/src/utils/game.util.ts @@ -81,6 +81,51 @@ let gameUtil = { player.cardSet.add(card.id); } return cards; + }, + /** + * 检查出牌是否符合规则 + * @param cardsLst + */ + checkDiscard(cardsLst: Card[]) { + if (cardsLst.length == 0 || cardsLst.length == 2) { + return false + } + let numSet: number[] = []; + cardsLst.forEach(function (value) { + if (value.number < 11) { + numSet.push(value.number); + } + }); + if (numSet.length === 1) { + return true; + } + if (numSet.length < 3) { + return false; + } + numSet.sort((a, b) => { + return a - b; + }); + let preNum; + let sequence = true; //是否是顺序 + let same = true; //是否是相同 + for (let num of numSet) { + if (preNum) { + if (num !== (preNum + 1) && sequence) { + sequence = false; + } + if (num !== preNum && same) { + same = false; + } + if (!sequence && !same) { + return false; + } + } + preNum = num; + } + + return true; + } + } export default gameUtil;