var NetManage = require('NetManage'); var Utils = require('Utils'); var battlenet = require('battlenetmanage'); var SDKManage = require('SDKManage'); cc.Class({ extends: cc.Component, properties: { lb_first: { default: null, type: cc.Label, }, lb_second: { default: null, type: cc.Label, }, nd_zhaomu: { default: null, type: cc.Node, }, nd_pipei: { default: null, type: cc.Node, }, nd_players: { default: [], type: cc.Node, }, btn_start: { default: null, type: cc.Node, }, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, onLoad() { this.zhaomutime = 0; this.m_curTime = 0; this.m_curSeconds = 0; this.updateteamtime = 0; this.step = 0; cc.Notifier.on( 'SMUpdateMatchInfo', this, this.SMUpdateMatchInfo.bind(this) ); cc.director.on('SOCKETCLOSE', this.socketCloseCallBack, this); this.btn_start.active = false; }, onDestroy() { cc.playerData.team_list = null; cc.Notifier.off('SMUpdateMatchInfo', this); cc.director.off('SOCKETCLOSE', this); cc.playerData.teamuuid = null; }, initdata(teamuuid) { this.nd_pipei.active = false; if (teamuuid) { this.nd_zhaomu.active = true; this.teamuuid = teamuuid; cc.playerData.teamuuid = this.teamuuid; window.team_uuid = this.teamuuid; } else { NetManage.createTeam((res) => { this.nd_zhaomu.active = true; this.teamuuid = res.team_uuid; cc.playerData.teamuuid = this.teamuuid; window.team_uuid = this.teamuuid; }); } cc.Notifier.emit('closechat'); }, startpipei() { this.nd_zhaomu.active = false; this.nd_pipei.active = true; this.step = 1; var teamlist = cc.playerData.team_list; var team_members = []; for (var i = 0; i < teamlist.length; i++) { team_members.push({ account_id: teamlist[i].account_id, }); } cc.playerData.changeHero(30100); var opt = cc.playerData.getbattleopt(); opt.team_uuid = this.teamuuid.team_uuid; opt.team_mode = 1; opt.team_members = team_members; battlenet.initengine(opt); }, SMUpdateMatchInfo(_data) { var data = _data.info; this.lb_first.string = Utils.second3Time(data.predict_time); this.refreshwait(data.members); if (data.phase == 2) { cc.uiMain.callbattlechosehero({ teamuuid: this.teamuuid, }); this.node.destroy(); return; } }, refreshwait(data) { for (var i = 0; i < 4; i++) { var name = ''; var headid = ''; var frameid = ''; if (data[i]) { name = data[i].name; headid = data[i].head_id; if (!headid) { headid = data[i].avatar_url; } frameid = data[i].head_frame; } this.nd_players[i].getComponent('iconset').initdata({ name: name, headid: headid, head_frame: frameid, }); } }, onclickpipei() { if (this.teamuuid) { NetManage.teamStartGame(this.teamuuid); } }, onclickclose() { if (this.teamuuid) { NetManage.leaveTeam(this.teamuuid); this.node.destroy(); } }, socketCloseCallBack() { this.node.destroy(); }, btnClose() { // sendBattlemsg(key,value) cc.battleIns.sendbattlemsg('CMMatchCancel'); setTimeout(() => { cc.battleIns.clean(); }, 100); this.node.destroy(); }, onclickzhaomu() { var nowtime = new Date().getTime() / 1000; if (nowtime - this.zhaomutime < 30) { cc.uiHelper.showTips('Recruiting, please wait'); return; } this.zhaomutime = nowtime; let battleobj = { tp: 1, text: 'Hey,come and play~', title: 'Rank - Multiplayer', roomid: this.teamuuid, }; let tmpData = { chat_channel: 1, target: '', msg_type: 1, msg_body: JSON.stringify(battleobj), }; cc.chatMgr.sendmsg('CMSendChatMsg', tmpData); cc.uiHelper.showTips('Send recruitment'); }, onclicktalk() { cc.uiMain.callChat(); }, updateteaminfo(v) { console.log(v); if (v.errcode == 0) { var info = v.team_info; this.btn_start.active = info.member_list[0].account_id == SDKManage.account_id; this.refreshwait(info.member_list); cc.playerData.team_list = info.member_list; if (info.state == 1) { this.startpipei(); } } }, update(dt) { if (this.step == 0) { if (this.teamuuid) { this.updateteamtime -= dt; if (this.updateteamtime <= 0) { NetManage.getTeamInfo( this.teamuuid, this.updateteaminfo.bind(this) ); this.updateteamtime = 1; } } return; } this.m_curTime += dt; if (this.m_curTime > 1) { this.m_curTime = 0; this.m_curSeconds++; this.lb_second.string = Utils.second3Time(this.m_curSeconds); } }, });