所有单发的消息判断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
|
* @param options
|
||||||
*/
|
*/
|
||||||
bGameResult(data?: any, options?: any): void;
|
bGameResult(data?: any, options?: any): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送换卡消息
|
||||||
|
* @param client
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
sChangeCard(client: Client, data?: any):void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送给个人的消息列表
|
* 发送给个人的消息列表
|
||||||
* @param client
|
* @param client
|
||||||
|
@ -36,7 +36,7 @@ Object.defineProperties(Room.prototype, {
|
|||||||
*/
|
*/
|
||||||
sSelectHero: {
|
sSelectHero: {
|
||||||
value: function (client: Client, data?: any) {
|
value: function (client: Client, data?: any) {
|
||||||
client.send('select_hero_s2c', data);
|
client && client.send('select_hero_s2c', data);
|
||||||
},
|
},
|
||||||
writable: true
|
writable: true
|
||||||
},
|
},
|
||||||
@ -56,7 +56,7 @@ Object.defineProperties(Room.prototype, {
|
|||||||
*/
|
*/
|
||||||
sDrawCard: {
|
sDrawCard: {
|
||||||
value: function (client: Client, data?: any) {
|
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: {
|
sMsgQueue: {
|
||||||
value: function (client:Client, datas?: IMsg) {
|
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: {
|
sStealCard: {
|
||||||
value: function (client: Client, data?: any) {
|
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: {
|
bRemoveCard: {
|
||||||
value: function (client: Client, data?: any) {
|
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) {
|
value: function (data?: any, options?: any) {
|
||||||
this.broadcast('game_result_s2c', data, options);
|
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 sessionId = client.sessionId;
|
||||||
let player = this.state.players.get(sessionId);
|
let player = this.state.players.get(sessionId);
|
||||||
if (this.state.gameState != GameStateConst.STATE_CHANGE_CARD) {
|
if (this.state.gameState != GameStateConst.STATE_CHANGE_CARD) {
|
||||||
client.send('change_card_s2c', {errcode: 1, errmsg: '当前不在换卡阶段'});
|
this.room.sChangeCard(client,{errcode: 1, errmsg: '当前不在换卡阶段'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (player.state != PlayerStateConst.PLAYER_SELECT_HERO) {
|
if (player.state != PlayerStateConst.PLAYER_SELECT_HERO) {
|
||||||
client.send('change_card_s2c', {errcode: 2, errmsg: '当前玩家已换卡'});
|
this.room.sChangeCard(client,{errcode: 2, errmsg: '当前玩家已换卡'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const maxCount = singleton(GameEnv).cardChangeNum;
|
const maxCount = singleton(GameEnv).cardChangeNum;
|
||||||
if (cards.length > maxCount) {
|
if (cards.length > maxCount) {
|
||||||
client.send('change_card_s2c', {errcode: 3, errmsg: '换卡数量超过限制'});
|
this.room.sChangeCard(client,{errcode: 3, errmsg: '换卡数量超过限制'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ export class ChangeCardCommand extends Command<CardGameState, { client: Client,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let newCards = gameUtil.changeCard(this.state.cardQueue, player, cardToRemove);
|
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;
|
player.state = PlayerStateConst.PLAYER_CHANGE_CARD;
|
||||||
let finishCount = 0;
|
let finishCount = 0;
|
||||||
for (let [, player] of this.state.players) {
|
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) {
|
execute({ client, cards , dtype} = this.payload) {
|
||||||
const player = this.state.players.get(client.sessionId);
|
const player = this.state.players.get(client.sessionId);
|
||||||
if (!player) {
|
if (!player) {
|
||||||
client.send('discard_card_s2c', {errcode: 1, errmsg: 'player不存在'});
|
client && client.send('discard_card_s2c', {errcode: 1, errmsg: 'player不存在'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!gameUtil.checkCardsExists(player.cards, cards)) {
|
if (!gameUtil.checkCardsExists(player.cards, cards)) {
|
||||||
client.send('discard_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
|
client && client.send('discard_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.state.currentTurn != client.sessionId) {
|
if (this.state.currentTurn != client.sessionId) {
|
||||||
client.send('discard_card_s2c', {errcode: 3, errmsg: '不是当前轮'});
|
client && client.send('discard_card_s2c', {errcode: 3, errmsg: '不是当前轮'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let tmpCards = [];
|
let tmpCards = [];
|
||||||
@ -40,7 +40,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
|||||||
tmpCards.push(player.cards.get(id + ''));
|
tmpCards.push(player.cards.get(id + ''));
|
||||||
}
|
}
|
||||||
if (!gameUtil.checkDiscard(tmpCards)) {
|
if (!gameUtil.checkDiscard(tmpCards)) {
|
||||||
client.send('discard_card_s2c', {errcode: 4, errmsg: '出牌不符合规则'});
|
client && client.send('discard_card_s2c', {errcode: 4, errmsg: '出牌不符合规则'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.state.cards.clear();
|
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);
|
let newCount = player.extraTime - Math.min(count, 0);
|
||||||
player.extraTime = Math.max(newCount, 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) {
|
for (let id of cards) {
|
||||||
this.state.cards.set(id+'', player.cards.get(id + ''));
|
this.state.cards.set(id+'', player.cards.get(id + ''));
|
||||||
player.cards.delete(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) {
|
if (cards.length === 1) {
|
||||||
let cardArr: Card[] = [...this.state.cards.values()];
|
let cardArr: Card[] = [...this.state.cards.values()];
|
||||||
this.room.battleMan.onCardDiscarded(player, cardArr[0])
|
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.room.battleMan.onCardLinkOver(player, cardArr);
|
||||||
this.state.updateGameState(GameStateConst.STATE_PICK_PET);
|
this.state.updateGameState(GameStateConst.STATE_PICK_PET);
|
||||||
let self = this;
|
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 time = singleton(GameEnv).playerActTime * 1000 + player.extraTime;
|
||||||
// 开启选随从计时, 计时结束后结束当前轮
|
// 开启选随从计时, 计时结束后结束当前轮
|
||||||
let timeOverSelectPet = function () {
|
let timeOverSelectPet = function () {
|
||||||
|
@ -12,19 +12,19 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
|
|||||||
execute({ client, cards, target } = this.payload) {
|
execute({ client, cards, target } = this.payload) {
|
||||||
const player = this.state.players.get(client.sessionId);
|
const player = this.state.players.get(client.sessionId);
|
||||||
if (!player) {
|
if (!player) {
|
||||||
client.send('eat_card_s2c', {errcode: 1, errmsg: 'player不存在或者'});
|
client && client.send('eat_card_s2c', {errcode: 1, errmsg: 'player不存在或者'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!gameUtil.checkCardsExists(player.cards, cards)) {
|
if (!gameUtil.checkCardsExists(player.cards, cards)) {
|
||||||
client.send('eat_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
|
client && client.send('eat_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.state.currentTurn == client.sessionId) {
|
if (this.state.currentTurn == client.sessionId) {
|
||||||
client.send('eat_card_s2c', {errcode: 3, errmsg: '不能吃自己的牌'});
|
client && client.send('eat_card_s2c', {errcode: 3, errmsg: '不能吃自己的牌'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.state.cards.has(target + '')) {
|
if (!this.state.cards.has(target + '')) {
|
||||||
client.send('eat_card_s2c', {errcode: 4, errmsg: '找不到要吃的牌'});
|
client && client.send('eat_card_s2c', {errcode: 4, errmsg: '找不到要吃的牌'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let tmpCards = [];
|
let tmpCards = [];
|
||||||
@ -33,16 +33,16 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
|
|||||||
}
|
}
|
||||||
tmpCards.push(this.state.cards.get(target + ''));
|
tmpCards.push(this.state.cards.get(target + ''));
|
||||||
if (!gameUtil.checkDiscard(tmpCards)) {
|
if (!gameUtil.checkDiscard(tmpCards)) {
|
||||||
client.send('discard_card_s2c', {errcode: 5, errmsg: '不符合吃牌规则'});
|
client && client.send('discard_card_s2c', {errcode: 5, errmsg: '不符合吃牌规则'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.state.gameState !== GameStateConst.STATE_BEGIN_EAT) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
//将吃牌数据临时保存
|
//将吃牌数据临时保存
|
||||||
if (this.state.tmpActionMap.has(client.sessionId)) {
|
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 ;
|
return ;
|
||||||
}
|
}
|
||||||
this.state.tmpActionMap.set(client.sessionId, cards);
|
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);
|
let client = this.room.getClient(player.id);
|
||||||
this.room.broadcast('eat_card_s2c', {player: player.id, errcode: 0, errmsg: ''}, {except: client});
|
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) {
|
for (let [key, val] of tmpActionMap) {
|
||||||
if (typeof val != 'number' && key !== player.id) {
|
if (typeof val != 'number' && key !== player.id) {
|
||||||
let client = this.room.getClient(key);
|
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) {
|
} else if (!player && timeUp) {
|
||||||
|
@ -41,7 +41,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
str += '将牌组中的卡全部变成指定的效果卡: changequeue:效果卡id 例: changequeue:20011 \n';
|
str += '将牌组中的卡全部变成指定的效果卡: changequeue:效果卡id 例: changequeue:20011 \n';
|
||||||
str += '抽一定数量的卡, 注意类型和效果id的搭配: draw:玩家index|数量|类型|效果id|点数 例: draw:0|3 or draw:0|1|1|20011|2 \n';
|
str += '抽一定数量的卡, 注意类型和效果id的搭配: draw:玩家index|数量|类型|效果id|点数 例: draw:0|3 or draw:0|1|1|20011|2 \n';
|
||||||
str += '更新英雄血量: herohp:玩家index|血量 例: herohp:0|500 \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;
|
card.effect = effectId;
|
||||||
}
|
}
|
||||||
let client = this.room.getClient(player.id);
|
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});
|
self.room.dispatcher.dispatch(new EatConfirmCommand(), {timeUp: true});
|
||||||
}
|
}
|
||||||
this.room.beginSchedule(time, timeOverEat, `eat_round`);
|
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