add skill handler( not finish)
This commit is contained in:
parent
ebe958fde1
commit
85c755577e
@ -3,7 +3,7 @@
|
|||||||
"name": "card_svr",
|
"name": "card_svr",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"typings" : "src/global.d.ts",
|
"typings": "src/global.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "ts-node-dev --files src/index.ts",
|
"start": "ts-node-dev --files src/index.ts",
|
||||||
"loadtest": "colyseus-loadtest loadtest/example.ts --room my_room --numClients 3",
|
"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 {SelectHeroCommand} from "./commands/SelectHeroCommand";
|
||||||
import {EatCardCommand} from "./commands/EatCardCommand";
|
import {EatCardCommand} from "./commands/EatCardCommand";
|
||||||
import {GiveUpCommand} from "./commands/GiveUpCommand";
|
import {GiveUpCommand} from "./commands/GiveUpCommand";
|
||||||
|
import {BattleHandler} from "./logic/Handler/BattleHandler";
|
||||||
|
|
||||||
export class GeneralRoom extends Room {
|
export class GeneralRoom extends Room {
|
||||||
dispatcher = new Dispatcher(this);
|
dispatcher = new Dispatcher(this);
|
||||||
maxClients = 4;
|
maxClients = 4;
|
||||||
clientMap = new Map();
|
clientMap = new Map();
|
||||||
|
battleMan = new BattleHandler();
|
||||||
|
|
||||||
onCreate (options: any) {
|
onCreate (options: any) {
|
||||||
this.setState(new CardGameState());
|
let cs = new CardGameState();
|
||||||
|
this.setState(cs);
|
||||||
|
this.battleMan.init(cs);
|
||||||
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);
|
||||||
@ -63,7 +67,8 @@ export class GeneralRoom extends Room {
|
|||||||
|
|
||||||
onJoin (client: Client, options: any) {
|
onJoin (client: Client, options: any) {
|
||||||
this.dispatcher.dispatch(new OnJoinCommand(), {
|
this.dispatcher.dispatch(new OnJoinCommand(), {
|
||||||
client: client
|
client: client,
|
||||||
|
battle: this.battleMan,
|
||||||
});
|
});
|
||||||
this.clientMap.set(client.sessionId, client);
|
this.clientMap.set(client.sessionId, client);
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,20 @@ import {Command} from "@colyseus/command";
|
|||||||
import {CardGameState} from "../schema/CardGameState";
|
import {CardGameState} from "../schema/CardGameState";
|
||||||
import {Player} from "../schema/Player";
|
import {Player} from "../schema/Player";
|
||||||
import {Client} from "colyseus";
|
import {Client} from "colyseus";
|
||||||
|
import { BattleHandler } from "rooms/logic/Handler/BattleHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 玩家成功加入房间
|
* 玩家成功加入房间
|
||||||
*/
|
*/
|
||||||
export class OnJoinCommand extends Command<CardGameState, {
|
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;
|
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) {
|
if (this.state.players.size >= this.room.maxClients) {
|
||||||
this.room.lock();
|
this.room.lock();
|
||||||
this.state.gameState = 1;
|
this.state.gameState = 1;
|
||||||
|
@ -2,7 +2,7 @@ import {Schema, type, filter} from "@colyseus/schema";
|
|||||||
|
|
||||||
export class Card extends Schema {
|
export class Card extends Schema {
|
||||||
|
|
||||||
constructor(number: number, type: string, id: string) {
|
constructor(number: number, type: string, id: number) {
|
||||||
super();
|
super();
|
||||||
this.number = number;
|
this.number = number;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -25,8 +25,8 @@ export class Card extends Schema {
|
|||||||
number: number;
|
number: number;
|
||||||
@type("string")
|
@type("string")
|
||||||
owner: string;
|
owner: string;
|
||||||
@type("string")
|
@type("number")
|
||||||
id: string;
|
id: number;
|
||||||
@type("boolean")
|
@type("boolean")
|
||||||
played: boolean = false;
|
played: boolean = false;
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user