修改掉线逻辑,增加赢牌的gm命令
This commit is contained in:
parent
204f4fec3e
commit
4f06b539e7
@ -100,22 +100,22 @@ export class GeneralRoom extends Room {
|
|||||||
}
|
}
|
||||||
//TODO: 掉线逻辑
|
//TODO: 掉线逻辑
|
||||||
async onLeave (client: Client, consented: boolean) {
|
async onLeave (client: Client, consented: boolean) {
|
||||||
// this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_OFFLINE;
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// if (consented) {
|
|
||||||
// throw new Error("consented leave");
|
|
||||||
// }
|
|
||||||
// await this.allowReconnection(client, 60);
|
|
||||||
// this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_NORMAL;
|
|
||||||
//
|
|
||||||
// } catch (e) {
|
|
||||||
// this.state.players.delete(client.sessionId);
|
|
||||||
// }
|
|
||||||
//TODO: 检查重新开始后, gameState
|
|
||||||
if (this.state.gameState === GameStateConst.STATE_GAME_OVER) {
|
if (this.state.gameState === GameStateConst.STATE_GAME_OVER) {
|
||||||
this.state.players.delete(client.id);
|
this.state.players.delete(client.sessionId);
|
||||||
this.bUserLeft(client.id);
|
this.bUserLeft(client.sessionId);
|
||||||
|
} else {
|
||||||
|
this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_OFFLINE;
|
||||||
|
try {
|
||||||
|
if (consented) {
|
||||||
|
throw new Error("consented leave");
|
||||||
|
}
|
||||||
|
await this.allowReconnection(client, 60);
|
||||||
|
this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_NORMAL;
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
debugRoom(`player realy level :${client.sessionId}`);
|
||||||
|
this.state.players.delete(client.sessionId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,8 +209,8 @@ export class GeneralRoom extends Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addRobot() {
|
addRobot(playerId?: string) {
|
||||||
const sessionId = generateId();
|
const sessionId = playerId || generateId();
|
||||||
let client = new RobotClient(sessionId, this.state, this.clock, this['onMessageHandlers']);
|
let client = new RobotClient(sessionId, this.state, this.clock, this['onMessageHandlers']);
|
||||||
if (this.reservedSeatTimeouts[sessionId]) {
|
if (this.reservedSeatTimeouts[sessionId]) {
|
||||||
clearTimeout(this.reservedSeatTimeouts[sessionId]);
|
clearTimeout(this.reservedSeatTimeouts[sessionId]);
|
||||||
|
@ -2,6 +2,7 @@ import {Command} from "@colyseus/command";
|
|||||||
import {CardGameState} from "../schema/CardGameState";
|
import {CardGameState} from "../schema/CardGameState";
|
||||||
import {Client} from "colyseus";
|
import {Client} from "colyseus";
|
||||||
import {debugRoom, error} from "../../common/Debug";
|
import {debugRoom, error} from "../../common/Debug";
|
||||||
|
import {GameResultCommand} from "./GameResultCommand";
|
||||||
|
|
||||||
|
|
||||||
export class GMCommand extends Command<CardGameState, {client: Client, message: string}> {
|
export class GMCommand extends Command<CardGameState, {client: Client, message: string}> {
|
||||||
@ -28,6 +29,9 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
case 'addcard':
|
case 'addcard':
|
||||||
this.addCard(arr[1]);
|
this.addCard(arr[1]);
|
||||||
break;
|
break;
|
||||||
|
case 'setwin':
|
||||||
|
this.setWin(arr[1]);
|
||||||
|
break;
|
||||||
case 'help':
|
case 'help':
|
||||||
this.sendHelp(client, arr[1]);
|
this.sendHelp(client, arr[1]);
|
||||||
break;
|
break;
|
||||||
@ -45,6 +49,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
str += '抽一定数量的卡, 注意类型和效果id的搭配: draw:玩家index|数量|类型|效果id|点数 例: draw:0|3 or draw:0|1|1|20011|2 \n';
|
str += '抽一定数量的卡, 注意类型和效果id的搭配: draw:玩家index|数量|类型|效果id|点数 例: draw:0|3 or draw:0|1|1|20011|2 \n';
|
||||||
str += '更新英雄血量: herohp:玩家index|血量 例: herohp:0|500 \n';
|
str += '更新英雄血量: herohp:玩家index|血量 例: herohp:0|500 \n';
|
||||||
str += '生成几张特定效果的卡: addcard:玩家index|效果卡id|数量 例: addcard:0|20011|1\n';
|
str += '生成几张特定效果的卡: addcard:玩家index|效果卡id|数量 例: addcard:0|20011|1\n';
|
||||||
|
str += '将某一队设为赢家: setwin:队伍index 例: setwin:0\n';
|
||||||
client && client.send('notice_msg', str);
|
client && client.send('notice_msg', str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,4 +157,13 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
let count = parseInt(arr[1]);
|
let count = parseInt(arr[1]);
|
||||||
this.room.updateHp(player.id, count);
|
this.room.updateHp(player.id, count);
|
||||||
}
|
}
|
||||||
|
setWin(msg: string) {
|
||||||
|
let teamId = parseInt(msg);
|
||||||
|
for (let [,player] of this.state.players) {
|
||||||
|
if (player.team != teamId) {
|
||||||
|
player.hp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.room.dispatcher.dispatch(new GameResultCommand());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
|||||||
|
|
||||||
this.room.bGameResult(resultData);
|
this.room.bGameResult(resultData);
|
||||||
this.state.updateGameState(GameStateConst.STATE_GAME_OVER);
|
this.state.updateGameState(GameStateConst.STATE_GAME_OVER);
|
||||||
this.resetAllState();
|
|
||||||
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
||||||
let self = this;
|
let self = this;
|
||||||
let resultTimeOver = async function () {
|
let resultTimeOver = async function () {
|
||||||
@ -96,6 +95,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
|||||||
}
|
}
|
||||||
let time = singleton(GameEnv).gameResultTime * 1000;
|
let time = singleton(GameEnv).gameResultTime * 1000;
|
||||||
this.room.beginSchedule(time, resultTimeOver, 'restart_schedule');
|
this.room.beginSchedule(time, resultTimeOver, 'restart_schedule');
|
||||||
|
this.resetAllState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user