From 85c755577e7dfca45a4bee4d75c3861f1f20f19f Mon Sep 17 00:00:00 2001 From: yuexin Date: Wed, 2 Dec 2020 20:04:24 +0800 Subject: [PATCH] add skill handler( not finish) --- package.json | 2 +- src/rooms/GeneralRoom.ts | 9 +++++++-- src/rooms/commands/OnJoinCommand.ts | 9 ++++++--- src/rooms/schema/Card.ts | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 1c2158c..3ccb42d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "card_svr", "version": "1.0.0", "main": "lib/index.js", - "typings" : "src/global.d.ts", + "typings": "src/global.d.ts", "scripts": { "start": "ts-node-dev --files src/index.ts", "loadtest": "colyseus-loadtest loadtest/example.ts --room my_room --numClients 3", diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 76d0ea8..ee9b30e 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -10,14 +10,18 @@ import {ChangeCardCommand} from "./commands/ChangeCardCommand"; import {SelectHeroCommand} from "./commands/SelectHeroCommand"; import {EatCardCommand} from "./commands/EatCardCommand"; import {GiveUpCommand} from "./commands/GiveUpCommand"; +import {BattleHandler} from "./logic/Handler/BattleHandler"; export class GeneralRoom extends Room { dispatcher = new Dispatcher(this); maxClients = 4; clientMap = new Map(); + battleMan = new BattleHandler(); onCreate (options: any) { - this.setState(new CardGameState()); + let cs = new CardGameState(); + this.setState(cs); + this.battleMan.init(cs); this.state.gameSate = 0; this.onMessage("play_ready_c2s", (client, message) => { console.log('play_ready from ', client.sessionId, message); @@ -63,7 +67,8 @@ export class GeneralRoom extends Room { onJoin (client: Client, options: any) { this.dispatcher.dispatch(new OnJoinCommand(), { - client: client + client: client, + battle: this.battleMan, }); this.clientMap.set(client.sessionId, client); } diff --git a/src/rooms/commands/OnJoinCommand.ts b/src/rooms/commands/OnJoinCommand.ts index a841d0e..edbc869 100644 --- a/src/rooms/commands/OnJoinCommand.ts +++ b/src/rooms/commands/OnJoinCommand.ts @@ -2,17 +2,20 @@ import {Command} from "@colyseus/command"; import {CardGameState} from "../schema/CardGameState"; import {Player} from "../schema/Player"; import {Client} from "colyseus"; +import { BattleHandler } from "rooms/logic/Handler/BattleHandler"; /** * 玩家成功加入房间 */ export class OnJoinCommand extends Command { - execute({client}: { client: Client }) { + execute({client, battle}: { client: Client, battle: BattleHandler }) { let team = this.state.players.size / 2 | 0; - this.state.players.set(client.sessionId, new Player(0, team)); + 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 = 1; diff --git a/src/rooms/schema/Card.ts b/src/rooms/schema/Card.ts index 6bbb002..36e4370 100644 --- a/src/rooms/schema/Card.ts +++ b/src/rooms/schema/Card.ts @@ -2,7 +2,7 @@ import {Schema, type, filter} from "@colyseus/schema"; export class Card extends Schema { - constructor(number: number, type: string, id: string) { + constructor(number: number, type: string, id: number) { super(); this.number = number; this.type = type; @@ -25,8 +25,8 @@ export class Card extends Schema { number: number; @type("string") owner: string; - @type("string") - id: string; + @type("number") + id: number; @type("boolean") played: boolean = false; /**