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) {