mm_os 4.3.7 → 5.0.1
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 +102 -504
- package/index.js +26 -19
- package/lib/os.js +536 -0
- package/package.json +60 -84
- 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 -704
- package/com/mqtt/index.js +0 -1052
- package/com/mqtt/index.test.js +0 -503
- 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 -1328
- 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 -395
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -711
- 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 -267
- 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/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 -602
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
package/core/room/bat/room.js
DELETED
|
@@ -1,524 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
Drive
|
|
3
|
-
} = require('mm_machine');
|
|
4
|
-
const {
|
|
5
|
-
idGen
|
|
6
|
-
} = require('../../ulits/id_gen.js');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 游戏房间
|
|
10
|
-
*/
|
|
11
|
-
class GameRoom extends Drive {
|
|
12
|
-
static config = {
|
|
13
|
-
// 房间名称
|
|
14
|
-
'name': '5v5',
|
|
15
|
-
// 房间标题
|
|
16
|
-
'title': '',
|
|
17
|
-
// 是否召集
|
|
18
|
-
'invite': true,
|
|
19
|
-
// 房间等级下限
|
|
20
|
-
'min_level': 0,
|
|
21
|
-
// 房间等级上限
|
|
22
|
-
'max_level': 1000,
|
|
23
|
-
// 房间最大人数
|
|
24
|
-
'max_players': 5,
|
|
25
|
-
// 游戏类型 rpg、card
|
|
26
|
-
'type': 'card',
|
|
27
|
-
// 游戏类型 排位赛rank、娱乐局casual
|
|
28
|
-
'mode': 'rank',
|
|
29
|
-
// 房间主程序
|
|
30
|
-
'main': ''
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 构造函数
|
|
35
|
-
* @param {object} config 配置参数
|
|
36
|
-
*/
|
|
37
|
-
constructor(config) {
|
|
38
|
-
super({
|
|
39
|
-
...GameRoom.config,
|
|
40
|
-
...config
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// 房间ID
|
|
44
|
-
this.room_id = this.genId();
|
|
45
|
-
|
|
46
|
-
// 游戏世界ID
|
|
47
|
-
this._world_id = '';
|
|
48
|
-
|
|
49
|
-
// 房主ID
|
|
50
|
-
this.owner = '';
|
|
51
|
-
|
|
52
|
-
// 玩家ID集合 - 使用Set保证唯一性和高效查找
|
|
53
|
-
this._player_ids = new Set();
|
|
54
|
-
|
|
55
|
-
// 状态 1:waiting等待中, 2:queue队列中, 3:doing进行中
|
|
56
|
-
this.state = 1;
|
|
57
|
-
|
|
58
|
-
// 匹配时间
|
|
59
|
-
this._match_time = null;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 获取模板目录
|
|
65
|
-
* @returns {string} 模板目录
|
|
66
|
-
*/
|
|
67
|
-
GameRoom.prototype.getTplDir = function() {
|
|
68
|
-
return __dirname;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 生成房间ID
|
|
73
|
-
* @returns {string} 房间ID
|
|
74
|
-
*/
|
|
75
|
-
GameRoom.prototype.genId = function () {
|
|
76
|
-
return idGen.genId('room');
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 初始化核心
|
|
81
|
-
* @param {object} channel 游戏频道
|
|
82
|
-
* @param {object} eventer 事件管理器
|
|
83
|
-
* @param {object} logger 日志管理器
|
|
84
|
-
*/
|
|
85
|
-
GameRoom.prototype._initCore = async function (channel, eventer, logger) {
|
|
86
|
-
if (logger) {
|
|
87
|
-
this.setLogger(logger);
|
|
88
|
-
}
|
|
89
|
-
if (eventer) {
|
|
90
|
-
this.getEventer = function () {
|
|
91
|
-
return eventer;
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
if (!channel) {
|
|
95
|
-
throw new TypeError('游戏频道不能为空');
|
|
96
|
-
}
|
|
97
|
-
// 游戏频道
|
|
98
|
-
this._channel = channel;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 加载房间玩家
|
|
103
|
-
* @returns {Promise<void>}
|
|
104
|
-
*/
|
|
105
|
-
GameRoom.prototype._load = async function () {
|
|
106
|
-
try {
|
|
107
|
-
// 通过事件方式加载房间内的玩家数据,避免直接操作数据库
|
|
108
|
-
var players = await this.emitWait('room_player_load', {
|
|
109
|
-
room_id: this.room_id,
|
|
110
|
-
room_name: this.config.name,
|
|
111
|
-
room: this
|
|
112
|
-
});
|
|
113
|
-
if (players && players.length > 0) {
|
|
114
|
-
// 遍历玩家列表,恢复玩家到房间
|
|
115
|
-
for (var i = 0; i < players.length; i++) {
|
|
116
|
-
var player_id = players[i];
|
|
117
|
-
// 添加玩家到房间
|
|
118
|
-
this._player_ids.add(player_id);
|
|
119
|
-
}
|
|
120
|
-
this.log('info', `加载房间玩家成功,共 ${players.length} 人`);
|
|
121
|
-
}
|
|
122
|
-
} catch (error) {
|
|
123
|
-
this.log('error', `加载房间玩家数据失败: `, error);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 设置房主
|
|
129
|
-
* @param {object} player 房主
|
|
130
|
-
*/
|
|
131
|
-
GameRoom.prototype.setOwner = function (player) {
|
|
132
|
-
this.owner = player.player_id;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 检查房间是否有玩家
|
|
137
|
-
* @param {string} player_id 玩家ID
|
|
138
|
-
* @returns {boolean} 是否有玩家
|
|
139
|
-
*/
|
|
140
|
-
GameRoom.prototype._hasPlayer = function (player_id) {
|
|
141
|
-
return this._player_ids.has(player_id);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* 添加玩家
|
|
146
|
-
* @param {string} player_id 玩家ID
|
|
147
|
-
*/
|
|
148
|
-
GameRoom.prototype._addPlayer = function (player_id) {
|
|
149
|
-
this._player_ids.add(player_id);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* 移除玩家
|
|
154
|
-
* @param {string} player_id 玩家ID
|
|
155
|
-
*/
|
|
156
|
-
GameRoom.prototype._delPlayer = function (player_id) {
|
|
157
|
-
this._player_ids.delete(player_id);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* 获取游戏世界
|
|
162
|
-
* @returns {object} 游戏世界
|
|
163
|
-
*/
|
|
164
|
-
GameRoom.prototype.getWorld = function () {
|
|
165
|
-
// 从游戏频道获取游戏世界
|
|
166
|
-
return this._channel.getWorld(this._world_id);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* 设置游戏世界
|
|
171
|
-
* @param {string} world_id 游戏世界ID
|
|
172
|
-
*/
|
|
173
|
-
GameRoom.prototype.setWorldId = function (world_id) {
|
|
174
|
-
this._world_id = world_id;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* 创建游戏世界
|
|
179
|
-
* @param {object} config 游戏世界配置
|
|
180
|
-
* @returns {object} 游戏世界
|
|
181
|
-
*/
|
|
182
|
-
GameRoom.prototype.createWorld = async function (config) {
|
|
183
|
-
// 游戏世界
|
|
184
|
-
var world = await this._channel.createWorld({ ...this.config, ...config });
|
|
185
|
-
// 设置游戏世界
|
|
186
|
-
this.setWorldId(world.world_id);
|
|
187
|
-
return world;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* 广播消息给房间内所有玩家
|
|
192
|
-
* @param {string} event 事件名称
|
|
193
|
-
* @param {object} data 数据
|
|
194
|
-
*/
|
|
195
|
-
GameRoom.prototype.broadcast = function (event, data) {
|
|
196
|
-
var player_ids = this.getAllPlayerIds();
|
|
197
|
-
// 直接触发房间广播事件,让事件处理器来处理
|
|
198
|
-
this.emitEvent('room_broadcast', {
|
|
199
|
-
room_id: this.room_id,
|
|
200
|
-
room_name: this.config.name,
|
|
201
|
-
event: event,
|
|
202
|
-
data: data,
|
|
203
|
-
player_ids: player_ids,
|
|
204
|
-
timestamp: Date.now()
|
|
205
|
-
});
|
|
206
|
-
this.log('debug', `广播消息: ${event} 给 ${player_ids.length} 名玩家`);
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* 玩家进入房间
|
|
211
|
-
* @param {string} player_id 玩家ID
|
|
212
|
-
*/
|
|
213
|
-
GameRoom.prototype.enter = function (player_id) {
|
|
214
|
-
// 检查玩家是否已在房间内
|
|
215
|
-
if (this._hasPlayer(player_id)) {
|
|
216
|
-
throw new Error(`玩家 ${player_id} 已在房间内`);
|
|
217
|
-
}
|
|
218
|
-
this._addPlayer(player_id);
|
|
219
|
-
this.emitEvent('room_enter', {
|
|
220
|
-
room_id: this.room_id,
|
|
221
|
-
room_name: this.config.name,
|
|
222
|
-
player_id: player_id,
|
|
223
|
-
timestamp: Date.now()
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* 玩家退出房间
|
|
229
|
-
* @param {string} player_id 玩家ID
|
|
230
|
-
*/
|
|
231
|
-
GameRoom.prototype.leave = function (player_id) {
|
|
232
|
-
this._delPlayer(player_id);
|
|
233
|
-
this.emitEvent('room_leave', {
|
|
234
|
-
room_id: this.room_id,
|
|
235
|
-
room_name: this.config.name,
|
|
236
|
-
player_id: player_id,
|
|
237
|
-
timestamp: Date.now()
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* 获取房间玩家数量
|
|
243
|
-
* @returns {number} 玩家数量
|
|
244
|
-
*/
|
|
245
|
-
GameRoom.prototype.getPlayerNum = function () {
|
|
246
|
-
return this._player_ids.size;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* 获取所有玩家ID
|
|
251
|
-
* @returns {Array} 玩家ID数组
|
|
252
|
-
*/
|
|
253
|
-
GameRoom.prototype.getAllPlayerIds = function () {
|
|
254
|
-
return Array.from(this._player_ids);
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* 开始匹配
|
|
259
|
-
*/
|
|
260
|
-
GameRoom.prototype.startMatch = function () {
|
|
261
|
-
// 检查所有玩家是否已准备
|
|
262
|
-
if (!this.isAllPlayersReady()) {
|
|
263
|
-
throw new Error('房间内玩家未全部准备');
|
|
264
|
-
}
|
|
265
|
-
// 检查房间是否已开始匹配
|
|
266
|
-
if (this.state === 2) {
|
|
267
|
-
throw new Error('房间已开始匹配');
|
|
268
|
-
}
|
|
269
|
-
// 检查房间是否已开始游戏
|
|
270
|
-
else if (this.state === 3) {
|
|
271
|
-
throw new Error('房间已开始游戏');
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
this.state = 2;
|
|
275
|
-
// 记录匹配开始时间
|
|
276
|
-
this._match_time = Date.now();
|
|
277
|
-
|
|
278
|
-
// 触发开始匹配事件
|
|
279
|
-
this.emitEvent('room_start_match', {
|
|
280
|
-
room_id: this.room_id,
|
|
281
|
-
room_name: this.config.name,
|
|
282
|
-
timestamp: this._match_time
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* 匹配玩家
|
|
288
|
-
* 根据房间配置进行玩家匹配
|
|
289
|
-
* @returns {object} 匹配结果
|
|
290
|
-
*/
|
|
291
|
-
GameRoom.prototype._matchPlayers = function () {
|
|
292
|
-
var config = this.config;
|
|
293
|
-
var format = config.format || '5v5';
|
|
294
|
-
var mode = config.mode || 'rank';
|
|
295
|
-
var player_ids = this.getAllPlayerIds();
|
|
296
|
-
var player_count = player_ids.length;
|
|
297
|
-
|
|
298
|
-
var ret = this._checkMatch(player_count, config.max_players || 6);
|
|
299
|
-
if (!ret.valid) {
|
|
300
|
-
return { success: false, reason: ret.reason };
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
var teams = this._splitTeams(player_ids, format);
|
|
304
|
-
if (!teams) {
|
|
305
|
-
return { success: false, reason: '玩家数量不符合比赛格式要求' };
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return this._buildMatch(mode, format, teams, player_count);
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* 检查匹配条件
|
|
313
|
-
* @param {number} player_count 玩家数量
|
|
314
|
-
* @param {number} max_players 最大玩家数
|
|
315
|
-
* @returns {object} 检查结果
|
|
316
|
-
*/
|
|
317
|
-
GameRoom.prototype._checkMatch = function (player_count, max_players) {
|
|
318
|
-
if (player_count === 0) {
|
|
319
|
-
return { valid: false, reason: '房间内没有玩家' };
|
|
320
|
-
}
|
|
321
|
-
if (player_count > max_players) {
|
|
322
|
-
return { valid: false, reason: '房间内玩家数量超过上限' };
|
|
323
|
-
}
|
|
324
|
-
return { valid: true };
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* 构建匹配结果
|
|
329
|
-
* @param {string} mode 游戏模式
|
|
330
|
-
* @param {string} format 比赛格式
|
|
331
|
-
* @param {object} teams 队伍配置
|
|
332
|
-
* @param {number} player_count 玩家数量
|
|
333
|
-
* @returns {object} 匹配结果
|
|
334
|
-
*/
|
|
335
|
-
GameRoom.prototype._buildMatch = function (mode, format, teams, player_count) {
|
|
336
|
-
var ret = {
|
|
337
|
-
success: true,
|
|
338
|
-
room_id: this.room_id,
|
|
339
|
-
mode: mode,
|
|
340
|
-
format: format,
|
|
341
|
-
teams: teams,
|
|
342
|
-
player_count: player_count,
|
|
343
|
-
timestamp: Date.now()
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
this.emitEvent('room_match_success', {
|
|
347
|
-
room_id: this.room_id,
|
|
348
|
-
ret: ret
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
return ret;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* 根据比赛格式分割队伍
|
|
356
|
-
* @param {Array} player_ids 玩家ID数组
|
|
357
|
-
* @param {string} format 比赛格式 (1v1, 3v3, 5v5, 1v3, 1v5)
|
|
358
|
-
* @returns {object|null} 队伍配置
|
|
359
|
-
*/
|
|
360
|
-
GameRoom.prototype._splitTeams = function (player_ids, format) {
|
|
361
|
-
var count = player_ids.length;
|
|
362
|
-
var format_map = {
|
|
363
|
-
'1v1': { count: 2, team_a_size: 1 },
|
|
364
|
-
'3v3': { count: 6, team_a_size: 3 },
|
|
365
|
-
'5v5': { count: 10, team_a_size: 5 },
|
|
366
|
-
'1v3': { count: 4, team_a_size: 1 },
|
|
367
|
-
'1v5': { count: 6, team_a_size: 1 }
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
var rule = format_map[format];
|
|
371
|
-
if (rule && count === rule.count) {
|
|
372
|
-
return {
|
|
373
|
-
team_a: player_ids.slice(0, rule.team_a_size),
|
|
374
|
-
team_b: player_ids.slice(rule.team_a_size),
|
|
375
|
-
format: format
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (count >= 2) {
|
|
380
|
-
var half = Math.floor(count / 2);
|
|
381
|
-
return { team_a: player_ids.slice(0, half), team_b: player_ids.slice(half), format: format };
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return null;
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* 获取玩家
|
|
389
|
-
* @param {string} player_id 玩家ID
|
|
390
|
-
* @returns {object} 玩家对象
|
|
391
|
-
*/
|
|
392
|
-
GameRoom.prototype._getPlayer = function(player_id) {
|
|
393
|
-
// 这里需要从游戏频道获取玩家对象
|
|
394
|
-
return this._channel.getPlayer(player_id);
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* 玩家准备
|
|
399
|
-
* @param {string} player_id 玩家ID
|
|
400
|
-
*/
|
|
401
|
-
GameRoom.prototype.ready = function(player_id) {
|
|
402
|
-
// 检查玩家是否已在房间内
|
|
403
|
-
if (!this._hasPlayer(player_id)) {
|
|
404
|
-
throw new Error(`玩家 ${player_id} 不在房间内`);
|
|
405
|
-
}
|
|
406
|
-
// 获取玩家
|
|
407
|
-
var player = this._getPlayer(player_id);
|
|
408
|
-
player.is_ready = true;
|
|
409
|
-
|
|
410
|
-
// 触发玩家准备事件
|
|
411
|
-
this.emitEvent('player_ready', {
|
|
412
|
-
room_id: this.room_id,
|
|
413
|
-
player_id: player_id,
|
|
414
|
-
timestamp: Date.now()
|
|
415
|
-
});
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* 玩家取消准备
|
|
420
|
-
* @param {string} player_id 玩家ID
|
|
421
|
-
*/
|
|
422
|
-
GameRoom.prototype.cancelReady = function(player_id) {
|
|
423
|
-
// 检查玩家是否已在房间内
|
|
424
|
-
if (!this._hasPlayer(player_id)) {
|
|
425
|
-
throw new Error(`玩家 ${player_id} 不在房间内`);
|
|
426
|
-
}
|
|
427
|
-
// 获取玩家
|
|
428
|
-
var player = this._getPlayer(player_id);
|
|
429
|
-
player.is_ready = false;
|
|
430
|
-
|
|
431
|
-
// 触发玩家取消准备事件
|
|
432
|
-
this.emitEvent('player_cancel_ready', {
|
|
433
|
-
room_id: this.room_id,
|
|
434
|
-
player_id: player_id,
|
|
435
|
-
timestamp: Date.now()
|
|
436
|
-
});
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* 检查所有玩家是否已准备
|
|
441
|
-
* @returns {boolean} 是否全部准备
|
|
442
|
-
*/
|
|
443
|
-
GameRoom.prototype.isAllPlayersReady = function() {
|
|
444
|
-
var player_ids = this.getAllPlayerIds();
|
|
445
|
-
// 如果房间没有玩家,返回false
|
|
446
|
-
if (player_ids.length === 0) {
|
|
447
|
-
return false;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// 使用for循环检查除房主外的所有玩家是否已准备
|
|
451
|
-
for (var i = 0; i < player_ids.length; i++) {
|
|
452
|
-
var player_id = player_ids[i];
|
|
453
|
-
|
|
454
|
-
// 跳过房主(房主没有准备按钮)
|
|
455
|
-
if (player_id === this.owner) {
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
var player = this._getPlayer(player_id);
|
|
460
|
-
|
|
461
|
-
// 如果有一个玩家未准备,返回false
|
|
462
|
-
if (!player.is_ready) {
|
|
463
|
-
return false;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// 所有非房主玩家都已准备
|
|
468
|
-
return true;
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* 获取准备玩家列表
|
|
473
|
-
* @returns {Array} 准备玩家ID列表
|
|
474
|
-
*/
|
|
475
|
-
GameRoom.prototype.getReadyPlayers = function() {
|
|
476
|
-
var ready_players = [];
|
|
477
|
-
var player_ids = this.getAllPlayerIds();
|
|
478
|
-
|
|
479
|
-
// 使用for循环获取除房主外的准备玩家列表
|
|
480
|
-
for (var i = 0; i < player_ids.length; i++) {
|
|
481
|
-
var player_id = player_ids[i];
|
|
482
|
-
|
|
483
|
-
// 跳过房主(房主没有准备按钮)
|
|
484
|
-
if (player_id === this.owner) {
|
|
485
|
-
continue;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
var player = this._getPlayer(player_id);
|
|
489
|
-
|
|
490
|
-
// 如果玩家已准备,添加到列表
|
|
491
|
-
if (player.is_ready) {
|
|
492
|
-
ready_players.push(player_id);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
return ready_players;
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* 保存房间数据
|
|
501
|
-
* @returns {Promise<void>}
|
|
502
|
-
*/
|
|
503
|
-
GameRoom.prototype._save = async function () {
|
|
504
|
-
try {
|
|
505
|
-
var room_data = {
|
|
506
|
-
room_id: this.room_id,
|
|
507
|
-
name: this.config.name,
|
|
508
|
-
owner: this.owner,
|
|
509
|
-
state: this.state,
|
|
510
|
-
player_ids: this.getAllPlayerIds(),
|
|
511
|
-
world_id: this._world_id
|
|
512
|
-
};
|
|
513
|
-
// 通过事件方式保存房间数据
|
|
514
|
-
await this.emitWait('room_save', {
|
|
515
|
-
room_id: this.room_id,
|
|
516
|
-
room_data: room_data
|
|
517
|
-
});
|
|
518
|
-
this.log('debug', `保存房间数据成功`);
|
|
519
|
-
} catch (error) {
|
|
520
|
-
this.log('error', `保存房间数据失败: `, error);
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
exports.GameRoom = GameRoom;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// 房间名称
|
|
3
|
-
"name": "5v5_rank",
|
|
4
|
-
// 房间标题
|
|
5
|
-
"title": "5v5排位赛",
|
|
6
|
-
// 房间描述
|
|
7
|
-
"description": "5v5排位赛房间",
|
|
8
|
-
// 房间等级上限
|
|
9
|
-
"max_level": 1000,
|
|
10
|
-
// 房间最大人数
|
|
11
|
-
"max_players": 5,
|
|
12
|
-
// 游戏类型 rpg、card
|
|
13
|
-
"type": "card",
|
|
14
|
-
// 游戏类型 排位赛rank、娱乐局casual
|
|
15
|
-
"mode": "rank",
|
|
16
|
-
// 房间主程序
|
|
17
|
-
"main": "",
|
|
18
|
-
// 房间最大房间数
|
|
19
|
-
"max_rooms": 1000
|
|
20
|
-
}
|