Game.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. const GameModule = require("./utils/GameModule");
  2. const FriendSystemApi = require('./net/FriendSystemApi');
  3. const ShareAction = require('./utils/ShareAction');
  4. const DWTool = require('./utils/DWTool');
  5. const DWAlert = require('./utils/DWAlert');
  6. const HomeApi = require("./net/HomeApi");
  7. const JobApi = require('./net/JobApi');
  8. const { GameNotificationKey, SenceMap, JobPageType } = require('./utils/GameEnum');
  9. const AlertManager = require('./utils/AlertManager');
  10. const tutorial = require('./utils/Bundle').tutorial;
  11. const StateMachine = require('./lib/StateMachine');
  12. const StateMachineHistory = require('./lib/StateMachineHistory');
  13. const WsManager = require('./net/Ws');
  14. cc.Class({
  15. extends: cc.Component,
  16. properties: {
  17. levelHomePrefab: cc.Prefab,
  18. levelFriendHomePrefab: cc.Prefab,
  19. wechatFriendNode: cc.Node,
  20. //用户信息页
  21. userInfoPrefab: cc.Prefab,
  22. myInfoTop: cc.Node,
  23. myTabBottom: cc.Node,
  24. friendInfoTop: cc.Node,
  25. friendTabBottom: cc.Node,
  26. sidebar: cc.Node,
  27. _otherActor: cc.Node,
  28. friendSystemPrefab: cc.Prefab,
  29. friendHeadSprite: cc.Sprite,
  30. talentPagePrefab: cc.Prefab,
  31. noticePoint: cc.Node,
  32. questPoint: cc.Node,
  33. chooseJob: cc.Node,
  34. transition: cc.Node,
  35. mapIcon: cc.Node,
  36. talentIcon: cc.Node,
  37. homeGuide: cc.Node,
  38. toastNode: cc.Node,
  39. levelHomeSpeedUpTipsNode: cc.Node,
  40. },
  41. onLoad() {
  42. GameModule.game = this.node;
  43. this.homeGuide.zIndex = 99;
  44. GameModule.homeGuide = this.homeGuide;
  45. // 创建一个事件监听实例, 用来实现跨节点监听事件
  46. GameEvent.init();
  47. //我的家园
  48. let levelHome = cc.instantiate(this.levelHomePrefab);
  49. levelHome = levelHome.getComponent('LevelHome');
  50. levelHome.init(Global.user.uid, Global.devCityId);
  51. this.levelHome = levelHome;
  52. //好友系统Tab面板
  53. let friendSystem = cc.instantiate(this.friendSystemPrefab);
  54. this.friendSystem = friendSystem.getComponent('FriendSystem');
  55. //好友家园
  56. let friendHome = cc.instantiate(this.levelFriendHomePrefab);
  57. friendHome = friendHome.getComponent('LevelFriendHome');
  58. this.friendHome = friendHome;
  59. //突破界面
  60. let breakOut = "";
  61. this.breakOut = breakOut;
  62. //底部Tab栏
  63. this.myTabBottom = this.myTabBottom.getComponent('Tab');
  64. // //转职界面
  65. // this.jobChange = cc.instantiate(this.jobChangePrefab);
  66. // this.jobChange = this.jobChange.getComponent('ChangeJob');
  67. // 星探界面
  68. this.finder = cc.instantiate(this.talentPagePrefab);
  69. this.finder = this.finder.getComponent('TalentPage');
  70. // 引导界面
  71. this.homeGuide = this.homeGuide.getComponent('HomeGuide')
  72. this.homeGuide.init(this)
  73. // cc.loader.loadRes('prefabs/home_guide', cc.Prefab, (err, res) => {
  74. // this.homeGuide = cc.instantiate(res)
  75. // cc.find('Canvas').addChild(this.homeGuide);
  76. // })
  77. // 监听事件
  78. this._setEventListener();
  79. // 初始化场景管理状态机
  80. this._initFSM()
  81. // 初始化socket链接
  82. this._initSocketMng();
  83. if (Global.shareUid != -1) {
  84. console.log('shareUid: ' + Global.shareUid);
  85. this.processShareAction();
  86. }
  87. this.friendHeadSprite.node.on(cc.Node.EventType.TOUCH_END, () => {
  88. GameEvent.fire(GameNotificationKey.ShowUserInfomation, this.friendHome.uid);
  89. }, this);
  90. this.setMapIconVisible(true);
  91. this.toastScript = this.toastNode.getComponent('ToastCtrl');
  92. this.levelHomeSpeedUpTips = this.levelHomeSpeedUpTipsNode.getComponent('LevelHomeSpeedUpTip');
  93. // this.scheduleOnce(() => {
  94. // Global.devCityId = 2;
  95. // this.gameFSM.visitcitymap(true);
  96. // }, 1);
  97. },
  98. setMapIconVisible(visible) {
  99. if (Global.devCityId > 1) {
  100. this.mapIcon.active = visible;
  101. } else {
  102. this.mapIcon.active = false;
  103. }
  104. },
  105. updateUIState(state) {
  106. if (!!state['state6'].pass) {
  107. if (!this.myTabBottom.node.active) {
  108. this.myTabBottom.node.active = true;
  109. let actionBottom = cc.moveBy(0.4, cc.v2(0, this.myTabBottom.node.height + 27));
  110. this.myTabBottom.node.runAction(actionBottom);
  111. }
  112. this.talentIcon.enable = true;
  113. this.talentIcon.active = true;
  114. }
  115. },
  116. _initSocketMng() {
  117. let ja0ckUrl = 'ws://172.16.15.170:8108/connect'
  118. let testUrl = 'wss://test-message-allstar.duowan.com/connect'
  119. let pUrl = 'wss://message-allstar.duowan.com/connect'
  120. let Message = tutorial.Message;
  121. let ws = this.ws = new WsManager(testUrl, {
  122. binaryType: 'arraybuffer',
  123. autoConnect: true, // 自动连接
  124. reconnection: true, // 断开自动重连
  125. reconnectionDelay: 5000, // 重连间隔时间,单位秒
  126. reconnectionAttempts: 5
  127. })
  128. let seq = 1;
  129. if (CC_WECHATGAME) {
  130. if (this.ws.readyState == 'closed') {
  131. this.ws.reconnect()
  132. }
  133. }
  134. ws.on('open', (res) => {
  135. /**
  136. * targetUid : 目标用户uid
  137. * opt : 操作类型
  138. * {1: 赎身; 2: 抢夺; 3: 签约; 4: 解雇; 5: 入驻;6: 召回;7: 驱赶;8: 举报; 9:通过好友申请;10:成为好友}
  139. * exBossUid : 抢夺成功时,前任老板的uid
  140. */
  141. GameEvent.on(GameNotificationKey.NoticeRoleOpt, this, (targetUid, opt, exBossUid) => {
  142. let payload = {
  143. roleOptMessage: {
  144. targetUid: targetUid,
  145. opt: opt
  146. },
  147. type: 3
  148. }
  149. //抢夺成功时,需要加上前任老板的uid
  150. if (opt == 2) {
  151. payload.roleOptMessage['exBossUid'] = exBossUid
  152. }
  153. let msg = Message.create(payload);
  154. let buffer = Message.encode(msg).finish()
  155. console.log('[Send msg]: ', msg);
  156. ws.send(buffer);
  157. });
  158. })
  159. ws.on('message', (data) => {
  160. let u8Arr = new Uint8Array(data)
  161. let decodeMsg = Message.decode(u8Arr);
  162. console.log("[Response msg type]: ", decodeMsg.type);
  163. console.log("[Response text msg]: ", decodeMsg);
  164. if (decodeMsg.type == 0) {
  165. this.toastNotification(decodeMsg.msg);//成为我的老板,我的艺人,我的好友主界面toast提醒。
  166. }
  167. if (decodeMsg.notificationMessage) {
  168. switch (decodeMsg.notificationMessage.nType) {
  169. case 1:
  170. // 普通通知
  171. this.toggleNoticePoint('notice', true);
  172. this.toastNotification(decodeMsg.notificationMessage);
  173. break;
  174. case 2:
  175. // 好友列表通知
  176. GameEvent.fire(GameNotificationKey.RefreshFriendList);
  177. // this.levelHome.init(Global.user.uid, Global.cityId);
  178. break;
  179. case 3:
  180. // Tab整合了, 不用单独刷新艺人了
  181. GameEvent.fire(GameNotificationKey.RefreshFriendList);
  182. break;
  183. case 4:
  184. // 用户家园建筑列表通知,刷新首页数据
  185. GameEvent.fire(GameNotificationKey.ReloadLevelHomeData)
  186. break;
  187. case 5:
  188. // 任务大厅通知
  189. this.toggleNoticePoint('quest', true)
  190. break;
  191. default:
  192. break;
  193. }
  194. }
  195. if (decodeMsg.buildingItems) {
  196. console.log(decodeMsg.buildingItems);
  197. GameEvent.fire(GameNotificationKey.ReceiveLevelHomeItemPropUpdate, decodeMsg.buildingItems);
  198. }
  199. })
  200. ws.on('close', () => {
  201. GameEvent.off(GameNotificationKey.NoticeRoleOpt, this);
  202. })
  203. ws.on('error', () => {
  204. GameEvent.off(GameNotificationKey.NoticeRoleOpt, this);
  205. })
  206. },
  207. _initFSM() {
  208. let self = this
  209. let gameFSM = StateMachine.factory({
  210. init: 'levelhome',
  211. transitions: [
  212. { name: 'visitfriend', from: ['levelhome', 'userinfo', 'friendhome'], to: 'friendhome' },
  213. { name: 'showuserinfo', from: ['levelhome', 'friendhome'], to: 'userinfo' },
  214. { name: 'visitcitymap', from: 'levelhome', to: 'citymap' },
  215. { name: 'visitcity', from: 'citymap', to: 'levelhome' },
  216. { name: 'changejob', from: '', to: '' }
  217. ],
  218. methods: {
  219. onBeforeVisitcity(lifecycle, cid) {
  220. //新城市初始化所有状态
  221. self.levelHome.init(Global.user.uid, cid);
  222. },
  223. onVisitfriend(lifecycle, uid) {
  224. //如果是friendhome状态之间跳转,则不切换右下方操作区域UI
  225. let toggleTop = true, toggleBottom = cc.Node;
  226. if (lifecycle.from == "friendhome") {
  227. self._onLeaveFriendhome(toggleTop, toggleBottom)
  228. self._onEnterFriendhome(uid, toggleTop, toggleBottom)
  229. }
  230. self._closeFriendSystem();
  231. self.setMapIconVisible(false);
  232. },
  233. onShowuserinfo() {
  234. },
  235. onVisitcitymap() {
  236. },
  237. onEnterFriendhome(lifecycle, uid) {
  238. self._onEnterFriendhome(uid)
  239. },
  240. onLeaveFriendhome() {
  241. self._onLeaveFriendhome()
  242. },
  243. onEnterLevelhome() {
  244. self.setMapIconVisible(true);
  245. self._onEnterLevelhome()
  246. },
  247. onLeaveLevelhome() {
  248. self._onLeaveLevelhome()
  249. },
  250. onEnterUserinfo(lifecycle, uid) {
  251. self._enterUserInfo(uid)
  252. self._hideTabbar();
  253. },
  254. onLeaveUserinfo() {
  255. self._showTabbar();
  256. },
  257. onEnterCitymap(lifecycle, showAnim) {
  258. self._onEnterCitymap(showAnim);
  259. },
  260. onLeaveCitymap() {
  261. self._onLeaveCitymap()
  262. }
  263. },
  264. plugins: [
  265. new StateMachineHistory()
  266. ]
  267. })
  268. this.gameFSM = new gameFSM('levelhome')
  269. },
  270. /**
  271. * 进入好友家园
  272. * @param {Number} uid 用户id
  273. * @param {Boolean} showTop 是否显示顶部信息
  274. * @param {Boolean} showBottom 是否显示底部操作栏
  275. */
  276. _onEnterFriendhome(uid, showTop = true, showBottom = true) {
  277. if (uid) {
  278. this.friendHome.initFriend(uid, res => {
  279. this._showFriendUI(showTop, showBottom)
  280. this.friendHome.node.active = true;
  281. })
  282. } else {
  283. this.friendHome.reInitFriend(() => {
  284. this._showFriendUI(showTop, showBottom)
  285. this.friendHome.node.active = true;
  286. });
  287. }
  288. },
  289. /**
  290. * 离开好友家园
  291. * @param {Boolean} hideTop 是否隐藏顶部信息
  292. * @param {Boolean} hideBottom 是否隐藏底部操作栏
  293. */
  294. _onLeaveFriendhome(hideTop = true, hideBottom = true) {
  295. this._hideFriendUI(hideTop, hideBottom)
  296. this.friendHome.node.active = false;
  297. },
  298. /**
  299. * 进入我的家园
  300. */
  301. _onEnterLevelhome() {
  302. this._showHomeUI()
  303. this._showSidebarUI()
  304. // 每次回到Levelhome都会重新请求好友列表
  305. this.myTabBottom.init(this)
  306. if (!this.isFirstLoad) {
  307. this.isFirstLoad = true;
  308. this.transition.active = true;
  309. let actionFade = cc.sequence(cc.fadeOut(2), cc.callFunc(() => {
  310. this.transition.active = false;
  311. }))
  312. this.transition.runAction(actionFade.easing(cc.easeIn(1.5)));
  313. } else {
  314. this.transition.active = true;
  315. this.transition.opacity = 200;
  316. let actionFade = cc.sequence(cc.fadeOut(1), cc.callFunc(() => {
  317. this.transition.active = false;
  318. }))
  319. this.transition.runAction(actionFade.easing(cc.easeIn(1.5)));
  320. }
  321. this.levelHome.node.active = true;
  322. this.refreshActorNoJob();
  323. },
  324. /**
  325. * 离开我的家园
  326. */
  327. _onLeaveLevelhome() {
  328. this._hideHomeUI()
  329. this._hideSidebarUI()
  330. },
  331. /**
  332. * 显示我的家园界面所需UI
  333. * 恢复LevelHome的位置到Canvas场景内
  334. */
  335. _showHomeUI() {
  336. let actionTop = cc.moveBy(0.4, cc.v2(0, -this.myInfoTop.height));
  337. this.myInfoTop.runAction(actionTop);
  338. if (this.talentIcon.enable) {
  339. this.talentIcon.active = true;
  340. }
  341. this.levelHome.node.x = 0;
  342. },
  343. /**
  344. * 隐藏我的家园界面所需UI
  345. * 把LevelHome移出Canvas场景外
  346. */
  347. _hideHomeUI() {
  348. let actionTop = cc.moveBy(0.4, cc.v2(0, this.myInfoTop.height));
  349. this.myInfoTop.runAction(actionTop);
  350. this.talentIcon.active = false;
  351. setTimeout(() => {
  352. this.levelHome.node.x = -800;
  353. }, 200)
  354. },
  355. /**
  356. * 隐藏侧边栏UI
  357. */
  358. _hideSidebarUI() {
  359. let action = cc.moveBy(0.3, cc.v2(this.sidebar.width, 0));
  360. this.sidebar.runAction(action);
  361. },
  362. /**
  363. * 显示侧边栏UI
  364. */
  365. _showSidebarUI() {
  366. let action = cc.moveBy(0.3, cc.v2(-this.sidebar.width, 0));
  367. this.sidebar.runAction(action);
  368. },
  369. /**
  370. * 显示好友家园界面所需UI
  371. * @param {Boolean} showTop 是否显示顶部信息
  372. * @param {Boolean} showBottom 是否显示底部操作栏
  373. */
  374. _showFriendUI(showTop = true, showBottom = true) {
  375. if (showTop) {
  376. let actionTop = cc.moveBy(0.4, cc.v2(0, -this.friendInfoTop.height));
  377. this.friendInfoTop.runAction(actionTop);
  378. }
  379. if (showBottom) {
  380. let actionRight = cc.moveBy(0.4, cc.v2(-270, 0));
  381. this.friendTabBottom.runAction(actionRight);
  382. }
  383. },
  384. /**
  385. * 隐藏好友家园界面所需UI
  386. * @param {Boolean} hideTop 是否隐藏顶部信息
  387. * @param {Boolean} hideBottom 是否隐藏底部操作栏
  388. */
  389. _hideFriendUI(hideTop = true, hideBottom = true) {
  390. if (hideTop) {
  391. let actionTop = cc.moveBy(0.3, cc.v2(0, this.friendInfoTop.height));
  392. this.friendInfoTop.runAction(actionTop);
  393. }
  394. if (hideBottom) {
  395. let actionRight = cc.moveBy(0.3, cc.v2(270, 0));
  396. this.friendTabBottom.runAction(actionRight);
  397. }
  398. },
  399. /**
  400. * 恢复Tab的位置到Canvas场景内
  401. */
  402. _showTabbar() {
  403. this.myTabBottom.x = 0;
  404. },
  405. /**
  406. * 把Tab移出Canvas场景外
  407. */
  408. _hideTabbar() {
  409. setTimeout(() => {
  410. this.myTabBottom.x = -800;
  411. }, 200)
  412. },
  413. /**
  414. * 进入个人信息页
  415. */
  416. _enterUserInfo(uid) {
  417. if (this.userInfo) {
  418. this.userInfo.init(this, uid);
  419. } else {
  420. DWTool.loadResPrefab('./prefabs/user_information')
  421. .then((result) => {
  422. this.userInfo = cc.instantiate(result);
  423. this.userInfo = this.userInfo.getComponent('UserInformation');
  424. this.userInfo.init(this, uid);
  425. }).catch((err) => {
  426. cc.error(err);
  427. });
  428. }
  429. },
  430. _showFriendSystem() {
  431. this.friendSystem.show(this.wechatFriendNode);
  432. },
  433. _closeFriendSystem() {
  434. this.friendSystem.close();
  435. },
  436. /**
  437. * 进入城市地图界面
  438. * @param {Boolean} showAnim 是否播放迁移到新城市的动画
  439. */
  440. _onEnterCitymap(showAnim) {
  441. let self = this;
  442. let devCityId = showAnim ? (Global.devCityId - 1) : Global.devCityId;
  443. if (this.cityMap) {
  444. this.cityMap.show(showAnim, devCityId);
  445. } else {
  446. cc.loader.loadRes('/prefabs/map', cc.Prefab, (error, prefab) => {
  447. if (error === null) {
  448. this.cityMap = cc.instantiate(prefab);
  449. cc.find('Canvas').addChild(this.cityMap);
  450. this.cityMap = this.cityMap.getComponent('CityMapCtrl');
  451. this.cityMap.init(this);
  452. this.cityMap.show(showAnim, devCityId);
  453. } else {
  454. console.log(JSON.stringify(error));
  455. }
  456. });
  457. }
  458. // this._hideLevelHome();
  459. // this.hideLevelHome();
  460. },
  461. /**
  462. * 离开城市地图界面
  463. */
  464. _onLeaveCitymap() {
  465. if (this.cityMap) {
  466. this.cityMap.node.active = false;
  467. }
  468. },
  469. /**
  470. * 查看他人艺人列表
  471. */
  472. showOtherActors() {
  473. DWTool.loadResPrefab('./prefabs/other_artist_list')
  474. .then((result) => {
  475. this._otherActor = cc.instantiate(result);
  476. this._otherActor.getComponent("OtherArtistList").uid = this.friendHome.uid;
  477. this._otherActor.parent = cc.find("Canvas");
  478. }).catch((err) => {
  479. cc.error(err);
  480. });
  481. },
  482. /**
  483. * 关闭他人艺人列表
  484. */
  485. closeOtherActors() {
  486. this._otherActor.destroy();
  487. },
  488. showCompanyMax() {
  489. this.scheduleOnce(() => {
  490. if (Global.devCityId === 1) {
  491. this.showCatFlyAnimation();
  492. this.mapIcon.active = true;
  493. } else {
  494. this.showCompanyMaxAlert();
  495. }
  496. }, 1);
  497. },
  498. showCompanyMaxAlert() {
  499. cc.loader.loadRes('/prefabs/current_company_max', cc.Prefab, (error, prefab) => {
  500. if (error === null) {
  501. let companyMaxAlert = cc.instantiate(prefab);
  502. cc.find('Canvas').addChild(companyMaxAlert);
  503. } else {
  504. console.log(JSON.stringify(error));
  505. }
  506. });
  507. },
  508. //转职
  509. //选择职业
  510. //职业突破页面
  511. showJobPage(type, userInfo, zIndex) {
  512. let self = this;
  513. cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
  514. if (error === null) {
  515. let jobChange = cc.instantiate(prefab);
  516. self.jobChange = jobChange.getComponent('ChangeJob');
  517. self.jobChange.show(type, userInfo, zIndex);
  518. } else {
  519. console.log(JSON.stringify(error));
  520. }
  521. });
  522. },
  523. showChooseJob() {
  524. let self = this;
  525. cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
  526. if (error === null) {
  527. let jobChange = cc.instantiate(prefab);
  528. this.jobChange = jobChange.getComponent('ChangeJob');
  529. this.jobChange.showFromTalent(JobPageType.ChooseJob, self.noJobActors);
  530. } else {
  531. console.log(JSON.stringify(error));
  532. }
  533. });
  534. },
  535. showRank: _.debounce(() => {
  536. AlertManager.showRankPage();
  537. }, 1000, true),
  538. //关闭转职,选择职业,突破页面
  539. closeJobPage() {
  540. this.jobChange.close();
  541. },
  542. showTalentPage() {
  543. this.finder.show();
  544. },
  545. /**
  546. * 是否显示按钮提示
  547. * @param {String} type {'notice': 消息通知, 'quest': '任务大厅通知'}
  548. * @param {Boolean} flag
  549. */
  550. toggleNoticePoint(type, flag) {
  551. let target
  552. switch (type) {
  553. case 'notice':
  554. target = this.noticePoint
  555. break;
  556. case 'quest':
  557. target = this.questPoint
  558. break;
  559. default:
  560. break;
  561. }
  562. if (flag) {
  563. target.active = true
  564. } else {
  565. target.active = false
  566. }
  567. },
  568. showCatFlyAnimation() {
  569. GameEvent.fire(GameNotificationKey.showCatFlyAnimation, this.mapIcon.getPosition());
  570. },
  571. handleCityMap: _.debounce(() => {
  572. GameEvent.fire(GameNotificationKey.ShowCityMap, false);
  573. // GameEvent.fire(GameNotificationKey.showCatFlyAnimation, this.mapIcon.getPosition());
  574. }, 1000, true),
  575. handleShowTalent: _.debounce(() => {
  576. cc.loader.loadRes('/prefabs/talent_mission', cc.Prefab, (error, prefab) => {
  577. if (error === null) {
  578. let mission = cc.instantiate(prefab);
  579. mission = mission.getComponent('TalentMission');
  580. mission.init();
  581. } else {
  582. console.log(JSON.stringify(error));
  583. }
  584. });
  585. }, 1000, true),
  586. handleNoticePopup: _.debounce((event) => {
  587. AlertManager.showNoticePopup();
  588. event.target.getChildByName("notice_point").active = false
  589. }, 1000, true),
  590. handleQuestPopup: _.debounce((event) => {
  591. AlertManager.showQuestPopup();
  592. event.target.getChildByName("notice_point").active = false
  593. }, 1000, true),
  594. handleBack: _.debounce(() => {
  595. GameEvent.fire(GameNotificationKey.HistoryBack)
  596. }, 1000, true),
  597. // 监听事件
  598. _setEventListener() {
  599. GameEvent.on(GameNotificationKey.ShowCityMap, this, (showAnim) => {
  600. this.gameFSM.visitcitymap(showAnim);
  601. // this.showCatFlyAnimation();
  602. });
  603. GameEvent.on(GameNotificationKey.ShowFriendSystem, this, () => {
  604. this._showFriendSystem();
  605. });
  606. GameEvent.on(GameNotificationKey.VisitFriendHome, this, (uid) => {
  607. this.gameFSM.visitfriend(uid)
  608. });
  609. GameEvent.on(GameNotificationKey.HistoryBack, this, () => {
  610. this.gameFSM.historyBack()
  611. })
  612. GameEvent.on(GameNotificationKey.ShowUserInfomation, this, (uid) => {
  613. this.gameFSM.showuserinfo(uid)
  614. });
  615. GameEvent.on(GameNotificationKey.ProcessShareAction, this, this.processShareAction);
  616. GameEvent.on(GameNotificationKey.ShowJobPage, this, this.showJobPage);
  617. GameEvent.on(GameNotificationKey.ShowJobPageFromTalent, this, this.showChooseJob);
  618. GameEvent.on(GameNotificationKey.RefreshFriendList, this, this.refreshActorNoJob);
  619. GameEvent.on(GameNotificationKey.CurrentCompanyMax, this, this.showCompanyMax);
  620. GameEvent.on(GameNotificationKey.afterCatFly, this, this.showCompanyMaxAlert);
  621. GameEvent.on(GameNotificationKey.LevelHomeSpeedUp, this, this.showLevelHomeSpeedUpTips);
  622. },
  623. onDestroy() {
  624. GameEvent.off(GameNotificationKey.ShowFriendSystem, this);
  625. GameEvent.off(GameNotificationKey.VisitFriendHome, this);
  626. GameEvent.off(GameNotificationKey.HistoryBack, this);
  627. GameEvent.off(GameNotificationKey.ProcessShareAction, this);
  628. GameEvent.off(GameNotificationKey.ShowUserInfomation, this);
  629. GameEvent.off(GameNotificationKey.ShowJobChoose, this);
  630. GameEvent.off(GameNotificationKey.ShowJobPage, this);
  631. GameEvent.off(GameNotificationKey.RefreshFriendList, this);
  632. GameEvent.off(GameNotificationKey.ShowJobPageFromTalent, this);
  633. GameEvent.off(GameNotificationKey.ShowCityMap, this);
  634. GameEvent.off(GameNotificationKey.CurrentCompanyMax, this);
  635. GameEvent.off(GameNotificationKey.afterCatFly, this);
  636. GameEvent.on(GameNotificationKey.LevelHomeSpeedUp, this);
  637. },
  638. processShareAction() {
  639. console.log('processShareAction');
  640. if (Global.shareType == ShareAction.ADD_FRIEND) {
  641. let shareUid = Global.shareUid
  642. FriendSystemApi.addFriend(shareUid, () => {
  643. GameEvent.fire('refresh_friend_list');
  644. setTimeout(() => {
  645. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
  646. }, 2500)
  647. });
  648. } else if (Global.shareType == ShareAction.BECOME_ARTIST) {
  649. let shareUid = Global.shareUid
  650. // FriendSystemApi.becomeArtist(shareUid, () => {
  651. // GameEvent.fire('refresh_friend_list');
  652. // setTimeout(() => {
  653. // GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 11);
  654. // }, 2500)
  655. // });
  656. FriendSystemApi.becomeArtistPromise(shareUid)
  657. .then(({ code, data }) => {
  658. console.log('becomeArtist: ', code);
  659. switch (code) {
  660. case 816://成为好友
  661. GameEvent.fire('refresh_friend_list');
  662. setTimeout(() => {
  663. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
  664. }, 2500);
  665. break;
  666. case 817: // 成为对方艺人
  667. GameEvent.fire('refresh_friend_list');
  668. setTimeout(() => {
  669. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 11);
  670. }, 2500);
  671. break;
  672. case 0: //正常
  673. break;
  674. case 4002://异常
  675. break;
  676. }
  677. })
  678. .catch(() => {
  679. });
  680. }
  681. Global.shareUid = -1;
  682. Global.shareType = ShareAction.None;
  683. },
  684. refreshActorNoJob() {
  685. JobApi.actorsNoJob(
  686. (response) => {
  687. if (response.list && !_.isEmpty(response.list) && response.list.length > 0) {
  688. this.chooseJob.active = true;
  689. this.noJobActors = response.list;
  690. } else {
  691. this.chooseJob.active = false;
  692. }
  693. },
  694. (code, msg) => {
  695. // this.chooseJob.active = false;
  696. }
  697. );
  698. },
  699. toastNotification(message) {
  700. if (this.node.active) {
  701. this.toastScript.show(message);
  702. }
  703. },
  704. showLevelHomeSpeedUpTips(name, type) {
  705. if (this.node.active) {
  706. this.levelHomeSpeedUpTips.show(name, type);
  707. }
  708. },
  709. });