增加一些gm命令
This commit is contained in:
parent
dd14a4d184
commit
b0635d77a5
@ -22,6 +22,7 @@ initData();
|
|||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
const gameServer = new Server({
|
const gameServer = new Server({
|
||||||
server,
|
server,
|
||||||
|
// driver: new MongooseDriver('mongodb://127.0.0.1/card-development'),
|
||||||
driver: new MongooseDriver('mongodb://192.168.100.24/card-development'),
|
driver: new MongooseDriver('mongodb://192.168.100.24/card-development'),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import {Delayed} from "@gamestdio/timer/lib/Delayed";
|
|||||||
import {IncomingMessage} from "http";
|
import {IncomingMessage} from "http";
|
||||||
import {PlayerStateConst} from "../constants/PlayerStateConst";
|
import {PlayerStateConst} from "../constants/PlayerStateConst";
|
||||||
import {Player} from "./schema/Player";
|
import {Player} from "./schema/Player";
|
||||||
|
import {GMCommand} from "./commands/GMCommand";
|
||||||
|
|
||||||
|
|
||||||
export class GeneralRoom extends Room {
|
export class GeneralRoom extends Room {
|
||||||
@ -69,6 +70,11 @@ export class GeneralRoom extends Room {
|
|||||||
this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId});
|
this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.onMessage("gm", (client, message) => {
|
||||||
|
msgLog('gm command from ', client.sessionId, message);
|
||||||
|
this.dispatcher.dispatch(new GMCommand(), {client, message});
|
||||||
|
});
|
||||||
|
|
||||||
this.onMessage("*", (client, type, message) => {
|
this.onMessage("*", (client, type, message) => {
|
||||||
//
|
//
|
||||||
// Triggers when any other type of message is sent,
|
// Triggers when any other type of message is sent,
|
||||||
|
81
src/rooms/commands/GMCommand.ts
Normal file
81
src/rooms/commands/GMCommand.ts
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import {Command} from "@colyseus/command";
|
||||||
|
import {CardGameState} from "../schema/CardGameState";
|
||||||
|
import {Client} from "colyseus";
|
||||||
|
import {debugRoom, error} from "../../common/Debug";
|
||||||
|
|
||||||
|
|
||||||
|
export class GMCommand extends Command<CardGameState, {client: Client, message: string}> {
|
||||||
|
|
||||||
|
async execute({client, message} = this.payload) {
|
||||||
|
if (message.indexOf(':') < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let arr = message.split(':');
|
||||||
|
switch (arr[0]) {
|
||||||
|
case 'changeeffect':
|
||||||
|
debugRoom(`receive changeeffect command: ${arr[1]}`);
|
||||||
|
this.changePlayerCards(arr[1]);
|
||||||
|
break;
|
||||||
|
case 'changequeue':
|
||||||
|
this.changeCardQueue(arr[1]);
|
||||||
|
break;
|
||||||
|
case 'draw':
|
||||||
|
this.drawCard(arr[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
getPlayerByIdx(idx: number) {
|
||||||
|
let players = [...this.state.players.values()];
|
||||||
|
return players[idx];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 将一个玩家的手牌全变成指定的效果卡
|
||||||
|
* changeeffect:0|20011
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
changePlayerCards(msg: string) {
|
||||||
|
if (msg.indexOf('|') < 0) {
|
||||||
|
error(`错误的GM命令格式: ${msg}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let arr = msg.split('|');
|
||||||
|
let playerIdx = parseInt(arr[0]);
|
||||||
|
let effectId = parseInt(arr[1]);
|
||||||
|
let player = this.getPlayerByIdx(playerIdx);
|
||||||
|
for (let [, card] of player.cards) {
|
||||||
|
card.effect = effectId;
|
||||||
|
}
|
||||||
|
let client = this.room.getClient(player.id);
|
||||||
|
client.send('sync_card', {}, {afterNextPatch: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将牌组中的卡全部变成指定的效果卡
|
||||||
|
* changequeue:20011
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
changeCardQueue(msg: string) {
|
||||||
|
let effectId = parseInt(msg);
|
||||||
|
for (let card of this.state.cardQueue) {
|
||||||
|
card.effect = effectId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抽一定数量的卡
|
||||||
|
* draw:0|3
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
drawCard(msg: string) {
|
||||||
|
if (msg.indexOf('|') < 0) {
|
||||||
|
error(`错误的GM命令格式: ${msg}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let arr = msg.split('|');
|
||||||
|
let playerIdx = parseInt(arr[0]);
|
||||||
|
let player = this.getPlayerByIdx(playerIdx);
|
||||||
|
let count = parseInt(arr[1]);
|
||||||
|
this.room.addCard(player.id, count, 0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user