add skill handler( not finish)
This commit is contained in:
parent
ebe958fde1
commit
85c755577e
@ -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",
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<CardGameState, {
|
||||
client: Client
|
||||
client: Client, battle: BattleHandler
|
||||
}> {
|
||||
|
||||
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;
|
||||
|
@ -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;
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user