resolve conflict
This commit is contained in:
commit
19d9714cc4
@ -16,6 +16,8 @@ export class GameStateConst {
|
|||||||
public static readonly DETERMINE_TURN = 6;
|
public static readonly DETERMINE_TURN = 6;
|
||||||
// 选英雄阶段
|
// 选英雄阶段
|
||||||
public static readonly CHANGE_HERO = 7;
|
public static readonly CHANGE_HERO = 7;
|
||||||
|
// 游戏中的结算轮
|
||||||
|
public static readonly STATE_ROUND_RESULT = 8;
|
||||||
// 游戏结束
|
// 游戏结束
|
||||||
public static readonly STATE_GAME_OVER = 9;
|
public static readonly STATE_GAME_OVER = 9;
|
||||||
|
|
||||||
|
30
src/global.d.ts
vendored
30
src/global.d.ts
vendored
@ -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 {
|
* @param client
|
||||||
testFun(param1: string): void;
|
* @param data
|
||||||
}
|
*/
|
||||||
|
sSelectHero(client: Client, data?: any);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 广播英雄选择结果
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
bSelectHero(data?: any);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import { GeneralRoom } from "./rooms/GeneralRoom";
|
|||||||
import {MongooseDriver} from "colyseus/lib/matchmaker/drivers/MongooseDriver";
|
import {MongooseDriver} from "colyseus/lib/matchmaker/drivers/MongooseDriver";
|
||||||
import {initData} from "./common/GConfig";
|
import {initData} from "./common/GConfig";
|
||||||
|
|
||||||
|
require('./rooms/MSender');
|
||||||
|
|
||||||
const port = Number(process.env.PORT || 2567);
|
const port = Number(process.env.PORT || 2567);
|
||||||
const app = express()
|
const app = express()
|
||||||
|
@ -53,7 +53,7 @@ export class GeneralRoom extends Room {
|
|||||||
|
|
||||||
this.onMessage("select_hero_c2s", (client, message) => {
|
this.onMessage("select_hero_c2s", (client, message) => {
|
||||||
console.log('select_hero from ', client.sessionId, 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) => {
|
this.onMessage("*", (client, type, message) => {
|
||||||
@ -81,4 +81,14 @@ export class GeneralRoom extends Room {
|
|||||||
this.dispatcher.stop();
|
this.dispatcher.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* begin of message
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* end of message
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
16
src/rooms/MSender.ts
Normal file
16
src/rooms/MSender.ts
Normal 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);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
import {Command} from "@colyseus/command";
|
import {Command} from "@colyseus/command";
|
||||||
import {CardGameState} from "../schema/CardGameState";
|
import {CardGameState} from "../schema/CardGameState";
|
||||||
import {DrawCommand} from "./DrawCommand";
|
import {DrawCommand} from "./DrawCommand";
|
||||||
|
import {GameStateConst} from "../../constants/GameStateConst";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下一轮
|
* 下一轮
|
||||||
@ -8,7 +9,7 @@ import {DrawCommand} from "./DrawCommand";
|
|||||||
export class NextTurnCommand extends Command<CardGameState, {}> {
|
export class NextTurnCommand extends Command<CardGameState, {}> {
|
||||||
|
|
||||||
execute() {
|
execute() {
|
||||||
this.state.gameState = 2;
|
this.state.gameState = GameStateConst.STATE_BEGIN_DRAW;
|
||||||
this.state.subTurn = '';
|
this.state.subTurn = '';
|
||||||
const sessionIds = [...this.state.players.keys()];
|
const sessionIds = [...this.state.players.keys()];
|
||||||
this.state.currentTurn = (this.state.currentTurn)
|
this.state.currentTurn = (this.state.currentTurn)
|
||||||
|
@ -4,6 +4,7 @@ import {Player} from "../schema/Player";
|
|||||||
import {Client} from "colyseus";
|
import {Client} from "colyseus";
|
||||||
import {GameStateConst} from "../../constants/GameStateConst";
|
import {GameStateConst} from "../../constants/GameStateConst";
|
||||||
import { BattleHandler } from "rooms/logic/Handler/BattleHandler";
|
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 team = this.state.players.size / 2 | 0;
|
||||||
let player = new Player(0, team);
|
let player = new Player(0, team);
|
||||||
this.state.players.set(client.sessionId, player);
|
this.state.players.set(client.sessionId, player);
|
||||||
battle.addPlayer(player);
|
|
||||||
if (this.state.players.size >= this.room.maxClients) {
|
if (this.state.players.size >= this.room.maxClients) {
|
||||||
this.room.lock();
|
this.room.lock();
|
||||||
this.state.gameState = GameStateConst.STATE_WAIT_PREPARE;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,16 +3,24 @@ import {CardGameState} from "../schema/CardGameState";
|
|||||||
import {Client} from "colyseus";
|
import {Client} from "colyseus";
|
||||||
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
||||||
import {BeginGameCommand} from "./BeginGameCommand";
|
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}> {
|
export class SelectHeroCommand extends Command<CardGameState, {client: Client, heroId: number, battle: BattleHandler}> {
|
||||||
execute({ client, heroId } = this.payload) {
|
execute({ client, heroId, battle} = this.payload) {
|
||||||
let player = this.state.players.get(client.sessionId);
|
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.heroId = heroId;
|
||||||
player.state = PlayerStateConst.PLAYER_SELECT_HERO;
|
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;
|
let readyCount = 0;
|
||||||
for (let [sessionId, player] of this.state.players) {
|
for (let [sessionId, player] of this.state.players) {
|
||||||
if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) {
|
if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) {
|
||||||
|
@ -156,4 +156,4 @@ export class PetHandler {
|
|||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,14 @@ import {Card} from "../rooms/schema/Card";
|
|||||||
|
|
||||||
import arrUtil from "./array.util";
|
import arrUtil from "./array.util";
|
||||||
import {Player} from "../rooms/schema/Player";
|
import {Player} from "../rooms/schema/Player";
|
||||||
import {singleton} from "../common/Singleton";
|
|
||||||
import {GameEnv} from "../cfg/GameEnv";
|
|
||||||
import {BaseConst} from "../constants/BaseConst";
|
import {BaseConst} from "../constants/BaseConst";
|
||||||
import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
|
import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
|
||||||
import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
|
import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
|
||||||
|
|
||||||
let gameUtil = {
|
let gameUtil = {
|
||||||
// TODO: 根据配表生成牌组
|
/**
|
||||||
|
* 游戏开始时, 初始化卡组
|
||||||
|
*/
|
||||||
initCardQue() {
|
initCardQue() {
|
||||||
let cards: Array<Card> = [];
|
let cards: Array<Card> = [];
|
||||||
let numCfgMap: Map<number, SystemCardCfg> = global.$cfg.get(BaseConst.SYSTEMCARD);
|
let numCfgMap: Map<number, SystemCardCfg> = global.$cfg.get(BaseConst.SYSTEMCARD);
|
||||||
@ -34,6 +34,12 @@ let gameUtil = {
|
|||||||
arrUtil.randomSort(cards);
|
arrUtil.randomSort(cards);
|
||||||
return cards;
|
return cards;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 根据配表中的权重, 获取一个效果卡的id
|
||||||
|
* @param weightArr 配表中的权重列表
|
||||||
|
* @param effCfgMap 配表中的所有效果卡的配置
|
||||||
|
* @param countMap 当前已生成的效果卡数量
|
||||||
|
*/
|
||||||
getRandomEffect(weightArr: number[][], effCfgMap: Map<number, EffectCardCfg>, countMap: Map<number, number>) {
|
getRandomEffect(weightArr: number[][], effCfgMap: Map<number, EffectCardCfg>, countMap: Map<number, number>) {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
let tmpArr:number[][] = [];
|
let tmpArr:number[][] = [];
|
||||||
@ -46,7 +52,7 @@ let gameUtil = {
|
|||||||
for (let data of tmpArr) {
|
for (let data of tmpArr) {
|
||||||
if (data[1] >= num ) {
|
if (data[1] >= num ) {
|
||||||
let count = countMap.has(data[0]) ? countMap.get(data[0]) : 0;
|
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;
|
effid = effCfgMap.get(data[0]).id;
|
||||||
countMap.set(effid, count + 1);
|
countMap.set(effid, count + 1);
|
||||||
break;
|
break;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
"strict": true,
|
"strict": true,
|
||||||
"strictNullChecks": false,
|
"strictNullChecks": false,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
"experimentalDecorators": true
|
"experimentalDecorators": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user