将是否能吃牌移至统一的class中
This commit is contained in:
parent
080badc9cd
commit
7e7f69fc61
@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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];
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -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<CardGameState, { client: Client, car
|
||||
}
|
||||
let targetCard
|
||||
if (target) {
|
||||
if (!new RoomOptions().canEat(this.state.advMode)) {
|
||||
this.room.send(client, 'discard_card_s2c', {
|
||||
errcode: 7,
|
||||
errmsg: '当前游戏不允许吃牌'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (this.state.cards.size > 1) {
|
||||
this.room.send(client, 'discard_card_s2c', {
|
||||
errcode: 6,
|
||||
|
Loading…
x
Reference in New Issue
Block a user