import { CardTable } from "../Table/CardTable"; import { EErrorCode } from "../../Config/_error_"; import * as _ from "underscore"; import { ExtUserModel } from "../../../Common/Service/ExtUserService"; import { CardServer } from "../CardServer"; import { GLog } from "cgserver"; import { RoomRobotCfgModel, GRoomRobotCfgSer } from "../../../Common/Service/RoomRobotCfgService"; import { GCacheTool } from "cgserver"; import { RoomModel } from "../../../Common/Service/RoomService"; import { GClubSer } from "../../../Common/Service/ClubService"; import { PlayerInfo } from "../Table/CardSeat"; export class ExtRoomModel extends RoomModel { //是否需要解散 dismiss=false } export class AdminRoomModel extends ExtRoomModel { //总人数(包含虚拟人数) user_num=0 //用户数量(机器人+真实用户) realy_user_num=0 //真人数量 client_num=0 //机器人数量 robot_num=0 //牌桌数量 table_num=0 } export abstract class CardRoom { protected _server:CardServer=null get server() { return this._server } protected _roomCfg:ExtRoomModel=null get roomCfg() { return this._roomCfg } protected _tables=new Array() get tables() { return this._tables } protected _cfg_ctdm=null get cfgCtdm() { return this._cfg_ctdm } set cfgCtdm(value) { this._cfg_ctdm=value } async init(server:CardServer,roomCfg:RoomModel) { this._roomCfg = roomCfg this._server = server } async getRoomInfo() { let ri = _.clone(this._roomCfg) ri.user_num = 0 ri.realy_user_num = 0 let robotCfg:RoomRobotCfgModel = await GRoomRobotCfgSer.getByRoomId(ri._id) if(robotCfg) { let time = new Date() //随时间动态变化 ri.user_num = robotCfg.virtual_num+(time.getHours()+time.getMinutes()+time.getSeconds()%10-12) } for(let i=0;i() for(let i=0;i { return a.create_time-b.create_time }) let rstbs=[] for(let i=page*page_num;i<(page+1)*page_num;++i) { rstbs.push(tbs[i].adminInfo) } return rstbs } onTableDismiss(table_id) { for(let i=0;i0) { let uc = await GClubSer.getUserClub(user.id,this._roomCfg.club_id) if(uc.coin2) { if(table.robotNum>=table.ctdm.max_user-2) { continue } } } let id = table.id if(_.include(pre_tb_ids,id)) { continue } indexes.push(i) } if(indexes.length<=0) { tb=await this.createTable() if(this._roomCfg.club_id>0) { tb.club=await GClubSer.get(this._roomCfg.club_id) } this._tables.push(tb) pre_tb_ids.push(tb.id) } else { indexes.sort((ai,bi)=> { let tbA = this._tables[ai] let tbB = this._tables[bi] return tbB.user_num-tbA.user_num }) tb = this._tables[indexes[0]] pre_tb_ids.push(tb.id) } if(pre_tb_ids.length>3) { pre_tb_ids.shift() } //1天内,不能进入刚才得三张座子 GCacheTool.add(cacheKey,pre_tb_ids,1*24*60*60*1000) let playerinfo = new PlayerInfo(user) return tb.onEnter(playerinfo) } /** * 必须重新该函数 */ abstract createTable():Promise async onLeave(user_id) { let tb = this._server.tableMgr.getTableByUserId(user_id) if(!tb) { return } return tb.onLeave(user_id) } }