增加下发随从信息的消息
This commit is contained in:
parent
fc68018a32
commit
c9f9cb8dd4
@ -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}]
|
||||
|
@ -28,6 +28,8 @@ export class GameEnv {
|
||||
public roundExtTime: number;
|
||||
// 玩家随从上限
|
||||
public maxPlayerPetCount: number;
|
||||
// 结算显示时间
|
||||
public resultShowTime: number;
|
||||
|
||||
public init(data: Map<number, BaseCfg>) {
|
||||
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.roundExtTime = data.get(BaseConst.ROUND_EXT_TIME).value;
|
||||
this.maxPlayerPetCount = data.get(BaseConst.MAX_PLAYER_PET_COUNT).value;
|
||||
this.resultShowTime = data.get(BaseConst.ROUND_SHOW_TIME).value;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ export class BaseConst {
|
||||
public static readonly ROUND_EXT_TIME = 99012;
|
||||
// 玩家随从上限
|
||||
public static readonly MAX_PLAYER_PET_COUNT = 99013;
|
||||
// 结算时间
|
||||
public static readonly ROUND_SHOW_TIME = 99014;
|
||||
|
||||
|
||||
public static readonly COMPOUND = "compound";
|
||||
|
26
src/global.d.ts
vendored
26
src/global.d.ts
vendored
@ -1,3 +1,4 @@
|
||||
|
||||
export {};
|
||||
|
||||
declare global {
|
||||
@ -13,6 +14,7 @@ declare global {
|
||||
* GeneralRoom 扩展方法
|
||||
*/
|
||||
import {Client, Room} from "colyseus";
|
||||
import {PetInfoMsg} from "./message/PetInfo";
|
||||
declare module "colyseus" {
|
||||
interface Room {
|
||||
/**
|
||||
@ -27,13 +29,33 @@ declare module "colyseus" {
|
||||
* @param client
|
||||
* @param data
|
||||
*/
|
||||
sSelectHero(client: Client, data?: any);
|
||||
sSelectHero(client: Client, data?: any):void;
|
||||
|
||||
/**
|
||||
* 广播英雄选择结果
|
||||
* @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
7
src/message/IMsg.ts
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
export interface IMsg {
|
||||
errcode: number;
|
||||
errmsg?: string;
|
||||
data?: any
|
||||
}
|
25
src/message/PetInfo.ts
Normal file
25
src/message/PetInfo.ts
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ export class GeneralRoom extends Room {
|
||||
let cs = new CardGameState();
|
||||
this.setState(cs);
|
||||
this.battleMan.init(cs);
|
||||
this.clock.start();
|
||||
this.state.gameSate = 0;
|
||||
this.onMessage("play_ready_c2s", (client, message) => {
|
||||
console.log('play_ready from ', client.sessionId, message);
|
||||
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
Object.defineProperties(Room.prototype, {
|
||||
bUserJoin: {
|
||||
value: function (data?: any, options?: any) {
|
||||
this.broadcast("player_join", data, options);
|
||||
},
|
||||
writable: true
|
||||
},
|
||||
sSelectHero: {
|
||||
value: function (client: Client, data?: any) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ export class BeginGameCommand extends Command<CardGameState, {}> {
|
||||
for (let client of this.room.clients) {
|
||||
let player = this.state.players.get(client.sessionId);
|
||||
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;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ export class ChangeCardCommand extends Command<CardGameState, { client: Client,
|
||||
// 正式开始游戏, 第一个玩家出牌
|
||||
let curClient = this.room.clients[0];
|
||||
this.state.currentTurn = curClient.sessionId;
|
||||
this.state.subTurn = '';
|
||||
this.state.round = 0;
|
||||
let curPlayer = this.state.players.get(curClient.sessionId);
|
||||
let cards = gameUtil.drawCard(this.state.cardQueue, curPlayer, singleton(GameEnv).roundDrawNum);
|
||||
curClient.send('draw_card_s2c', cards);
|
||||
|
14
src/rooms/commands/GameResultCommand.ts
Normal file
14
src/rooms/commands/GameResultCommand.ts
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ import {Command} from "@colyseus/command";
|
||||
import {CardGameState} from "../schema/CardGameState";
|
||||
import {NextTurnCommand} from "./NextTurnCommand";
|
||||
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.room.broadcast('give_up_eat_s2c', {player: client.sessionId});
|
||||
if (this.state.giveUpCount >= this.room.maxClients - 1) {
|
||||
return [new NextTurnCommand()];
|
||||
return [new TurnEndCommand()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { Command } from "@colyseus/command";
|
||||
import { CardGameState } from "../schema/CardGameState";
|
||||
import {NextTurnCommand} from "./NextTurnCommand";
|
||||
import {GameStateConst} from "../../constants/GameStateConst";
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,9 @@ import {Command} from "@colyseus/command";
|
||||
import {CardGameState} from "../schema/CardGameState";
|
||||
import {DrawCommand} from "./DrawCommand";
|
||||
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() {
|
||||
this.state.gameState = GameStateConst.STATE_BEGIN_DRAW;
|
||||
this.state.subTurn = '';
|
||||
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)
|
||||
? sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length]
|
||||
: sessionIds[0];
|
||||
|
@ -2,6 +2,10 @@ import {Command} from "@colyseus/command";
|
||||
import {CardGameState} from "../schema/CardGameState";
|
||||
import {DrawCommand} from "./DrawCommand";
|
||||
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() {
|
||||
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()];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { Command } from "@colyseus/command";
|
||||
import { CardGameState } from "../schema/CardGameState";
|
||||
import {Client} from "colyseus";
|
||||
import {NextTurnCommand} from "./NextTurnCommand";
|
||||
import {TurnEndCommand} from "./TurnEndCommand";
|
||||
|
||||
/**
|
||||
* 选择随从或者法术
|
||||
@ -31,7 +32,7 @@ export class SelectPetCommand extends Command<CardGameState, {client: Client,
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [new NextTurnCommand()];
|
||||
return [new TurnEndCommand()];
|
||||
|
||||
}
|
||||
}
|
||||
|
34
src/rooms/commands/TurnEndCommand.ts
Normal file
34
src/rooms/commands/TurnEndCommand.ts
Normal 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()]
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,6 @@ import { Command } from "@colyseus/command";
|
||||
|
||||
export class Wait extends Command<any, number> {
|
||||
async execute(number: number) {
|
||||
await this.delay(100);
|
||||
await this.delay(number);
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,17 @@ let gameUtil = {
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
/**
|
||||
* 结算时计算总的ap
|
||||
* @param player
|
||||
*/
|
||||
calcTotalAp(player: Player) {
|
||||
let result = player.ap;
|
||||
for (let [pid, pet] of player.pets) {
|
||||
result += pet.ap;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user