封装一些下发消息

This commit is contained in:
zhl 2020-12-03 14:57:28 +08:00
parent b3fceda525
commit cb7b1cef6d
10 changed files with 63 additions and 11 deletions

View File

@ -16,6 +16,8 @@ export class GameStateConst {
public static readonly DETERMINE_TURN = 6;
// 选英雄阶段
public static readonly CHANGE_HERO = 7;
// 游戏中的结算轮
public static readonly STATE_ROUND_RESULT = 8;
// 游戏结束
public static readonly STATE_GAME_OVER = 9;

19
src/global.d.ts vendored
View File

@ -9,12 +9,19 @@ declare global {
}
}
}
declare module colyseus {
namespace Colyseus {
class Room {
testFun(param1: string): void;
}
/**
* GeneralRoom
*/
import { Room } from "colyseus";
declare module "colyseus" {
interface Room {
/**
* 广
* @param data
* @param options
*/
bUserJoin(data?: any, options?: any): void;
}
}

View File

@ -9,6 +9,7 @@ import { GeneralRoom } from "./rooms/GeneralRoom";
import {MongooseDriver} from "colyseus/lib/matchmaker/drivers/MongooseDriver";
import {initData} from "./common/GConfig";
require('./rooms/MSender');
const port = Number(process.env.PORT || 2567);
const app = express()

View File

@ -81,4 +81,14 @@ export class GeneralRoom extends Room {
this.dispatcher.stop();
}
/**
* begin of message
*/
/**
* end of message
*/
}

8
src/rooms/MSender.ts Normal file
View File

@ -0,0 +1,8 @@
import { Room } from "colyseus";
const room = Room.prototype;
room.bUserJoin = function (data, options?: any) {
this.broadcast("player_join", data, options);
}

View File

@ -1,6 +1,7 @@
import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {DrawCommand} from "./DrawCommand";
import {GameStateConst} from "../../constants/GameStateConst";
/**
*
@ -8,7 +9,7 @@ import {DrawCommand} from "./DrawCommand";
export class NextTurnCommand extends Command<CardGameState, {}> {
execute() {
this.state.gameState = 2;
this.state.gameState = GameStateConst.STATE_BEGIN_DRAW;
this.state.subTurn = '';
const sessionIds = [...this.state.players.keys()];
this.state.currentTurn = (this.state.currentTurn)

View File

@ -21,7 +21,7 @@ export class OnJoinCommand extends Command<CardGameState, {
this.room.lock();
this.state.gameState = GameStateConst.STATE_WAIT_PREPARE;
}
this.room.broadcast("player_join", `${client.sessionId}`, {except: client});
this.room.bUserJoin(`${client.sessionId}`, {except: client});
}
}

View File

@ -0,0 +1,16 @@
import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {DrawCommand} from "./DrawCommand";
import {GameStateConst} from "../../constants/GameStateConst";
/**
*
* TODO::
*/
export class PartResultCommand extends Command<CardGameState, {}> {
execute() {
this.state.gameState = GameStateConst.STATE_ROUND_RESULT;
}
}

View File

@ -2,14 +2,14 @@ import {Card} from "../rooms/schema/Card";
import arrUtil from "./array.util";
import {Player} from "../rooms/schema/Player";
import {singleton} from "../common/Singleton";
import {GameEnv} from "../cfg/GameEnv";
import {BaseConst} from "../constants/BaseConst";
import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
let gameUtil = {
// TODO: 根据配表生成牌组
/**
* ,
*/
initCardQue() {
let cards: Array<Card> = [];
let numCfgMap: Map<number, SystemCardCfg> = global.$cfg.get(BaseConst.SYSTEMCARD);
@ -34,6 +34,12 @@ let gameUtil = {
arrUtil.randomSort(cards);
return cards;
},
/**
* , id
* @param weightArr
* @param effCfgMap
* @param countMap
*/
getRandomEffect(weightArr: number[][], effCfgMap: Map<number, EffectCardCfg>, countMap: Map<number, number>) {
let total = 0;
let tmpArr:number[][] = [];

View File

@ -14,6 +14,7 @@
"strict": true,
"strictNullChecks": false,
"esModuleInterop": true,
"moduleResolution": "node",
"experimentalDecorators": true
}
}