mm_os
Version:
MM_OS服务端架构,用于快速构建应用程序,支持网站建设、小程序后台、AI应用、物联网(IOT/AIOT)、游戏服务端等多种场景。
61 lines (52 loc) • 1.11 kB
JavaScript
const {
idGen
} = require('../../ulits/id_gen.js');
/**
* 房间类
*/
class Room {
static config = {
// 房间名称
'name': '',
// 房间口号
'slogan': '',
// 房主ID
'owner': '',
// 关联世界ID
'world_id': '',
// 房间主程序
'main': ''
};
/**
* 房间类构造函数
* @param {object} config 房间配置对象
*/
constructor(config) {
// 房间ID
this.id = this.genId();
// 玩家ID集合 - 使用Set保证唯一性和高效查找
this._player_ids = new Set();
// 状态 1:waiting等待中, 2:queue队列中, 3:doing进行中
this.state = 1;
// 匹配时间
this._match_time = null;
this.setConfig(config);
}
}
/**
* 设置房间配置
* @param {object} config 房间配置对象
*/
Room.prototype.setConfig = function (config) {
Object.assign(this.config, config);
};
/**
* 生成房间ID
* @returns {string} 房间ID
*/
Room.prototype.genId = function () {
return idGen.genId('room');
};
module.exports = {
Room
};