resolve conflict

This commit is contained in:
yuexin 2020-12-03 19:06:35 +08:00
commit 19d9714cc4
12 changed files with 98 additions and 17 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;

30
src/global.d.ts vendored
View File

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

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

@ -53,7 +53,7 @@ export class GeneralRoom extends Room {
this.onMessage("select_hero_c2s", (client, message) => {
console.log('select_hero from ', client.sessionId, message);
this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId});
this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId, battle: this.battleMan});
});
this.onMessage("*", (client, type, message) => {
@ -81,4 +81,14 @@ export class GeneralRoom extends Room {
this.dispatcher.stop();
}
/**
* begin of message
*/
/**
* end of message
*/
}

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

@ -0,0 +1,16 @@
import { Room } from "colyseus";
const room = Room.prototype;
room.bUserJoin = function (data, options?: any) {
this.broadcast("player_join", data, options);
}
room.sSelectHero = function (client, data) {
this.send(client, 'select_hero_s2c', data);
}
room.bSelectHero = function(data) {
this.broadcast("select_hero_s2c", data);
}

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

@ -4,6 +4,7 @@ import {Player} from "../schema/Player";
import {Client} from "colyseus";
import {GameStateConst} from "../../constants/GameStateConst";
import { BattleHandler } from "rooms/logic/Handler/BattleHandler";
import {BaseConst} from "../../constants/BaseConst";
/**
*
@ -16,12 +17,11 @@ export class OnJoinCommand extends Command<CardGameState, {
let team = this.state.players.size / 2 | 0;
let player = new Player(0, team);
this.state.players.set(client.sessionId, player);
battle.addPlayer(player);
if (this.state.players.size >= this.room.maxClients) {
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

@ -3,16 +3,24 @@ import {CardGameState} from "../schema/CardGameState";
import {Client} from "colyseus";
import {PlayerStateConst} from "../../constants/PlayerStateConst";
import {BeginGameCommand} from "./BeginGameCommand";
import {BattleHandler} from "../logic/Handler/BattleHandler";
import {BaseConst} from "../../constants/BaseConst";
/**
*
*/
export class SelectHeroCommand extends Command<CardGameState, {client: Client, heroId: number}> {
execute({ client, heroId } = this.payload) {
export class SelectHeroCommand extends Command<CardGameState, {client: Client, heroId: number, battle: BattleHandler}> {
execute({ client, heroId, battle} = this.payload) {
let player = this.state.players.get(client.sessionId);
const heroMap = global.$cfg.get(BaseConst.HERO);
if (!heroMap || !heroMap.has(heroId)) {
this.room.sSelectHero(client, {errcode: 1, errmsg: '无法找到对应英雄的配置'});
return;
}
player.heroId = heroId;
player.state = PlayerStateConst.PLAYER_SELECT_HERO;
this.room.broadcast('select_hero_s2c', {errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId});
battle.addPlayer(player);
this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId});
let readyCount = 0;
for (let [sessionId, player] of this.state.players) {
if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) {

View File

@ -156,4 +156,4 @@ export class PetHandler {
});
};
}
}

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[][] = [];
@ -46,7 +52,7 @@ let gameUtil = {
for (let data of tmpArr) {
if (data[1] >= num ) {
let count = countMap.has(data[0]) ? countMap.get(data[0]) : 0;
if (count < effCfgMap.get(data[0]).count) {
if (count <= effCfgMap.get(data[0]).count) {
effid = effCfgMap.get(data[0]).id;
countMap.set(effid, count + 1);
break;

View File

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