增加下发随从信息的消息

This commit is contained in:
zhl 2020-12-03 19:22:37 +08:00
parent fc68018a32
commit c9f9cb8dd4
19 changed files with 191 additions and 24 deletions

View File

@ -1 +1 @@
[{"id":99001,"type_id":1,"value":6},{"id":99002,"type_id":1,"value":2},{"id":99003,"type_id":2,"value":20},{"id":99004,"type_id":1,"value":2},{"id":99005,"type_id":1,"value":3},{"id":99006,"type_id":1,"value":4},{"id":99007,"type_id":1,"value":12},{"id":99008,"type_id":2,"value":8},{"id":99009,"type_id":2,"value":8},{"id":99010,"type_id":2,"value":15},{"id":99011,"type_id":2,"value":20},{"id":99012,"type_id":2,"value":5},{"id":99013,"type_id":1,"value":5}] [{"id":99001,"type_id":1,"value":6},{"id":99002,"type_id":1,"value":2},{"id":99003,"type_id":2,"value":20},{"id":99004,"type_id":1,"value":2},{"id":99005,"type_id":1,"value":3},{"id":99006,"type_id":1,"value":4},{"id":99007,"type_id":1,"value":12},{"id":99008,"type_id":2,"value":8},{"id":99009,"type_id":2,"value":8},{"id":99010,"type_id":2,"value":15},{"id":99011,"type_id":2,"value":20},{"id":99012,"type_id":2,"value":5},{"id":99013,"type_id":1,"value":5},{"id":99014,"type_id":2,"value":5}]

View File

@ -28,6 +28,8 @@ export class GameEnv {
public roundExtTime: number; public roundExtTime: number;
// 玩家随从上限 // 玩家随从上限
public maxPlayerPetCount: number; public maxPlayerPetCount: number;
// 结算显示时间
public resultShowTime: number;
public init(data: Map<number, BaseCfg>) { public init(data: Map<number, BaseCfg>) {
this.initCardNum = data.get(BaseConst.INIT_CARD_NUM).value; this.initCardNum = data.get(BaseConst.INIT_CARD_NUM).value;
@ -43,5 +45,6 @@ export class GameEnv {
this.maxExtTime = data.get(BaseConst.MAX_EXT_TIME).value; this.maxExtTime = data.get(BaseConst.MAX_EXT_TIME).value;
this.roundExtTime = data.get(BaseConst.ROUND_EXT_TIME).value; this.roundExtTime = data.get(BaseConst.ROUND_EXT_TIME).value;
this.maxPlayerPetCount = data.get(BaseConst.MAX_PLAYER_PET_COUNT).value; this.maxPlayerPetCount = data.get(BaseConst.MAX_PLAYER_PET_COUNT).value;
this.resultShowTime = data.get(BaseConst.ROUND_SHOW_TIME).value;
} }
} }

View File

@ -25,6 +25,8 @@ export class BaseConst {
public static readonly ROUND_EXT_TIME = 99012; public static readonly ROUND_EXT_TIME = 99012;
// 玩家随从上限 // 玩家随从上限
public static readonly MAX_PLAYER_PET_COUNT = 99013; public static readonly MAX_PLAYER_PET_COUNT = 99013;
// 结算时间
public static readonly ROUND_SHOW_TIME = 99014;
public static readonly COMPOUND = "compound"; public static readonly COMPOUND = "compound";

26
src/global.d.ts vendored
View File

@ -1,3 +1,4 @@
export {}; export {};
declare global { declare global {
@ -13,6 +14,7 @@ declare global {
* GeneralRoom * GeneralRoom
*/ */
import {Client, Room} from "colyseus"; import {Client, Room} from "colyseus";
import {PetInfoMsg} from "./message/PetInfo";
declare module "colyseus" { declare module "colyseus" {
interface Room { interface Room {
/** /**
@ -27,13 +29,33 @@ declare module "colyseus" {
* @param client * @param client
* @param data * @param data
*/ */
sSelectHero(client: Client, data?: any); sSelectHero(client: Client, data?: any):void;
/** /**
* 广 * 广
* @param data * @param data
*/ */
bSelectHero(data?: any); bSelectHero(data?: any):void;
/**
*
* @param client
* @param data
*/
sDrawCard(client: Client, data?: any):void;
/**
* 广
* @param data
*/
bPartResult(data?: any): void;
/**
*
* @param data
*/
bAddPet(data?: PetInfoMsg): void;
} }
} }

7
src/message/IMsg.ts Normal file
View File

@ -0,0 +1,7 @@
export interface IMsg {
errcode: number;
errmsg?: string;
data?: any
}

25
src/message/PetInfo.ts Normal file
View File

@ -0,0 +1,25 @@
import {IMsg} from "./IMsg";
/**
* ,
*/
export class PetInfoMsg implements IMsg {
data: any;
errcode: number;
errmsg: string;
constructor(data?: {
id: number
isHero: boolean,
ap: number,
extAp: number,
harmReduce?: number,
skills: number[],
extSkills: number[]
}) {
this.errcode = 0;
this.data = data;
}
}

View File

@ -23,6 +23,7 @@ export class GeneralRoom extends Room {
let cs = new CardGameState(); let cs = new CardGameState();
this.setState(cs); this.setState(cs);
this.battleMan.init(cs); this.battleMan.init(cs);
this.clock.start();
this.state.gameSate = 0; this.state.gameSate = 0;
this.onMessage("play_ready_c2s", (client, message) => { this.onMessage("play_ready_c2s", (client, message) => {
console.log('play_ready from ', client.sessionId, message); console.log('play_ready from ', client.sessionId, message);

View File

@ -1,16 +1,41 @@
import { Room } from "colyseus"; import {Client, Room} from "colyseus";
import {IMsg} from "../message/IMsg";
import {PetInfoMsg} from "../message/PetInfo";
const room = Room.prototype;
room.bUserJoin = function (data, options?: any) { Object.defineProperties(Room.prototype, {
this.broadcast("player_join", data, options); bUserJoin: {
} value: function (data?: any, options?: any) {
this.broadcast("player_join", data, options);
room.sSelectHero = function (client, data) { },
this.send(client, 'select_hero_s2c', data); writable: true
} },
sSelectHero: {
room.bSelectHero = function(data) { value: function (client: Client, data?: any) {
this.broadcast("select_hero_s2c", data); this.send(client, 'select_hero_s2c', data);
} },
writable: true
},
bSelectHero: {
value: function (data?: any) {
this.broadcast("select_hero_s2c", data);
},
writable: true
},
sDrawCard: {
value: function (client: Client, data?: any) {
this.send(client, 'draw_card_s2c', data);
}
},
bPartResult: {
value: function (data?: any) {
this.send("", data);
}
},
bAddPet: {
value: function (data?: PetInfoMsg) {
this.broadcast("pet_info_s2c", data);
}
}
});

View File

@ -18,7 +18,7 @@ export class BeginGameCommand extends Command<CardGameState, {}> {
for (let client of this.room.clients) { for (let client of this.room.clients) {
let player = this.state.players.get(client.sessionId); let player = this.state.players.get(client.sessionId);
let cards = gameUtil.drawCard(this.state.cardQueue, player, singleton(GameEnv).initCardNum); let cards = gameUtil.drawCard(this.state.cardQueue, player, singleton(GameEnv).initCardNum);
client.send('draw_card_s2c', cards); this.room.sDrawCard(client, cards);
} }
this.state.gameState = GameStateConst.STATE_CHANGE_CARD; this.state.gameState = GameStateConst.STATE_CHANGE_CARD;
} }

View File

@ -39,7 +39,7 @@ export class ChangeCardCommand extends Command<CardGameState, { client: Client,
// 正式开始游戏, 第一个玩家出牌 // 正式开始游戏, 第一个玩家出牌
let curClient = this.room.clients[0]; let curClient = this.room.clients[0];
this.state.currentTurn = curClient.sessionId; this.state.currentTurn = curClient.sessionId;
this.state.subTurn = ''; this.state.round = 0;
let curPlayer = this.state.players.get(curClient.sessionId); let curPlayer = this.state.players.get(curClient.sessionId);
let cards = gameUtil.drawCard(this.state.cardQueue, curPlayer, singleton(GameEnv).roundDrawNum); let cards = gameUtil.drawCard(this.state.cardQueue, curPlayer, singleton(GameEnv).roundDrawNum);
curClient.send('draw_card_s2c', cards); curClient.send('draw_card_s2c', cards);

View File

@ -0,0 +1,14 @@
import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {GameStateConst} from "../../constants/GameStateConst";
/**
*
*/
export class GameResultCommand extends Command<CardGameState, {}> {
execute() {
this.state.gameState = GameStateConst.STATE_GAME_OVER;
}
}

View File

@ -2,6 +2,7 @@ import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState"; import {CardGameState} from "../schema/CardGameState";
import {NextTurnCommand} from "./NextTurnCommand"; import {NextTurnCommand} from "./NextTurnCommand";
import {Client} from "colyseus"; import {Client} from "colyseus";
import {TurnEndCommand} from "./TurnEndCommand";
/** /**
* *
@ -11,7 +12,7 @@ export class GiveUpCommand extends Command<CardGameState, {client: Client}> {
this.state.giveUpCount += 1; this.state.giveUpCount += 1;
this.room.broadcast('give_up_eat_s2c', {player: client.sessionId}); this.room.broadcast('give_up_eat_s2c', {player: client.sessionId});
if (this.state.giveUpCount >= this.room.maxClients - 1) { if (this.state.giveUpCount >= this.room.maxClients - 1) {
return [new NextTurnCommand()]; return [new TurnEndCommand()];
} }
} }
} }

View File

@ -1,6 +1,5 @@
import { Command } from "@colyseus/command"; import { Command } from "@colyseus/command";
import { CardGameState } from "../schema/CardGameState"; import { CardGameState } from "../schema/CardGameState";
import {NextTurnCommand} from "./NextTurnCommand";
import {GameStateConst} from "../../constants/GameStateConst"; import {GameStateConst} from "../../constants/GameStateConst";
/** /**

View File

@ -2,6 +2,9 @@ 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"; import {GameStateConst} from "../../constants/GameStateConst";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import {PartResultCommand} from "./PartResultCommand";
/** /**
* *
@ -10,8 +13,12 @@ export class NextTurnCommand extends Command<CardGameState, {}> {
execute() { execute() {
this.state.gameState = GameStateConst.STATE_BEGIN_DRAW; this.state.gameState = GameStateConst.STATE_BEGIN_DRAW;
this.state.subTurn = '';
const sessionIds = [...this.state.players.keys()]; const sessionIds = [...this.state.players.keys()];
// 如果上一轮是最后一个玩家, 则round + 1;
if (this.state.currentTurn
&& sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) {
this.state.round += 1;
}
this.state.currentTurn = (this.state.currentTurn) this.state.currentTurn = (this.state.currentTurn)
? sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length] ? sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length]
: sessionIds[0]; : sessionIds[0];

View File

@ -2,6 +2,10 @@ 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"; import {GameStateConst} from "../../constants/GameStateConst";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import {NextTurnCommand} from "./NextTurnCommand";
import {Wait} from "./Wait";
/** /**
* *
@ -11,6 +15,18 @@ export class PartResultCommand extends Command<CardGameState, {}> {
execute() { execute() {
this.state.gameState = GameStateConst.STATE_ROUND_RESULT; this.state.gameState = GameStateConst.STATE_ROUND_RESULT;
const time = singleton(GameEnv).resultShowTime || 1;
let team1 = [];
let team2 = [];
for (let [sessionId, player] of this.state.players) {
if (player.team == 0) {
team1.push(player);
} else {
team2.push(player);
}
}
return [new Wait().setPayload(time*1000) ,new NextTurnCommand()];
} }
} }

View File

@ -2,6 +2,7 @@ import { Command } from "@colyseus/command";
import { CardGameState } from "../schema/CardGameState"; import { CardGameState } from "../schema/CardGameState";
import {Client} from "colyseus"; import {Client} from "colyseus";
import {NextTurnCommand} from "./NextTurnCommand"; import {NextTurnCommand} from "./NextTurnCommand";
import {TurnEndCommand} from "./TurnEndCommand";
/** /**
* *
@ -31,7 +32,7 @@ export class SelectPetCommand extends Command<CardGameState, {client: Client,
break; break;
} }
} }
return [new NextTurnCommand()]; return [new TurnEndCommand()];
} }
} }

View File

@ -0,0 +1,34 @@
import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import {PartResultCommand} from "./PartResultCommand";
import {NextTurnCommand} from "./NextTurnCommand";
import {GameResultCommand} from "./GameResultCommand";
/**
*
*/
export class TurnEndCommand extends Command<CardGameState, {}> {
execute() {
// @ts-ignore
const sessionIds = [...this.state.players.keys()];
if (this.state.currentTurn
&& sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) {
// 每n轮结束的时候结算一次
const roundNum = singleton(GameEnv).duelRoundNum;
const totalRound = roundNum * singleton(GameEnv).maxDuelNum;
if (this.state.round % roundNum == (roundNum - 1)) {
if (this.state.round >= totalRound - 1) {
return [new GameResultCommand()];
} else {
return [new PartResultCommand()];
}
}
}
return [new NextTurnCommand()]
}
}

View File

@ -2,6 +2,6 @@ import { Command } from "@colyseus/command";
export class Wait extends Command<any, number> { export class Wait extends Command<any, number> {
async execute(number: number) { async execute(number: number) {
await this.delay(100); await this.delay(number);
} }
} }

View File

@ -161,7 +161,17 @@ let gameUtil = {
} }
return true; return true;
},
/**
* ap
* @param player
*/
calcTotalAp(player: Player) {
let result = player.ap;
for (let [pid, pet] of player.pets) {
result += pet.ap;
}
return result;
} }
} }