diff --git a/src/cfg/RoomOptions.ts b/src/cfg/RoomOptions.ts index e69de29..8cfaad4 100644 --- a/src/cfg/RoomOptions.ts +++ b/src/cfg/RoomOptions.ts @@ -0,0 +1,22 @@ +import { singleton } from '../decorators/singleton.decorator' +import { GameEnv } from './GameEnv' + +@singleton +export class RoomOptions { + /** + * 当前游戏能否吃牌 + * @param {boolean} advMode + * @return {boolean} + */ + public canEat(advMode: boolean) { + let result = false + if (advMode && new GameEnv().canEatAdv) { + result = true + } else if (!advMode && new GameEnv().canEatBase) { + result = true + } + return result + } + + +} diff --git a/src/robot/Robot.ts b/src/robot/Robot.ts index 4745206..462a081 100644 --- a/src/robot/Robot.ts +++ b/src/robot/Robot.ts @@ -5,6 +5,7 @@ import {Player} from "../rooms/schema/Player"; import assistantUtil from "../utils/assistant.util"; import {delay, wait} from "../decorators/cfg"; import { GameEnv } from '../cfg/GameEnv' +import { RoomOptions } from '../cfg/RoomOptions' export class Robot { host: string; @@ -160,12 +161,7 @@ export class Robot { @wait('maxDiscardTime') private async discard() { let targetCard - let canEat = false - if (this.room.state.advMode && new GameEnv().canEatAdv) { - canEat = true - } else if (!this.room.state.advMode && new GameEnv().canEatBase) { - canEat = true - } + let canEat = new RoomOptions().canEat(this.room.state.advMode) if (this.room.state.cards.size == 1 && canEat) { targetCard =[...this.room.state.cards.values()][0]; } diff --git a/src/robot/RobotClient.ts b/src/robot/RobotClient.ts index 5cf2558..f03fa2a 100644 --- a/src/robot/RobotClient.ts +++ b/src/robot/RobotClient.ts @@ -9,6 +9,7 @@ import {Player} from "../rooms/schema/Player"; import assistantUtil from "../utils/assistant.util"; import {wait} from "../decorators/cfg"; import { GameEnv } from '../cfg/GameEnv' +import { RoomOptions } from '../cfg/RoomOptions' /** * 服务端辅助机器人 @@ -137,13 +138,7 @@ export class RobotClient implements Client { @wait('maxDiscardTime') private async discard() { let targetCard - let canEat = false - if (this.svrstate.advMode && new GameEnv().canEatAdv) { - canEat = true - } else if (!this.svrstate.advMode && new GameEnv().canEatBase) { - canEat = true - } - + let canEat = new RoomOptions().canEat(this.svrstate.advMode) if (this.svrstate.cards.size == 1 && canEat) { targetCard =[...this.svrstate.cards.values()][0]; } diff --git a/src/rooms/commands/DiscardCommand.ts b/src/rooms/commands/DiscardCommand.ts index a79d11e..86e7869 100644 --- a/src/rooms/commands/DiscardCommand.ts +++ b/src/rooms/commands/DiscardCommand.ts @@ -9,6 +9,7 @@ import { TurnEndCommand } from './TurnEndCommand' import { Card } from '../schema/Card' import { Wait } from './Wait' import { StateTypeEnum } from '../enums/StateTypeEnum' +import { RoomOptions } from '../../cfg/RoomOptions' /** * 出牌 @@ -57,6 +58,13 @@ export class DiscardCommand extends Command 1) { this.room.send(client, 'discard_card_s2c', { errcode: 6,