Commit 860b4b42 authored by 范雪寒's avatar 范雪寒

feat: 单机可以玩了

parent f62de039
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
"type": "software", "type": "software",
"scope": "game", "scope": "game",
"name": "GameOBESDK", "name": "GameOBESDK",
"version": "1.1.4.301", "version": "1.1.5.300",
"playbook": "" "playbook": ""
} }
\ No newline at end of file
...@@ -64,7 +64,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -64,7 +64,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log("房主"); console.log("房主");
this.isRoomOwner = true; this.isRoomOwner = true;
this.server = new GameServer(2, this.networkHelper); this.server = new GameServer(2, this.networkHelper);
await this.networkHelper.startFrameSync();
this.server.addPlayer({ this.server.addPlayer({
uuid: this.playerId, uuid: this.playerId,
isAI: false, isAI: false,
...@@ -647,8 +646,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -647,8 +646,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
dataList.push(frameData); dataList.push(frameData);
} }
dataList.forEach(async (item) => { dataList.forEach(async (item) => {
console.log(item); if (!item.data) {
return; return;
}
console.log(item);
if (this.server) { if (this.server) {
this.server.onFrameEvent(item.data); this.server.onFrameEvent(item.data);
......
...@@ -33,7 +33,6 @@ export class NetworkHelper { ...@@ -33,7 +33,6 @@ export class NetworkHelper {
appId: '105879509',// 应用的ID appId: '105879509',// 应用的ID
openId: 'op_16' + Math.random(),// 玩家ID openId: 'op_16' + Math.random(),// 玩家ID
}); });
console.log(this.client);
await this.client.init(); await this.client.init();
} }
...@@ -41,41 +40,24 @@ export class NetworkHelper { ...@@ -41,41 +40,24 @@ export class NetworkHelper {
async joinRoom(roomType: string, maxPlayers: number) { async joinRoom(roomType: string, maxPlayers: number) {
const matchRoomConfig = { const matchRoomConfig = {
matchParams: { matchParams: {
matchRule: '', param1: 'param1',
matchRule2: '',
}, },
roomType: roomType, roomType: roomType,
customRoomProperties: '',
maxPlayers: maxPlayers, maxPlayers: maxPlayers,
}; };
// 在线匹配参数 this.room = await this.client.matchRoom(matchRoomConfig);
const matchPlayerConfig = {
playerInfo: {
playerId: 'xxxxxx',
matchParams: {
test: 1, // 匹配参数的属性需要与matchCode所属规则中配置的属性对应
},
},
matchCode: 'cc4dc617d3aa4f849824a12c3e8290c8',
};
const playerConfig = {
customPlayerStatus: 0,
customPlayerProperties: ''
};
console.log('汪汪汪1');
// this.room = await this.client.createRoom(matchRoomConfig, playerConfig);
this.room = await this.client.matchPlayer(matchPlayerConfig, playerConfig);
console.log('汪汪汪2' + JSON.stringify(this.room));
this.player = this.room.player; this.player = this.room.player;
console.log('汪汪汪: ' + this.room.players.length);
await this.startFrameSync();
console.log('汪汪汪2');
this.room.onJoin(this.onJoinRoom.bind(this)); this.room.onJoin(this.onJoinRoom.bind(this));
this.room.onLeave(this.onLeaveRoom.bind(this)); this.room.onLeave(this.onLeaveRoom.bind(this));
this.room.onStartFrameSync(this.onStartFrameSync.bind(this)); // this.room.onStartFrameSync(this.onStartFrameSync.bind(this));
this.room.onStopFrameSync(this.onStopFrameSync.bind(this)); this.room.onStopFrameSync(this.onStopFrameSync.bind(this));
this.room.onRecvFrame(this.onRecvFrame.bind(this)); this.room.onRecvFrame(this.onRecvFrame.bind(this));
this.room.onDisconnect(this.onDisconnect.bind(this)); this.room.onDisconnect(this.onDisconnect.bind(this));
this.room.onDismiss(this.onDisconnect.bind(this)); this.room.onDismiss(this.onDisconnect.bind(this));
console.log('汪汪汪3' + this.player.playerId);
return this.player.playerId; return this.player.playerId;
} }
...@@ -92,30 +74,32 @@ export class NetworkHelper { ...@@ -92,30 +74,32 @@ export class NetworkHelper {
} }
} }
closeRoom() { async closeRoom() {
return; await this.client.cancelMatch();
}
async startFrameSync() {
await this.room.startFrameSync();
// return new Promise((resolve, reject) => { // return new Promise((resolve, reject) => {
// this.room.changeRoom({ isForbidJoin: true }, (event) => { // this.room.onStartFrameSync(() => {
// console.log("关门"); // cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
// // console.log(JSON.stringify(event))
// resolve(null); // resolve(null);
// }); // });
// }); // });
} }
async startFrameSync() {
await this.room.startFrameSync();
cc.log("开始帧同步成功,请到控制台查看具体帧同步信息");
}
async stopFrameSync() { async stopFrameSync() {
await this.room.stopFrameSync(); await this.room.stopFrameSync();
console.log("停止帧同步成功"); console.log("停止帧同步成功");
} }
sendFrame(data: any) { sendFrame(data: any) {
console.log('sendFrame: ' + JSON.stringify(data)); console.warn('sendFrame: ' + JSON.stringify(data));
if (this.room._isSyncing) {
this.room.sendFrame(JSON.stringify(data)); this.room.sendFrame(JSON.stringify(data));
} else {
console.log('is syncing = false');
this.onRecvFrame({data});
}
} }
onJoinRoom(event) { onJoinRoom(event) {
...@@ -123,6 +107,9 @@ export class NetworkHelper { ...@@ -123,6 +107,9 @@ export class NetworkHelper {
this._eventListeners["playerJoin"](event); this._eventListeners["playerJoin"](event);
} }
console.log("新玩家加入", JSON.stringify(event)); console.log("新玩家加入", JSON.stringify(event));
this.room.players.forEach(player => {
console.log('player.playerId = ', player.playerId);
});
} }
onLeaveRoom(event) { onLeaveRoom(event) {
console.log("onLeaveRoom"); console.log("onLeaveRoom");
...@@ -146,6 +133,7 @@ export class NetworkHelper { ...@@ -146,6 +133,7 @@ export class NetworkHelper {
} }
} }
onStartFrameSync(event) { onStartFrameSync(event) {
console.log('onStartFrameSync');
if (this._eventListeners["gameStart"]) { if (this._eventListeners["gameStart"]) {
this._eventListeners["gameStart"](event); this._eventListeners["gameStart"](event);
} }
......
...@@ -37,11 +37,12 @@ export class GameServer { ...@@ -37,11 +37,12 @@ export class GameServer {
this.headUrls = this.headUrls.sort((a, b) => RandomInt(2) - 1); this.headUrls = this.headUrls.sort((a, b) => RandomInt(2) - 1);
this.nameList = this.nameList.sort((a, b) => RandomInt(2) - 1); this.nameList = this.nameList.sort((a, b) => RandomInt(2) - 1);
this.networkHelper.startFrameSync();
} }
async addPlayer(player) { async addPlayer(player) {
if (this.playerList.find(p => p.uuid == player.uuid)) {
return;
}
console.log("addPlayer"); console.log("addPlayer");
this.playerList.push({ this.playerList.push({
name: this.nameList.splice(0, 1)[0], name: this.nameList.splice(0, 1)[0],
...@@ -206,7 +207,7 @@ export class GameServer { ...@@ -206,7 +207,7 @@ export class GameServer {
startAI() { startAI() {
this.playerList this.playerList
.filter((player) => player.isAI == true) .filter((player) => player.isAI == true)
.forEach((player) => {}); .forEach((player) => { });
} }
_timeoutIds = null; _timeoutIds = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment