From 7e7f69fc617dbde3e447990ef2522f86983be3c1 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 1 Mar 2021 15:17:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=98=AF=E5=90=A6=E8=83=BD=E5=90=83?= =?UTF-8?q?=E7=89=8C=E7=A7=BB=E8=87=B3=E7=BB=9F=E4=B8=80=E7=9A=84class?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cfg/RoomOptions.ts | 22 ++++++++++++++++++++++ src/robot/Robot.ts | 8 ++------ src/robot/RobotClient.ts | 9 ++------- src/rooms/commands/DiscardCommand.ts | 8 ++++++++ 4 files changed, 34 insertions(+), 13 deletions(-) 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,