增加对state的字段listerners的null check
This commit is contained in:
parent
82217d6bab
commit
832e5266b0
@ -9,6 +9,7 @@
|
||||
"debug": "node --require ts-node/register --inspect src/index.ts",
|
||||
"dev": "DEBUG=colyseus:*,jc:* node --require ts-node/register --inspect src/index.ts",
|
||||
"dev:less": "DEBUG=colyseus:command,jc:* node --require ts-node/register --inspect=0.0.0.0:9229 src/index.ts",
|
||||
"dev:jc": "DEBUG=jc:* node --require ts-node/register --inspect=0.0.0.0:9229 src/index.ts",
|
||||
"loadtest": "colyseus-loadtest loadtest/example.ts --room my_room --numClients 3",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
@ -23,7 +23,7 @@ const server = http.createServer(app);
|
||||
const gameServer = new Server({
|
||||
server,
|
||||
// driver: new MongooseDriver('mongodb://127.0.0.1/card-development'),
|
||||
driver: new MongooseDriver('mongodb://192.168.100.24/card-development-z'),
|
||||
driver: new MongooseDriver('mongodb://192.168.100.24/card-development-x'),
|
||||
});
|
||||
|
||||
// register your room handlers
|
||||
|
@ -6,6 +6,9 @@ import {CardGameState} from "../rooms/schema/CardGameState";
|
||||
import Clock from "@gamestdio/timer";
|
||||
import {GameStateConst} from "../constants/GameStateConst";
|
||||
import {Card} from "../rooms/schema/Card";
|
||||
import {BaseConst} from "../constants/BaseConst";
|
||||
import arrUtil from "../utils/array.util";
|
||||
import {HeroCfg} from "../cfg/parsers/HeroCfg";
|
||||
|
||||
export class RobotClient implements Client {
|
||||
id: string;
|
||||
@ -122,8 +125,11 @@ export class RobotClient implements Client {
|
||||
}
|
||||
private selectHero() {
|
||||
this.cards = this.svrstate.players.get(this.sessionId).cards;
|
||||
let heroMap: Map<number, HeroCfg> = global.$cfg.get(BaseConst.HERO);
|
||||
let heroArr = [...heroMap.values()];
|
||||
let hero = arrUtil.randomGet(heroArr, 1);
|
||||
this.reply('select_hero_c2s', {
|
||||
heroId: 30011
|
||||
heroId: hero[0].id
|
||||
});
|
||||
}
|
||||
private changeCard(cardIds: number[]) {
|
||||
|
@ -49,7 +49,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
*/
|
||||
resetAllState() {
|
||||
this.state.restartCount = 0;
|
||||
this.state.currentTurn = undefined;
|
||||
this.state.updateGameTurn( undefined);
|
||||
this.state.subTurn = undefined;
|
||||
this.state.round = 0;
|
||||
this.state.cardQueue.length = 0;
|
||||
|
@ -32,9 +32,9 @@ export class NextTurnCommand extends Command<CardGameState, {}> {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.state.currentTurn = (this.state.currentTurn)
|
||||
this.state.updateGameTurn((this.state.currentTurn)
|
||||
? sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length]
|
||||
: sessionIds[0];
|
||||
: sessionIds[0]);
|
||||
let player = this.state.players.get(this.state.currentTurn);
|
||||
if (!player) {
|
||||
error('未找到玩家');
|
||||
|
@ -60,12 +60,12 @@ export class CardGameState extends Schema {
|
||||
updateGameState(val: number) {
|
||||
let preVal = this.gameState;
|
||||
this.gameState = val;
|
||||
this.$listeners.gameState.invoke(val, preVal);
|
||||
this.$listeners?.gameState?.invoke(val, preVal);
|
||||
}
|
||||
|
||||
updateGameTurn(val: string) {
|
||||
let preVal = this.currentTurn;
|
||||
this.currentTurn = val;
|
||||
this.$listeners.currentTurn.invoke(val, preVal);
|
||||
this.$listeners?.currentTurn?.invoke(val, preVal);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user