所有单发的消息判断client是否已为null
This commit is contained in:
parent
98067da9ef
commit
0782e1a03a
8
src/global.d.ts
vendored
8
src/global.d.ts
vendored
@ -127,6 +127,14 @@ declare module "colyseus" {
|
||||
* @param options
|
||||
*/
|
||||
bGameResult(data?: any, options?: any): void;
|
||||
|
||||
/**
|
||||
* 发送换卡消息
|
||||
* @param client
|
||||
* @param data
|
||||
*/
|
||||
sChangeCard(client: Client, data?: any):void;
|
||||
|
||||
/**
|
||||
* 发送给个人的消息列表
|
||||
* @param client
|
||||
|
@ -36,7 +36,7 @@ Object.defineProperties(Room.prototype, {
|
||||
*/
|
||||
sSelectHero: {
|
||||
value: function (client: Client, data?: any) {
|
||||
client.send('select_hero_s2c', data);
|
||||
client && client.send('select_hero_s2c', data);
|
||||
},
|
||||
writable: true
|
||||
},
|
||||
@ -56,7 +56,7 @@ Object.defineProperties(Room.prototype, {
|
||||
*/
|
||||
sDrawCard: {
|
||||
value: function (client: Client, data?: any) {
|
||||
client.send('draw_card_s2c', data);
|
||||
client && client.send('draw_card_s2c', data);
|
||||
}
|
||||
},
|
||||
/**
|
||||
@ -108,7 +108,7 @@ Object.defineProperties(Room.prototype, {
|
||||
*/
|
||||
sMsgQueue: {
|
||||
value: function (client:Client, datas?: IMsg) {
|
||||
client.send("msg_queue_s2c", datas);
|
||||
client && client.send("msg_queue_s2c", datas);
|
||||
}
|
||||
},
|
||||
/**
|
||||
@ -151,7 +151,7 @@ Object.defineProperties(Room.prototype, {
|
||||
*/
|
||||
sStealCard: {
|
||||
value: function (client: Client, data?: any) {
|
||||
client.send("steal_card_s2c", data, {afterNextPatch: true});
|
||||
client && client.send("steal_card_s2c", data, {afterNextPatch: true});
|
||||
}
|
||||
},
|
||||
/**
|
||||
@ -161,7 +161,7 @@ Object.defineProperties(Room.prototype, {
|
||||
*/
|
||||
bRemoveCard: {
|
||||
value: function (client: Client, data?: any) {
|
||||
client.send("remove_card_s2c", data);
|
||||
client && client.send("remove_card_s2c", data);
|
||||
}
|
||||
},
|
||||
/**
|
||||
@ -209,6 +209,12 @@ Object.defineProperties(Room.prototype, {
|
||||
value: function (data?: any, options?: any) {
|
||||
this.broadcast('game_result_s2c', data, options);
|
||||
}
|
||||
},
|
||||
|
||||
sChangeCard: {
|
||||
value: function (client: Client, data?: any) {
|
||||
client && client.send("change_card_s2c", data);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -22,16 +22,16 @@ export class ChangeCardCommand extends Command<CardGameState, { client: Client,
|
||||
let sessionId = client.sessionId;
|
||||
let player = this.state.players.get(sessionId);
|
||||
if (this.state.gameState != GameStateConst.STATE_CHANGE_CARD) {
|
||||
client.send('change_card_s2c', {errcode: 1, errmsg: '当前不在换卡阶段'});
|
||||
this.room.sChangeCard(client,{errcode: 1, errmsg: '当前不在换卡阶段'});
|
||||
return;
|
||||
}
|
||||
if (player.state != PlayerStateConst.PLAYER_SELECT_HERO) {
|
||||
client.send('change_card_s2c', {errcode: 2, errmsg: '当前玩家已换卡'});
|
||||
this.room.sChangeCard(client,{errcode: 2, errmsg: '当前玩家已换卡'});
|
||||
return;
|
||||
}
|
||||
const maxCount = singleton(GameEnv).cardChangeNum;
|
||||
if (cards.length > maxCount) {
|
||||
client.send('change_card_s2c', {errcode: 3, errmsg: '换卡数量超过限制'});
|
||||
this.room.sChangeCard(client,{errcode: 3, errmsg: '换卡数量超过限制'});
|
||||
return;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ export class ChangeCardCommand extends Command<CardGameState, { client: Client,
|
||||
}
|
||||
}
|
||||
let newCards = gameUtil.changeCard(this.state.cardQueue, player, cardToRemove);
|
||||
client.send('change_card_s2c', {errcode:0, errmsg: '', cards: newCards});
|
||||
this.room.sChangeCard(client,{errcode:0, errmsg: '', cards: newCards});
|
||||
player.state = PlayerStateConst.PLAYER_CHANGE_CARD;
|
||||
let finishCount = 0;
|
||||
for (let [, player] of this.state.players) {
|
||||
|
@ -24,15 +24,15 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
execute({ client, cards , dtype} = this.payload) {
|
||||
const player = this.state.players.get(client.sessionId);
|
||||
if (!player) {
|
||||
client.send('discard_card_s2c', {errcode: 1, errmsg: 'player不存在'});
|
||||
client && client.send('discard_card_s2c', {errcode: 1, errmsg: 'player不存在'});
|
||||
return;
|
||||
}
|
||||
if (!gameUtil.checkCardsExists(player.cards, cards)) {
|
||||
client.send('discard_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
|
||||
client && client.send('discard_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
|
||||
return;
|
||||
}
|
||||
if (this.state.currentTurn != client.sessionId) {
|
||||
client.send('discard_card_s2c', {errcode: 3, errmsg: '不是当前轮'});
|
||||
client && client.send('discard_card_s2c', {errcode: 3, errmsg: '不是当前轮'});
|
||||
return;
|
||||
}
|
||||
let tmpCards = [];
|
||||
@ -40,7 +40,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
tmpCards.push(player.cards.get(id + ''));
|
||||
}
|
||||
if (!gameUtil.checkDiscard(tmpCards)) {
|
||||
client.send('discard_card_s2c', {errcode: 4, errmsg: '出牌不符合规则'});
|
||||
client && client.send('discard_card_s2c', {errcode: 4, errmsg: '出牌不符合规则'});
|
||||
return;
|
||||
}
|
||||
this.state.cards.clear();
|
||||
@ -52,13 +52,6 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
let newCount = player.extraTime - Math.min(count, 0);
|
||||
player.extraTime = Math.max(newCount, 0);
|
||||
}
|
||||
// if (this.room.mainClock?.active) {
|
||||
// let maxTime = singleton(GameEnv).maxDiscardTime * 1000;
|
||||
// let count = this.room.mainClock.elapsedTime - maxTime;
|
||||
// let newCount = player.extraTime - count;
|
||||
// player.extraTime = Math.max(newCount, 0);
|
||||
// this.room.mainClock.clear();
|
||||
// }
|
||||
for (let id of cards) {
|
||||
this.state.cards.set(id+'', player.cards.get(id + ''));
|
||||
player.cards.delete(id + '');
|
||||
@ -69,7 +62,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
* 如果出一张牌的话, 进入胡牌轮
|
||||
* 否则直接进入选随从轮
|
||||
*/
|
||||
client.send('discard_card_s2c', {errcode: 0, cards: cards, type: dtype})
|
||||
client && client.send('discard_card_s2c', {errcode: 0, cards: cards, type: dtype})
|
||||
if (cards.length === 1) {
|
||||
let cardArr: Card[] = [...this.state.cards.values()];
|
||||
this.room.battleMan.onCardDiscarded(player, cardArr[0])
|
||||
@ -79,7 +72,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
this.room.battleMan.onCardLinkOver(player, cardArr);
|
||||
this.state.updateGameState(GameStateConst.STATE_PICK_PET);
|
||||
let self = this;
|
||||
client.send('eat_card_s2c', {player: player.id, errcode: 0, errmsg: ''});
|
||||
client && client.send('eat_card_s2c', {player: player.id, errcode: 0, errmsg: ''});
|
||||
let time = singleton(GameEnv).playerActTime * 1000 + player.extraTime;
|
||||
// 开启选随从计时, 计时结束后结束当前轮
|
||||
let timeOverSelectPet = function () {
|
||||
|
@ -12,19 +12,19 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
|
||||
execute({ client, cards, target } = this.payload) {
|
||||
const player = this.state.players.get(client.sessionId);
|
||||
if (!player) {
|
||||
client.send('eat_card_s2c', {errcode: 1, errmsg: 'player不存在或者'});
|
||||
client && client.send('eat_card_s2c', {errcode: 1, errmsg: 'player不存在或者'});
|
||||
return;
|
||||
}
|
||||
if (!gameUtil.checkCardsExists(player.cards, cards)) {
|
||||
client.send('eat_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
|
||||
client && client.send('eat_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
|
||||
return;
|
||||
}
|
||||
if (this.state.currentTurn == client.sessionId) {
|
||||
client.send('eat_card_s2c', {errcode: 3, errmsg: '不能吃自己的牌'});
|
||||
client && client.send('eat_card_s2c', {errcode: 3, errmsg: '不能吃自己的牌'});
|
||||
return;
|
||||
}
|
||||
if (!this.state.cards.has(target + '')) {
|
||||
client.send('eat_card_s2c', {errcode: 4, errmsg: '找不到要吃的牌'});
|
||||
client && client.send('eat_card_s2c', {errcode: 4, errmsg: '找不到要吃的牌'});
|
||||
return;
|
||||
}
|
||||
let tmpCards = [];
|
||||
@ -33,16 +33,16 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
|
||||
}
|
||||
tmpCards.push(this.state.cards.get(target + ''));
|
||||
if (!gameUtil.checkDiscard(tmpCards)) {
|
||||
client.send('discard_card_s2c', {errcode: 5, errmsg: '不符合吃牌规则'});
|
||||
client && client.send('discard_card_s2c', {errcode: 5, errmsg: '不符合吃牌规则'});
|
||||
return;
|
||||
}
|
||||
if (this.state.gameState !== GameStateConst.STATE_BEGIN_EAT) {
|
||||
client.send('discard_card_s2c', {errcode: 7, errmsg: '不是吃牌轮'});
|
||||
client && client.send('discard_card_s2c', {errcode: 7, errmsg: '不是吃牌轮'});
|
||||
return;
|
||||
}
|
||||
//将吃牌数据临时保存
|
||||
if (this.state.tmpActionMap.has(client.sessionId)) {
|
||||
client.send('discard_card_s2c', {errcode: 8, errmsg: '不可更改操作'});
|
||||
client && client.send('discard_card_s2c', {errcode: 8, errmsg: '不可更改操作'});
|
||||
return ;
|
||||
}
|
||||
this.state.tmpActionMap.set(client.sessionId, cards);
|
||||
|
@ -101,12 +101,12 @@ export class EatConfirmCommand extends Command<CardGameState, { timeUp: boolean
|
||||
// 成功后广播吃牌成功消息
|
||||
let client = this.room.getClient(player.id);
|
||||
this.room.broadcast('eat_card_s2c', {player: player.id, errcode: 0, errmsg: ''}, {except: client});
|
||||
client.send('eat_card_s2c', {player: player.id, errcode: 0, errmsg: ''});
|
||||
client && client.send('eat_card_s2c', {player: player.id, errcode: 0, errmsg: ''});
|
||||
// 向其他玩家发送吃卡失败的消息
|
||||
for (let [key, val] of tmpActionMap) {
|
||||
if (typeof val != 'number' && key !== player.id) {
|
||||
let client = this.room.getClient(key);
|
||||
client.send('eat_card_s2c', {errcode: 9, errmsg: '吃卡失败'});
|
||||
client && client.send('eat_card_s2c', {errcode: 9, errmsg: '吃卡失败'});
|
||||
}
|
||||
}
|
||||
} else if (!player && timeUp) {
|
||||
|
@ -41,7 +41,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
||||
str += '将牌组中的卡全部变成指定的效果卡: changequeue:效果卡id 例: changequeue:20011 \n';
|
||||
str += '抽一定数量的卡, 注意类型和效果id的搭配: draw:玩家index|数量|类型|效果id|点数 例: draw:0|3 or draw:0|1|1|20011|2 \n';
|
||||
str += '更新英雄血量: herohp:玩家index|血量 例: herohp:0|500 \n';
|
||||
client.send('notice_msg', str);
|
||||
client && client.send('notice_msg', str);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,7 +75,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
||||
card.effect = effectId;
|
||||
}
|
||||
let client = this.room.getClient(player.id);
|
||||
client.send('sync_card', {}, {afterNextPatch: true});
|
||||
client && client.send('sync_card', {}, {afterNextPatch: true});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,12 +29,6 @@ export class NextSubCommand extends Command<CardGameState, {}> {
|
||||
self.room.dispatcher.dispatch(new EatConfirmCommand(), {timeUp: true});
|
||||
}
|
||||
this.room.beginSchedule(time, timeOverEat, `eat_round`);
|
||||
// this.room.mainClock = this.clock.setTimeout(function () {
|
||||
// debugRoom('吃牌时间到, 进入下一轮')
|
||||
// self.room.mainClock.clear();
|
||||
// // self.room.dispatcher.dispatch(new TurnEndCommand());
|
||||
// self.room.dispatcher.dispatch(new EatConfirmCommand(), {timeUp: true});
|
||||
// }, time);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user