add skill handler( not finish)

This commit is contained in:
yuexin 2020-12-02 20:04:24 +08:00
parent ebe958fde1
commit 85c755577e
4 changed files with 17 additions and 9 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
/**