From 85998f3b355dbd3050a04abdf4012d545e01bc74 Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 14 Jan 2021 10:58:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=88=9B=E5=BB=BA=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E7=BB=9F=E4=B8=80=E5=88=B0webapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/WebApi.ts | 15 +++++++++++++++ src/rooms/GeneralRoom.ts | 35 ++--------------------------------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/common/WebApi.ts b/src/common/WebApi.ts index 1c95ffb..4ba8039 100644 --- a/src/common/WebApi.ts +++ b/src/common/WebApi.ts @@ -60,4 +60,19 @@ export function reportGameResult(data: any) { }); } +/** + * 创建机器人 + * @param data + */ +export function createRobot(data: any) { + axios.get('http://127.0.0.1:2500/robot/create', { + params: data + }).then((res) => { + debugRoom(res.status); + debugRoom(res.data); + }).catch((err) => { + error(err); + }) +} + diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index e2bbc79..a372818 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -22,6 +22,7 @@ import {RobotClient} from "../robot/RobotClient"; import axios from 'axios'; import {wait} from "../decorators/cfg"; import {ChangePetCommand} from "./commands/ChangePetCommand"; +import {createRobot} from "../common/WebApi"; export class GeneralRoom extends Room { dispatcher = new Dispatcher(this); @@ -245,39 +246,7 @@ export class GeneralRoom extends Room { room: this.roomId, sessionId: playerId } - - axios.get('http://127.0.0.1:2500/robot/create', { - params: data - }).then((res) => { - debugRoom(res.status); - debugRoom(res.data); - }).catch((err) => { - error(err); - }) - - // const sessionId = playerId || generateId(); - // let client = new RobotClient(sessionId, this.state, this.clock, this['onMessageHandlers']); - // if (this.reservedSeatTimeouts[sessionId]) { - // clearTimeout(this.reservedSeatTimeouts[sessionId]); - // delete this.reservedSeatTimeouts[sessionId]; - // } - // // get seat reservation options and clear it - // const options = this.reservedSeats[sessionId]; - // delete this.reservedSeats[sessionId]; - // this.clients.push(client); - // client.ref.once('close', this['_onLeave'].bind(this, client)); - // // client.ref.on('message', this.onMessage.bind(this, client)); - // const reconnection = this.reconnections[sessionId]; - // if (reconnection) { - // reconnection.resolve(client); - // } - // else { - // if (this.onJoin) { - // this.onJoin(client, options); - // } - // delete this.reservedSeats[sessionId]; - // } - // this._events.emit('join', client); + createRobot(data); } addAssistClient(sessionId: string) {