封装一些下发消息
This commit is contained in:
parent
b3fceda525
commit
cb7b1cef6d
@ -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
19
src/global.d.ts
vendored
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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
8
src/rooms/MSender.ts
Normal 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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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});
|
||||
}
|
||||
|
||||
}
|
||||
|
16
src/rooms/commands/PartResultCommand.ts
Normal file
16
src/rooms/commands/PartResultCommand.ts
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -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[][] = [];
|
||||
|
@ -14,6 +14,7 @@
|
||||
"strict": true,
|
||||
"strictNullChecks": false,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node",
|
||||
"experimentalDecorators": true
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user