-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchvsDemoEngine.js
More file actions
233 lines (203 loc) · 6.05 KB
/
MatchvsDemoEngine.js
File metadata and controls
233 lines (203 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
let mvs=require("Matchvs");
let Glb=require("Glb");
let response=require("MatchvsDemoResponse");
function MatchvsDemoEngine() {
}
/**
* 初始化
* @param channel
* @param platform
* @param gameID
*/
MatchvsDemoEngine.prototype.init = function(channel, platform){
response.prototype.bind();
let gameVersion = 1;
let result = mvs.engine.init(mvs.response, channel, platform,Glb.gameID,Glb.appKey,gameVersion);
console.log("初始化result"+result);
return result;
};
/**
* 独立部署使用的初始化接口
* @param {string} endPoint
* @param {number} gameID
*/
MatchvsDemoEngine.prototype.premiseInit = function (endPoint, gameID) {
response.prototype.bind();
let result = mvs.engine.premiseInit(mvs.response, endPoint, gameID);
console.log("独立部署初始化result"+result);
return result;
};
/**
* 注册
* @returns {number|*}
*/
MatchvsDemoEngine.prototype.registerUser = function() {
let result = mvs.engine.registerUser();
console.log("注册result"+result);
return result;
};
/**
* 登录
* @param userID
* @param token
* @returns {DataView|*|number|void}
*/
MatchvsDemoEngine.prototype.login = function(userID,token){
let DeviceID = 'abcdef';
let result = mvs.engine.login(userID, token,DeviceID);
console.log("登录result"+result);
return result;
};
/**
* 断线重连
* @returns {*|number}
*/
MatchvsDemoEngine.prototype.reconnect = function () {
let result = mvs.engine.reconnect();
console.log("重连result"+result);
return result;
};
/**
* 退出游戏
* @returns {DataView|number|*}
*/
MatchvsDemoEngine.prototype.logout = function () {
let result = mvs.engine.logout("退出游戏");
console.log('退出游戏result'+result);
return result;
};
/**
* 反初始化
*/
MatchvsDemoEngine.prototype.uninit =function () {
let result = mvs.engine.uninit();
console.log('反初始化result'+result);
return result;
};
/**
* 随机匹配
* @param mxaNumer 房间最大人数
* @param profile 负载消息,可以用来传送玩家姓名 等级等信息
* @returns {number}
*/
MatchvsDemoEngine.prototype.joinRandomRoom = function(mxaNumer,profile){
let result = mvs.engine.joinRandomRoom(mxaNumer, MatchvsDemoEngine.prototype.getUserProfile(profile));
console.log("随机匹配result"+result);
return result;
};
/**
* 属性匹配
* @param matchinfo
* @param profile
*/
MatchvsDemoEngine.prototype.joinRoomWithProperties = function (matchinfo,profile) {
let result = mvs.engine.joinRoomWithProperties(matchinfo, MatchvsDemoEngine.prototype.getUserProfile(profile));
console.log("属性匹配result"+result);
return result;
};
/**
* 离开房间
*/
MatchvsDemoEngine.prototype.leaveRoom = function () {
let obj = {name: Glb.name, profile: '主动离开了房间'};
let result = mvs.engine.leaveRoom(JSON.stringify(obj));
console.log(Glb.name+"主动离开房间result"+result);
return result;
};
/**
* 关闭房间
* @returns {number}
*/
MatchvsDemoEngine.prototype.joinOver = function(){
let result = mvs.engine.joinOver("关闭房间");
console.log("joinOver result"+result);
return result;
};
/**
* 打开房间
* @returns {number}
*/
MatchvsDemoEngine.prototype.joinOpen = function(){
let result = mvs.engine.joinOpen("打开房间");
console.log("joinOpen result"+result);
return result;
};
/**
* 获取房间列表扩展接口
* @param roomFilter
* @returns {*|number}
*/
MatchvsDemoEngine.prototype.getRoomListEx = function (roomFilter) {
let result = mvs.engine.getRoomListEx(roomFilter);
console.log("加载房间列表扩展接口 result"+result);
return result;
};
/**
* 加入指定房间
* @param roomID
* @param profile
*/
MatchvsDemoEngine.prototype.joinRoom = function (roomID,profile) {
let result = mvs.engine.joinRoom(roomID, MatchvsDemoEngine.prototype.getUserProfile(profile));
console.log("加入指定房间 result"+result);
return result;
};
/**
* 创建指定房间
* @param roomFilter
* @param profile
* @returns {number}
*/
MatchvsDemoEngine.prototype.createRoom = function (roomFilter,profile) {
let result = mvs.engine.createRoom(roomFilter, MatchvsDemoEngine.prototype.getUserProfile(profile));
console.log("创建指定类型房间 result"+result);
return result;
};
/**
* 踢出指定玩家
* @param userID
* @param profile
*/
MatchvsDemoEngine.prototype.kickPlayer = function (userID,profile) {
let obj = {name: profile, profile: profile + '被踢出了房间'};
let result = mvs.engine.kickPlayer(userID, JSON.stringify(obj));
console.log(userID+"被踢出游戏 result"+result);
return result;
};
/**
* 修改房间属性
* @param roomID
* @returns {*}
*/
MatchvsDemoEngine.prototype.getRoomDetail = function(roomID){
let result = mvs.engine.getRoomDetail(roomID);
console.log("获取房间详情 result"+ result);
return result;
};
MatchvsDemoEngine.prototype.sendEvent = function (msg) {
let data = mvs.engine.sendEvent(msg);
// console.log("发送信息 result"+ data.result);
return data.result;
};
/**
* 发送消息扩展
* @param type 消息类型。0表示转发给房间成员;1表示转发给game server;2表示转发给房间成员及game server
* @param msg 消息内容
* @returns {*}
*/
MatchvsDemoEngine.prototype.sendEventEx = function (type,msg) {
let data = mvs.engine.sendEventEx(type, msg, 1, []);
return data.result;
};
/**
* 获取进入房间负载信息
* @param profile
* @returns {string}
*/
MatchvsDemoEngine.prototype.getUserProfile = function (profile) {
let userProfile = {name: Glb.name, avatar: Glb.avatar, profile: profile};
let userProfileStr = JSON.stringify(userProfile);
console.log("进入房间负载信息"+userProfileStr);
return userProfileStr;
};
module.exports = MatchvsDemoEngine;