This commit is contained in:
yuexin 2021-03-19 11:17:34 +08:00
commit 984ad01fb3
6 changed files with 61 additions and 0 deletions

View File

@ -889,6 +889,12 @@ interface Map<K, V> {
* @param value
*/
inc?(key: K, value: V): this;
/**
* Map中第一个值
* @return {Map<K, V>}
*/
getFirst?(): Map<K, V> | null;
}
Object.defineProperties(Map.prototype, {
@ -900,5 +906,15 @@ Object.defineProperties(Map.prototype, {
this.set(key, value);
}
}
},
getFirst: {
value: function<T> () {
if (this.size > 0) {
return this.values().next().value
} else {
return null
}
},
writable: true
}
});

7
src/global.d.ts vendored
View File

@ -187,6 +187,13 @@ declare module 'colyseus' {
*/
bMsgQueue(datas: IMsg[], options?: any): void;
/**
* 广
* @param data
* @param options
*/
bEatChange(data: any, options?: {except: Client}): void;
send(client: Client, type: string, data?: any): void;

18
src/message/EatCard.ts Normal file
View File

@ -0,0 +1,18 @@
import { Card } from '../rooms/schema/Card'
export class EatCard{
id: number
effect: number
owner: string
constructor() {
}
static fromCard(card: Card) {
let result = new EatCard()
result.id = card.id
result.effect = card.effect
result.owner = card.owner
return result
}
}

View File

@ -240,6 +240,15 @@ Object.defineProperties(Room.prototype, {
this.broadcast('player_dead_s2c', data, options);
}
},
bEatChange: {
value: function (data: any, options?: {except: Client}) {
let bOptions: any = {afterNextPatch: true}
if (options?.except) {
bOptions.except = options?.except
}
this.broadcast('eatcard_change_s2c', data, bOptions);
}
},
send: {
value: function (client: Client, type: string, data?: any) {

View File

@ -13,6 +13,7 @@ import { RULE_CANEAT, RULE_SINGLEEAT } from '../../cfg/RoomOptions'
import { ClockNameConst } from '../../constants/ClockNameConst'
import { stopDrawCardClock } from '../../utils/clock.util'
import { CardType } from '../../cfg/enums/CardType'
import { EatCard } from '../../message/EatCard'
/**
*
@ -108,6 +109,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
for (let [key, val] of this.state.cards) {
this.state.cards.delete(key)
}
this.room.bEatChange({type: 'remove', old: EatCard.fromCard(targetCard), current: null})
} else {
if (!gameUtil.checkDiscard(tmpCards, new GameEnv().selfEatCount)) {
this.room.send(client, 'discard_card_s2c', {
@ -128,12 +130,18 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
}
// 如果当前出的牌只有一张, 且是法术牌或者随从牌, 则替换state.cards中的牌
if (tmpCards.length == 1 && (tmpCards[0].type == CardType.general || tmpCards[0].type == CardType.variable_unit)) {
let old: EatCard = null
if (this.state.cards.size > 0) {
let card = this.state.cards.values().next().value
old = EatCard.fromCard(card)
}
for (let [key, val] of this.state.cards) {
this.state.cards.delete(key)
}
let card = tmpCards[0]
card.round = this.state.round
this.state.cards.set(card.id + '', card)
this.room.bEatChange({type: 'replace', old, current: EatCard.fromCard(card)})
}
/**
* ,

View File

@ -5,6 +5,7 @@ import { GameResultCommand } from './GameResultCommand'
import gameUtil from '../../utils/game.util'
import { StateTypeEnum } from '../enums/StateTypeEnum'
import { RULE_EATFLOW, RULE_EATSELF } from '../../cfg/RoomOptions'
import { EatCard } from '../../message/EatCard'
/**
*
@ -48,12 +49,14 @@ export class TurnEndCommand extends Command<CardGameState, {}> {
//如果可以吃自己出的牌, 那么等到下一轮自己出完牌再清空
if (targetCard.owner === this.state.currentTurn && targetCard.round != this.state.round) {
this.state.cards.clear()
this.room.bEatChange({type: 'remove', old: EatCard.fromCard(targetCard), current: null})
}
} else {
// 如果不能吃自己的牌, 那么在下一回合自己轮开始前清空自己的牌
const nextPid = this.room.nextPlayer(this.state.currentTurn)
if (targetCard.owner == nextPid) {
this.state.cards.clear()
this.room.bEatChange({type: 'remove', old: EatCard.fromCard(targetCard), current: null})
}
}