mm_os 4.3.6 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -504
- package/index.js +26 -19
- package/lib/loader.js +787 -0
- package/lib/os.js +369 -0
- package/package.json +55 -80
- package/LICENSE +0 -21
- package/README_EN.md +0 -505
- package/adapter/adapter.js +0 -484
- package/adapter/custom_persistence.js +0 -661
- package/adapter/mqtt.js +0 -254
- package/adapter/socket.js +0 -244
- package/adapter/web.js +0 -92
- package/adapter/websocket.js +0 -43
- package/ai.js +0 -130
- package/com/api/README.md +0 -3
- package/com/api/com.json +0 -5
- package/com/api/config.tpl.json +0 -41
- package/com/api/drive.js +0 -732
- package/com/api/index.js +0 -201
- package/com/api/oauth.js +0 -200
- package/com/api/script.tpl.js +0 -32
- package/com/cmd/README.md +0 -11
- package/com/cmd/com.json +0 -5
- package/com/cmd/config.tpl.json +0 -48
- package/com/cmd/drive.js +0 -176
- package/com/cmd/index.js +0 -287
- package/com/cmd/job/config.json +0 -66
- package/com/cmd/job/index.js +0 -241
- package/com/cmd/job/test.js +0 -188
- package/com/cmd/msg.json +0 -48
- package/com/cmd/script.tpl.js +0 -12
- package/com/db/README.md +0 -3
- package/com/db/com.json +0 -5
- package/com/db/drive.js +0 -2206
- package/com/db/index.js +0 -241
- package/com/event/README.md +0 -4
- package/com/event/com.json +0 -5
- package/com/event/config.tpl.json +0 -20
- package/com/event/drive.js +0 -61
- package/com/event/index.js +0 -438
- package/com/event/script.tpl.js +0 -23
- package/com/mqtt/README.md +0 -47
- package/com/mqtt/com.json +0 -5
- package/com/mqtt/config.tpl.json +0 -42
- package/com/mqtt/drive.js +0 -696
- package/com/mqtt/index.js +0 -1017
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/mm_mqtt.js +0 -446
- package/com/mqtt/script.tpl.js +0 -719
- package/com/nav/README.md +0 -2
- package/com/nav/com.json +0 -5
- package/com/nav/config.tpl.json +0 -84
- package/com/nav/drive.js +0 -702
- package/com/nav/index.js +0 -228
- package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
- package/com/nav/tpl/admin_pc/page_config.vue +0 -280
- package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
- package/com/nav/tpl/admin_pc/page_default.vue +0 -247
- package/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
- package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
- package/com/nav/tpl/admin_pc/page_table.vue +0 -296
- package/com/nav/tpl/admin_pc/page_type.vue +0 -321
- package/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
- package/com/nav/tpl/dev_pc/page_config.vue +0 -253
- package/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/com/nav/tpl/dev_pc/page_form.vue +0 -162
- package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
- package/com/nav/tpl/dev_pc/page_table.vue +0 -247
- package/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/com/nav/tpl/home_pc/page_channel.vue +0 -234
- package/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/com/nav/tpl/home_phone/page_list.vue +0 -234
- package/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/com/nav/viewmodel.js +0 -446
- package/com/param/README.md +0 -2
- package/com/param/com.json +0 -5
- package/com/param/config.tpl.json +0 -136
- package/com/param/drive.js +0 -502
- package/com/param/index.js +0 -158
- package/com/param/script.tpl.js +0 -12
- package/com/pendant/README.md +0 -3
- package/com/pendant/com.json +0 -5
- package/com/pendant/config.tpl.json +0 -32
- package/com/pendant/drive.js +0 -204
- package/com/pendant/index.js +0 -467
- package/com/pendant/pendant.html +0 -16
- package/com/pendant/script.tpl.js +0 -18
- package/com/socket/README.md +0 -47
- package/com/socket/com.json +0 -5
- package/com/socket/config.tpl.json +0 -12
- package/com/socket/drive.js +0 -679
- package/com/socket/index.js +0 -402
- package/com/socket/script.tpl.js +0 -41
- package/com/sql/README.md +0 -3
- package/com/sql/com.json +0 -5
- package/com/sql/config.tpl.json +0 -74
- package/com/sql/drive.js +0 -1283
- package/com/sql/index.js +0 -152
- package/com/sql/script.tpl.js +0 -47
- package/com/static/README.md +0 -2
- package/com/static/com.json +0 -5
- package/com/static/config.tpl.json +0 -24
- package/com/static/drive.js +0 -194
- package/com/static/index.js +0 -237
- package/com/static/script.tpl.js +0 -28
- package/com/task/README.md +0 -3
- package/com/task/com.json +0 -5
- package/com/task/config.tpl.json +0 -24
- package/com/task/drive.js +0 -428
- package/com/task/index.js +0 -159
- package/com/task/script.tpl.js +0 -40
- package/com/template/com.json +0 -5
- package/com/template/config.tpl.json +0 -16
- package/com/template/drive.js +0 -81
- package/com/template/index.js +0 -141
- package/com.js +0 -237
- package/common/README.md +0 -2
- package/common/middleware/web_after/index.js +0 -26
- package/common/middleware/web_after/middleware.json +0 -9
- package/common/middleware/web_base/index.js +0 -113
- package/common/middleware/web_base/middleware.json +0 -19
- package/common/middleware/web_before/index.js +0 -33
- package/common/middleware/web_before/middleware.json +0 -9
- package/common/middleware/web_cors/index.js +0 -87
- package/common/middleware/web_cors/middleware.json +0 -24
- package/common/middleware/web_error/index.js +0 -131
- package/common/middleware/web_error/middleware.json +0 -19
- package/common/middleware/web_ip/index.js +0 -15
- package/common/middleware/web_ip/middleware.json +0 -14
- package/common/middleware/web_logger/index.js +0 -156
- package/common/middleware/web_logger/middleware.json +0 -14
- package/common/middleware/web_main/index.js +0 -26
- package/common/middleware/web_main/middleware.json +0 -9
- package/common/middleware/web_static/index.js +0 -73
- package/common/middleware/web_static/middleware.json +0 -54
- package/common/middleware/web_waf/index.js +0 -385
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -710
- package/core/app/script.tpl.js +0 -52
- package/core/channel/index.js +0 -899
- package/core/channel/matcher.js +0 -585
- package/core/com/config.tpl.json +0 -16
- package/core/com/index.js +0 -77
- package/core/com/script.tpl.js +0 -5
- package/core/component/component.js +0 -42
- package/core/component/config.tpl.json +0 -63
- package/core/component/index.js +0 -273
- package/core/component/script.tpl.js +0 -19
- package/core/controller/config.tpl.json +0 -14
- package/core/controller/index.js +0 -371
- package/core/controller/script.tpl.js +0 -27
- package/core/factory/config.tpl.json +0 -14
- package/core/factory/entity.js +0 -275
- package/core/factory/index.js +0 -241
- package/core/factory/script.tpl.js +0 -16
- package/core/game/bat/index.js +0 -137
- package/core/game/bat/world.js +0 -622
- package/core/game/config.tpl.json +0 -16
- package/core/game/entity_admin.js +0 -230
- package/core/game/index.js +0 -186
- package/core/handler/config.tpl.json +0 -22
- package/core/handler/index.js +0 -181
- package/core/handler/script.tpl.js +0 -23
- package/core/logic/config.tpl.json +0 -14
- package/core/logic/index.js +0 -59
- package/core/logic/script.tpl.js +0 -19
- package/core/middleware/config.tpl.json +0 -16
- package/core/middleware/index.js +0 -117
- package/core/middleware/script.tpl.js +0 -37
- package/core/mod/config.tpl.json +0 -22
- package/core/mod/index.js +0 -136
- package/core/mod/script.tpl.js +0 -34
- package/core/model/config.tpl.json +0 -219
- package/core/model/index.js +0 -272
- package/core/model/model.js +0 -27
- package/core/model/script.tpl.js +0 -20
- package/core/notifier/config.tpl.json +0 -14
- package/core/notifier/index.js +0 -77
- package/core/notifier/script.tpl.js +0 -20
- package/core/plugin/config.tpl.json +0 -36
- package/core/plugin/index.js +0 -297
- package/core/plugin/script.tpl.js +0 -51
- package/core/pusher/config.tpl.json +0 -14
- package/core/pusher/index.js +0 -158
- package/core/pusher/script.tpl.js +0 -20
- package/core/room/bat/index.js +0 -170
- package/core/room/bat/room.js +0 -524
- package/core/room/config.tpl.json +0 -20
- package/core/room/index.js +0 -249
- package/core/room/room.js +0 -61
- package/core/scene/config.tpl.json +0 -14
- package/core/scene/index.js +0 -467
- package/core/scene/loop.js +0 -1306
- package/core/scene/map.js +0 -28
- package/core/scene/script.tpl.js +0 -22
- package/core/sender/config.tpl.json +0 -14
- package/core/sender/index.js +0 -79
- package/core/sender/script.tpl.js +0 -20
- package/core/service/config.tpl.json +0 -14
- package/core/service/index.js +0 -100
- package/core/service/script.tpl.js +0 -25
- package/core/store/config.tpl.json +0 -26
- package/core/store/index.js +0 -1794
- package/core/store/script.tpl.js +0 -22
- package/core/store/sql.js +0 -1488
- package/core/system/config.tpl.json +0 -18
- package/core/system/index.js +0 -312
- package/core/system/script.tpl.js +0 -77
- package/core/view/config.tpl.json +0 -14
- package/core/view/index.js +0 -91
- package/core/view/script.tpl.js +0 -20
- package/core/zone/bat/index.js +0 -744
- package/core/zone/config.tpl.json +0 -54
- package/core/zone/index.js +0 -655
- package/core/zone/script.tpl.js +0 -10
- package/core/zone/zone_bat.js +0 -136
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
- package/os.js +0 -53
- package/server.js +0 -595
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
package/core/factory/index.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
const { Drive } = require('mm_machine');
|
|
2
|
-
const { Entity } = require('./entity.js');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 实体管理器类
|
|
6
|
-
* 负责实体的创建、查询、更新和删除操作
|
|
7
|
-
* 管理实体与组件的关联关系
|
|
8
|
-
*/
|
|
9
|
-
class Factory extends Drive {
|
|
10
|
-
static config = {
|
|
11
|
-
'name': 'default',
|
|
12
|
-
'title': '工厂',
|
|
13
|
-
'description': '数据模型工厂类,负责创建和管理数据模型实例',
|
|
14
|
-
'main': '',
|
|
15
|
-
'components': []
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 构造函数
|
|
20
|
-
* @param {object} config 配置参数
|
|
21
|
-
*/
|
|
22
|
-
constructor(config) {
|
|
23
|
-
super({ ...Factory.config, ...config || {} });
|
|
24
|
-
// 组件注册表
|
|
25
|
-
this._component = {};
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 获取模板目录
|
|
31
|
-
* @returns {string} 模板目录
|
|
32
|
-
*/
|
|
33
|
-
Factory.prototype.getTplDir = function () {
|
|
34
|
-
return __dirname;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 初始化核心
|
|
39
|
-
* @param {object} component 组件注册表
|
|
40
|
-
* @param {object} eventer 事件管理器
|
|
41
|
-
* @param {object} logger 日志管理器
|
|
42
|
-
*/
|
|
43
|
-
Factory.prototype._initCore = async function (component, eventer, logger) {
|
|
44
|
-
// 初始化依赖项
|
|
45
|
-
if (logger) {
|
|
46
|
-
this.setLogger(logger);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (eventer) {
|
|
50
|
-
this.getEventer = function () {
|
|
51
|
-
return eventer;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (component) {
|
|
56
|
-
this._component = component;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
this._checkDeps();
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 检查依赖项
|
|
64
|
-
*/
|
|
65
|
-
Factory.prototype._checkDeps = function () {
|
|
66
|
-
let { components } = this.config;
|
|
67
|
-
components = components || [];
|
|
68
|
-
for (let i = 0; i < components.length; i++) {
|
|
69
|
-
let name = components[i];
|
|
70
|
-
if (!this._component[name]) {
|
|
71
|
-
this.log('error', `组件 ${name} 不存在`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 注册组件类型
|
|
78
|
-
* @param {string} name 组件类型
|
|
79
|
-
* @param {object} component 组件类
|
|
80
|
-
*/
|
|
81
|
-
Factory.prototype.registerComponent = function (name, component) {
|
|
82
|
-
// 参数校验
|
|
83
|
-
if (typeof name !== 'string') {
|
|
84
|
-
throw new TypeError('组件类型必须是字符串');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (typeof component !== 'object') {
|
|
88
|
-
throw new TypeError('组件类必须是对象');
|
|
89
|
-
}
|
|
90
|
-
this._component[name] = component;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 注销组件类型
|
|
95
|
-
* @param {string} name 组件类型
|
|
96
|
-
* @returns {boolean} 是否注销成功
|
|
97
|
-
*/
|
|
98
|
-
Factory.prototype.unregisterComponent = function (name) {
|
|
99
|
-
// 参数校验
|
|
100
|
-
if (typeof name !== 'string') {
|
|
101
|
-
throw new TypeError('组件类型必须是字符串');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
delete this._component[name];
|
|
105
|
-
return true;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 创建实体
|
|
110
|
-
* @param {object} model 实体模型
|
|
111
|
-
* @param {string} model.entity_id 实体ID - 可选,默认自动生成
|
|
112
|
-
* @param {string} model.player_id 玩家ID - 可选,默认空字符串
|
|
113
|
-
* @param {string} model.type 实体类型 - 可选,默认空字符串
|
|
114
|
-
* @returns {object} 实体对象
|
|
115
|
-
*/
|
|
116
|
-
Factory.prototype.createEntity = function (model = {}) {
|
|
117
|
-
let entity = new Entity(model.entity_id, model.player_id, model.type);
|
|
118
|
-
let { components } = this.config;
|
|
119
|
-
for (let i = 0; i < components.length; i++) {
|
|
120
|
-
let name = components[i];
|
|
121
|
-
if (this._component[name]) {
|
|
122
|
-
entity.addComponent(name, this._component[name].create(model[name]));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// 触发实体创建事件
|
|
126
|
-
this.emitEvent('factory_entity_create', {
|
|
127
|
-
factory_name: this.config.name,
|
|
128
|
-
entity_id: entity.entity_id,
|
|
129
|
-
entity_type: entity.type,
|
|
130
|
-
timestamp: Date.now()
|
|
131
|
-
});
|
|
132
|
-
return entity;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 设置实体模型
|
|
137
|
-
* @param {Entity} entity 实体对象
|
|
138
|
-
* @param {object} model 实体模型
|
|
139
|
-
*/
|
|
140
|
-
Factory.prototype.setModel = function (entity, model) {
|
|
141
|
-
// 初始化实体
|
|
142
|
-
entity.setModel(model);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* 为实体添加组件
|
|
147
|
-
* @param {Entity} entity 实体对象
|
|
148
|
-
* @param {string} name 组件类型
|
|
149
|
-
* @param {object} component_data 组件数据
|
|
150
|
-
* @returns {boolean} 是否添加成功
|
|
151
|
-
*/
|
|
152
|
-
Factory.prototype.addComponent = function (entity, name, component_data) {
|
|
153
|
-
// 参数校验
|
|
154
|
-
if (typeof entity !== 'object' || !entity.isActive()) {
|
|
155
|
-
throw new TypeError('实体必须是有效实体对象');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (typeof name !== 'string') {
|
|
159
|
-
throw new TypeError('组件类型必须是字符串');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (typeof component_data !== 'object' || Array.isArray(component_data)) {
|
|
163
|
-
throw new TypeError('组件数据必须是对象');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
let result = entity.addComponent(name, component_data);
|
|
167
|
-
// 触发组件添加事件
|
|
168
|
-
this.emitEvent('factory_component_add', {
|
|
169
|
-
factory_name: this.config.name,
|
|
170
|
-
entity_id: entity.entity_id,
|
|
171
|
-
component: name,
|
|
172
|
-
timestamp: Date.now()
|
|
173
|
-
});
|
|
174
|
-
return result;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* 从实体移除组件
|
|
179
|
-
* @param {Entity} entity 实体对象
|
|
180
|
-
* @param {string} name 组件类型
|
|
181
|
-
* @returns {boolean} 是否移除成功
|
|
182
|
-
*/
|
|
183
|
-
Factory.prototype.delComponent = function (entity, name) {
|
|
184
|
-
// 参数校验
|
|
185
|
-
if (typeof entity !== 'object' || !entity.isActive()) {
|
|
186
|
-
throw new TypeError('实体必须是有效实体对象');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (typeof name !== 'string') {
|
|
190
|
-
throw new TypeError('组件类型必须是字符串');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
let result = entity.delComponent(name);
|
|
194
|
-
// 触发组件移除事件
|
|
195
|
-
this.emitEvent('factory_component_del', {
|
|
196
|
-
factory_name: this.config.name,
|
|
197
|
-
entity_id: entity.entity_id,
|
|
198
|
-
component: name,
|
|
199
|
-
timestamp: Date.now()
|
|
200
|
-
});
|
|
201
|
-
return result;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* 创建模型
|
|
206
|
-
* @param {object} data 模型数据
|
|
207
|
-
* @returns {object} 模型对象
|
|
208
|
-
*/
|
|
209
|
-
Factory.prototype.createModel = function (data) {
|
|
210
|
-
if (typeof data !== 'object' || Array.isArray(data)) {
|
|
211
|
-
throw new TypeError('模型数据必须是对象');
|
|
212
|
-
}
|
|
213
|
-
let entity = new Entity(model.entity_id, model.player_id);
|
|
214
|
-
// let { components } = this.config;
|
|
215
|
-
return entity;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* 创建实体
|
|
220
|
-
* @param {object} data 实体数据
|
|
221
|
-
* @returns {object} 实体对象
|
|
222
|
-
*/
|
|
223
|
-
Factory.prototype.create = function (data) {
|
|
224
|
-
if (typeof data !== 'object') {
|
|
225
|
-
throw new TypeError('实体数据必须是对象');
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
let entity = this.createEntity(data);
|
|
229
|
-
this.addMethod(entity);
|
|
230
|
-
return entity;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* 为实体添加方法
|
|
235
|
-
* @param {Entity} entity 实体对象
|
|
236
|
-
*/
|
|
237
|
-
Factory.prototype.addMethod = function (entity) {
|
|
238
|
-
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
exports.Factory = Factory;
|
package/core/game/bat/index.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
const { Drive } = require('mm_machine');
|
|
2
|
-
const { GameWorld } = require('./world.js');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 游戏
|
|
6
|
-
*/
|
|
7
|
-
class Game extends Drive {
|
|
8
|
-
static config = {
|
|
9
|
-
name: 'default',
|
|
10
|
-
// 世界类型 可选值:角色扮演RPG、动作游戏ACT、冒险游戏AVG、AAG、SLG、SRPG、RTS、FTG、STG、FPS、TPS、PZL、SPG、RCG(RAC)、CAG、TAB、MSC、WAG、MUD、MOBA
|
|
11
|
-
type: 'RPG',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 构造函数
|
|
16
|
-
* @param {object} config 配置参数
|
|
17
|
-
* @param {object} parent 父对象
|
|
18
|
-
*/
|
|
19
|
-
constructor(config, parent) {
|
|
20
|
-
super({ ...Game.config, ...config || {} }, parent);
|
|
21
|
-
// // 世界列表
|
|
22
|
-
// this._worlds = new Map();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 初始化游戏
|
|
28
|
-
* @param {object} server 游戏服务器
|
|
29
|
-
* @param {object} eventer 事件管理器
|
|
30
|
-
* @param {object} logger 日志管理器
|
|
31
|
-
*/
|
|
32
|
-
Game.prototype._initCore = async function (server, eventer, logger) {
|
|
33
|
-
if (logger) {
|
|
34
|
-
this.setLogger(logger);
|
|
35
|
-
}
|
|
36
|
-
if (eventer) {
|
|
37
|
-
this.getEventer = function () {
|
|
38
|
-
return eventer;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
if (!server) {
|
|
42
|
-
throw new TypeError('游戏服务器不能为空');
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.getServer = function () {
|
|
46
|
-
return server;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 创建世界
|
|
53
|
-
* @param {object} config 世界配置
|
|
54
|
-
* @param {string} world_id 世界ID
|
|
55
|
-
* @returns {object} 创建的世界对象
|
|
56
|
-
*/
|
|
57
|
-
Game.prototype.createWorld = async function (config, world_id) {
|
|
58
|
-
// 参数校验
|
|
59
|
-
if (!config.name) {
|
|
60
|
-
throw new TypeError('世界配置必须包含名称');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let world = new GameWorld(config, this);
|
|
64
|
-
world.world_id = world_id;
|
|
65
|
-
await world.do('init', this._channel, this.getEventer(), this.getLogger());
|
|
66
|
-
this._worlds.set(world.world_id, world);
|
|
67
|
-
return world;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 获取世界
|
|
72
|
-
* @param {string} world_id 世界ID
|
|
73
|
-
* @returns {object} 世界对象
|
|
74
|
-
*/
|
|
75
|
-
Game.prototype.get = function (world_id) {
|
|
76
|
-
return this._worlds.get(world_id);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 创建主城世界
|
|
81
|
-
* @param {object} config 世界配置
|
|
82
|
-
* @returns {object} 游戏世界对象
|
|
83
|
-
*/
|
|
84
|
-
Game.prototype._createMainWorld = async function (config = {}) {
|
|
85
|
-
var world = await this.createWorld({
|
|
86
|
-
name: 'main_world',
|
|
87
|
-
title: '主城世界',
|
|
88
|
-
type: 'safe',
|
|
89
|
-
max_players: this.config.max_players || 5000,
|
|
90
|
-
...config
|
|
91
|
-
});
|
|
92
|
-
this._channel.main_world_id = world.world_id;
|
|
93
|
-
return world;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 获取世界
|
|
98
|
-
* @param {string} world_id 世界ID
|
|
99
|
-
* @returns {object} 世界对象
|
|
100
|
-
*/
|
|
101
|
-
Game.prototype.getById = function (world_id) {
|
|
102
|
-
return this._worlds.get(world_id);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 进入世界
|
|
107
|
-
* @param {string} world_id 世界ID
|
|
108
|
-
* @param {string} player_id 玩家ID
|
|
109
|
-
* @returns {object} 世界对象
|
|
110
|
-
* @throws {Error} 进入世界失败时抛出
|
|
111
|
-
*/
|
|
112
|
-
Game.prototype.enter = function (world_id, player_id) {
|
|
113
|
-
let game = this.getById(world_id);
|
|
114
|
-
if (!game) {
|
|
115
|
-
throw new Error(`${world_id} 不存在`);
|
|
116
|
-
}
|
|
117
|
-
game.enter(player_id);
|
|
118
|
-
return game;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* 根据世界名称获取世界对象
|
|
123
|
-
* @param {string} name 世界名称
|
|
124
|
-
* @returns {object|null} 世界对象,如果不存在则返回null
|
|
125
|
-
*/
|
|
126
|
-
Game.prototype.getByName = function (name) {
|
|
127
|
-
for (let game of this._worlds.values()) {
|
|
128
|
-
if (game.config.name === name) {
|
|
129
|
-
return game;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
module.exports = {
|
|
136
|
-
Game
|
|
137
|
-
};
|