import * as _ from "underscore" import { CardRobot } from "./CardRobot"; import { CardServer } from "../CardServer"; import { CardRoom } from "../Room/CardRoom"; import { GRoomRobotCfgSer } from "../../../Common/Service/RoomRobotCfgService"; //单房间配置 export class RobotCfg { /** * 多少毫秒后开始启动自动机器人,小于0 表示不启用自动机器人 */ auto_pre_time=-1 /** * 每隔多少毫秒触发添加机器人需求 */ auto_dt_time=5000 /** * 最小机器人id号 */ min_robot_id=6141321 /** * 最大机器人id号 */ max_robot_id=6142319 } export class CardRobotManager { protected _robots=new Map() protected _cfg:RobotCfg=new RobotCfg() protected _server:CardServer=null get server() { return this._server } constructor(server:CardServer) { this._server = server if(this._cfg.auto_pre_time>0) { setTimeout(()=> { setInterval(()=> { this._update() },this._cfg.auto_dt_time) },this._cfg.auto_pre_time) } } protected _update() { let rooms = this._server.roomMgr.rooms for(let room_id in rooms) { let room:CardRoom = rooms[room_id] let add=false GRoomRobotCfgSer.getByRoomId(room_id).then((cfg)=> { let run = room.realyUserNum if(cfg.min_num>run) { let r=_.random(0,100) if(r<50) { add = true } } else if(cfg.max_num-run>0) { let dt = cfg.max_num-run let r = _.random(0,cfg.max_num) if(r