Game.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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.notificationMessage) {
  165. switch (decodeMsg.notificationMessage.nType) {
  166. case 1:
  167. // 普通通知
  168. this.toggleNoticePoint('notice', true);
  169. this.toastNotification(decodeMsg.notificationMessage);
  170. break;
  171. case 2:
  172. // 好友列表通知
  173. GameEvent.fire(GameNotificationKey.RefreshFriendList);
  174. // this.levelHome.init(Global.user.uid, Global.cityId);
  175. break;
  176. case 3:
  177. // Tab整合了, 不用单独刷新艺人了
  178. GameEvent.fire(GameNotificationKey.RefreshFriendList);
  179. break;
  180. case 4:
  181. // 用户家园建筑列表通知,刷新首页数据
  182. GameEvent.fire(GameNotificationKey.ReloadLevelHomeData)
  183. break;
  184. case 5:
  185. // 任务大厅通知
  186. this.toggleNoticePoint('quest', true)
  187. break;
  188. default:
  189. break;
  190. }
  191. }
  192. if(decodeMsg.buildingItems) {
  193. console.log(decodeMsg.buildingItems);
  194. GameEvent.fire(GameNotificationKey.ReceiveLevelHomeItemPropUpdate, decodeMsg.buildingItems);
  195. }
  196. })
  197. ws.on('close', () => {
  198. GameEvent.off(GameNotificationKey.NoticeRoleOpt, this);
  199. })
  200. ws.on('error', () => {
  201. GameEvent.off(GameNotificationKey.NoticeRoleOpt, this);
  202. })
  203. },
  204. _initFSM() {
  205. let self = this
  206. let gameFSM = StateMachine.factory({
  207. init: 'levelhome',
  208. transitions: [
  209. { name: 'visitfriend', from: ['levelhome', 'userinfo', 'friendhome'], to: 'friendhome' },
  210. { name: 'showuserinfo', from: ['levelhome', 'friendhome'], to: 'userinfo' },
  211. { name: 'visitcitymap', from: 'levelhome', to: 'citymap' },
  212. { name: 'visitcity', from: 'citymap', to: 'levelhome' },
  213. { name: 'changejob', from: '', to: '' }
  214. ],
  215. methods: {
  216. onBeforeVisitcity(lifecycle, cid) {
  217. //新城市初始化所有状态
  218. self.levelHome.init(Global.user.uid, cid);
  219. },
  220. onVisitfriend(lifecycle, uid) {
  221. //如果是friendhome状态之间跳转,则不切换右下方操作区域UI
  222. let toggleTop = true, toggleBottom = cc.Node;
  223. if (lifecycle.from == "friendhome") {
  224. self._onLeaveFriendhome(toggleTop, toggleBottom)
  225. self._onEnterFriendhome(uid, toggleTop, toggleBottom)
  226. }
  227. self._closeFriendSystem();
  228. self.setMapIconVisible(false);
  229. },
  230. onShowuserinfo() {
  231. },
  232. onVisitcitymap() {
  233. },
  234. onEnterFriendhome(lifecycle, uid) {
  235. self._onEnterFriendhome(uid)
  236. },
  237. onLeaveFriendhome() {
  238. self._onLeaveFriendhome()
  239. },
  240. onEnterLevelhome() {
  241. self.setMapIconVisible(true);
  242. self._onEnterLevelhome()
  243. },
  244. onLeaveLevelhome() {
  245. self._onLeaveLevelhome()
  246. },
  247. onEnterUserinfo(lifecycle, uid) {
  248. self._enterUserInfo(uid)
  249. self._hideTabbar();
  250. },
  251. onLeaveUserinfo() {
  252. self._showTabbar();
  253. },
  254. onEnterCitymap(lifecycle, showAnim) {
  255. self._onEnterCitymap(showAnim);
  256. },
  257. onLeaveCitymap() {
  258. self._onLeaveCitymap()
  259. }
  260. },
  261. plugins: [
  262. new StateMachineHistory()
  263. ]
  264. })
  265. this.gameFSM = new gameFSM('levelhome')
  266. },
  267. /**
  268. * 进入好友家园
  269. * @param {Number} uid 用户id
  270. * @param {Boolean} showTop 是否显示顶部信息
  271. * @param {Boolean} showBottom 是否显示底部操作栏
  272. */
  273. _onEnterFriendhome(uid, showTop = true, showBottom = true) {
  274. if (uid) {
  275. this.friendHome.initFriend(uid, res => {
  276. this._showFriendUI(showTop, showBottom)
  277. this.friendHome.node.active = true;
  278. })
  279. } else {
  280. this.friendHome.reInitFriend(() => {
  281. this._showFriendUI(showTop, showBottom)
  282. this.friendHome.node.active = true;
  283. });
  284. }
  285. },
  286. /**
  287. * 离开好友家园
  288. * @param {Boolean} hideTop 是否隐藏顶部信息
  289. * @param {Boolean} hideBottom 是否隐藏底部操作栏
  290. */
  291. _onLeaveFriendhome(hideTop = true, hideBottom = true) {
  292. this._hideFriendUI(hideTop, hideBottom)
  293. this.friendHome.node.active = false;
  294. },
  295. /**
  296. * 进入我的家园
  297. */
  298. _onEnterLevelhome() {
  299. this._showHomeUI()
  300. this._showSidebarUI()
  301. // 每次回到Levelhome都会重新请求好友列表
  302. this.myTabBottom.init(this)
  303. if (!this.isFirstLoad) {
  304. this.isFirstLoad = true;
  305. this.transition.active = true;
  306. let actionFade = cc.sequence(cc.fadeOut(2), cc.callFunc(() => {
  307. this.transition.active = false;
  308. }))
  309. this.transition.runAction(actionFade.easing(cc.easeIn(1.5)));
  310. } else {
  311. this.transition.active = true;
  312. this.transition.opacity = 200;
  313. let actionFade = cc.sequence(cc.fadeOut(1), cc.callFunc(() => {
  314. this.transition.active = false;
  315. }))
  316. this.transition.runAction(actionFade.easing(cc.easeIn(1.5)));
  317. }
  318. this.levelHome.node.active = true;
  319. this.refreshActorNoJob();
  320. },
  321. /**
  322. * 离开我的家园
  323. */
  324. _onLeaveLevelhome() {
  325. this._hideHomeUI()
  326. this._hideSidebarUI()
  327. },
  328. /**
  329. * 显示我的家园界面所需UI
  330. * 恢复LevelHome的位置到Canvas场景内
  331. */
  332. _showHomeUI() {
  333. let actionTop = cc.moveBy(0.4, cc.v2(0, -this.myInfoTop.height));
  334. this.myInfoTop.runAction(actionTop);
  335. if (this.talentIcon.enable) {
  336. this.talentIcon.active = true;
  337. }
  338. this.levelHome.node.x = 0;
  339. },
  340. /**
  341. * 隐藏我的家园界面所需UI
  342. * 把LevelHome移出Canvas场景外
  343. */
  344. _hideHomeUI() {
  345. let actionTop = cc.moveBy(0.4, cc.v2(0, this.myInfoTop.height));
  346. this.myInfoTop.runAction(actionTop);
  347. this.talentIcon.active = false;
  348. setTimeout(() => {
  349. this.levelHome.node.x = -800;
  350. }, 200)
  351. },
  352. /**
  353. * 隐藏侧边栏UI
  354. */
  355. _hideSidebarUI() {
  356. let action = cc.moveBy(0.3, cc.v2(this.sidebar.width, 0));
  357. this.sidebar.runAction(action);
  358. },
  359. /**
  360. * 显示侧边栏UI
  361. */
  362. _showSidebarUI() {
  363. let action = cc.moveBy(0.3, cc.v2(-this.sidebar.width, 0));
  364. this.sidebar.runAction(action);
  365. },
  366. /**
  367. * 显示好友家园界面所需UI
  368. * @param {Boolean} showTop 是否显示顶部信息
  369. * @param {Boolean} showBottom 是否显示底部操作栏
  370. */
  371. _showFriendUI(showTop = true, showBottom = true) {
  372. if (showTop) {
  373. let actionTop = cc.moveBy(0.4, cc.v2(0, -this.friendInfoTop.height));
  374. this.friendInfoTop.runAction(actionTop);
  375. }
  376. if (showBottom) {
  377. let actionRight = cc.moveBy(0.4, cc.v2(-270, 0));
  378. this.friendTabBottom.runAction(actionRight);
  379. }
  380. },
  381. /**
  382. * 隐藏好友家园界面所需UI
  383. * @param {Boolean} hideTop 是否隐藏顶部信息
  384. * @param {Boolean} hideBottom 是否隐藏底部操作栏
  385. */
  386. _hideFriendUI(hideTop = true, hideBottom = true) {
  387. if (hideTop) {
  388. let actionTop = cc.moveBy(0.3, cc.v2(0, this.friendInfoTop.height));
  389. this.friendInfoTop.runAction(actionTop);
  390. }
  391. if (hideBottom) {
  392. let actionRight = cc.moveBy(0.3, cc.v2(270, 0));
  393. this.friendTabBottom.runAction(actionRight);
  394. }
  395. },
  396. /**
  397. * 恢复Tab的位置到Canvas场景内
  398. */
  399. _showTabbar() {
  400. this.myTabBottom.x = 0;
  401. },
  402. /**
  403. * 把Tab移出Canvas场景外
  404. */
  405. _hideTabbar() {
  406. setTimeout(() => {
  407. this.myTabBottom.x = -800;
  408. }, 200)
  409. },
  410. /**
  411. * 进入个人信息页
  412. */
  413. _enterUserInfo(uid) {
  414. if (this.userInfo) {
  415. this.userInfo.init(this, uid);
  416. } else {
  417. DWTool.loadResPrefab('./prefabs/user_information')
  418. .then((result) => {
  419. this.userInfo = cc.instantiate(result);
  420. this.userInfo = this.userInfo.getComponent('UserInformation');
  421. this.userInfo.init(this, uid);
  422. }).catch((err) => {
  423. cc.error(err);
  424. });
  425. }
  426. },
  427. _showFriendSystem() {
  428. this.friendSystem.show(this.wechatFriendNode);
  429. },
  430. _closeFriendSystem() {
  431. this.friendSystem.close();
  432. },
  433. /**
  434. * 进入城市地图界面
  435. * @param {Boolean} showAnim 是否播放迁移到新城市的动画
  436. */
  437. _onEnterCitymap(showAnim) {
  438. let self = this;
  439. let devCityId = showAnim ? (Global.devCityId - 1) : Global.devCityId;
  440. if (this.cityMap) {
  441. this.cityMap.show(showAnim, devCityId);
  442. } else {
  443. cc.loader.loadRes('/prefabs/map', cc.Prefab, (error, prefab) => {
  444. if (error === null) {
  445. this.cityMap = cc.instantiate(prefab);
  446. cc.find('Canvas').addChild(this.cityMap);
  447. this.cityMap = this.cityMap.getComponent('CityMapCtrl');
  448. this.cityMap.init(this);
  449. this.cityMap.show(showAnim, devCityId);
  450. } else {
  451. console.log(JSON.stringify(error));
  452. }
  453. });
  454. }
  455. // this._hideLevelHome();
  456. // this.hideLevelHome();
  457. },
  458. /**
  459. * 离开城市地图界面
  460. */
  461. _onLeaveCitymap() {
  462. if (this.cityMap) {
  463. this.cityMap.node.active = false;
  464. }
  465. },
  466. /**
  467. * 查看他人艺人列表
  468. */
  469. showOtherActors() {
  470. DWTool.loadResPrefab('./prefabs/other_artist_list')
  471. .then((result) => {
  472. this._otherActor = cc.instantiate(result);
  473. this._otherActor.getComponent("OtherArtistList").uid = this.friendHome.uid;
  474. this._otherActor.parent = cc.find("Canvas");
  475. }).catch((err) => {
  476. cc.error(err);
  477. });
  478. },
  479. /**
  480. * 关闭他人艺人列表
  481. */
  482. closeOtherActors() {
  483. this._otherActor.destroy();
  484. },
  485. showCompanyMax() {
  486. this.scheduleOnce(() => {
  487. if (Global.devCityId === 1) {
  488. this.showCatFlyAnimation();
  489. this.mapIcon.active = true;
  490. } else {
  491. this.showCompanyMaxAlert();
  492. }
  493. }, 1);
  494. },
  495. showCompanyMaxAlert() {
  496. cc.loader.loadRes('/prefabs/current_company_max', cc.Prefab, (error, prefab) => {
  497. if (error === null) {
  498. let companyMaxAlert = cc.instantiate(prefab);
  499. cc.find('Canvas').addChild(companyMaxAlert);
  500. } else {
  501. console.log(JSON.stringify(error));
  502. }
  503. });
  504. },
  505. //转职
  506. //选择职业
  507. //职业突破页面
  508. showJobPage(type, userInfo, zIndex) {
  509. let self = this;
  510. cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
  511. if (error === null) {
  512. let jobChange = cc.instantiate(prefab);
  513. self.jobChange = jobChange.getComponent('ChangeJob');
  514. self.jobChange.show(type, userInfo, zIndex);
  515. } else {
  516. console.log(JSON.stringify(error));
  517. }
  518. });
  519. },
  520. showChooseJob() {
  521. let self = this;
  522. cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
  523. if (error === null) {
  524. let jobChange = cc.instantiate(prefab);
  525. this.jobChange = jobChange.getComponent('ChangeJob');
  526. this.jobChange.showFromTalent(JobPageType.ChooseJob, self.noJobActors);
  527. } else {
  528. console.log(JSON.stringify(error));
  529. }
  530. });
  531. },
  532. showRank: _.debounce(() => {
  533. AlertManager.showRankPage();
  534. }, 1000, true),
  535. //关闭转职,选择职业,突破页面
  536. closeJobPage() {
  537. this.jobChange.close();
  538. },
  539. showTalentPage() {
  540. this.finder.show();
  541. },
  542. /**
  543. * 是否显示按钮提示
  544. * @param {String} type {'notice': 消息通知, 'quest': '任务大厅通知'}
  545. * @param {Boolean} flag
  546. */
  547. toggleNoticePoint(type, flag) {
  548. let target
  549. switch (type) {
  550. case 'notice':
  551. target = this.noticePoint
  552. break;
  553. case 'quest':
  554. target = this.questPoint
  555. break;
  556. default:
  557. break;
  558. }
  559. if (flag) {
  560. target.active = true
  561. } else {
  562. target.active = false
  563. }
  564. },
  565. showCatFlyAnimation() {
  566. GameEvent.fire(GameNotificationKey.showCatFlyAnimation, this.mapIcon.getPosition());
  567. },
  568. handleCityMap: _.debounce(() => {
  569. GameEvent.fire(GameNotificationKey.ShowCityMap, false);
  570. // GameEvent.fire(GameNotificationKey.showCatFlyAnimation, this.mapIcon.getPosition());
  571. }, 1000, true),
  572. handleShowTalent: _.debounce(() => {
  573. cc.loader.loadRes('/prefabs/talent_mission', cc.Prefab, (error, prefab) => {
  574. if (error === null) {
  575. let mission = cc.instantiate(prefab);
  576. mission = mission.getComponent('TalentMission');
  577. mission.init();
  578. } else {
  579. console.log(JSON.stringify(error));
  580. }
  581. });
  582. }, 1000, true),
  583. handleNoticePopup: _.debounce((event) => {
  584. AlertManager.showNoticePopup();
  585. event.target.getChildByName("notice_point").active = false
  586. }, 1000, true),
  587. handleQuestPopup: _.debounce((event) => {
  588. AlertManager.showQuestPopup();
  589. event.target.getChildByName("notice_point").active = false
  590. }, 1000, true),
  591. handleBack: _.debounce(() => {
  592. GameEvent.fire(GameNotificationKey.HistoryBack)
  593. }, 1000, true),
  594. // 监听事件
  595. _setEventListener() {
  596. GameEvent.on(GameNotificationKey.ShowCityMap, this, (showAnim) => {
  597. this.gameFSM.visitcitymap(showAnim);
  598. // this.showCatFlyAnimation();
  599. });
  600. GameEvent.on(GameNotificationKey.ShowFriendSystem, this, () => {
  601. this._showFriendSystem();
  602. });
  603. GameEvent.on(GameNotificationKey.VisitFriendHome, this, (uid) => {
  604. this.gameFSM.visitfriend(uid)
  605. });
  606. GameEvent.on(GameNotificationKey.HistoryBack, this, () => {
  607. this.gameFSM.historyBack()
  608. })
  609. GameEvent.on(GameNotificationKey.ShowUserInfomation, this, (uid) => {
  610. this.gameFSM.showuserinfo(uid)
  611. });
  612. GameEvent.on(GameNotificationKey.ProcessShareAction, this, this.processShareAction);
  613. GameEvent.on(GameNotificationKey.ShowJobPage, this, this.showJobPage);
  614. GameEvent.on(GameNotificationKey.ShowJobPageFromTalent, this, this.showChooseJob);
  615. GameEvent.on(GameNotificationKey.RefreshFriendList, this, this.refreshActorNoJob);
  616. GameEvent.on(GameNotificationKey.CurrentCompanyMax, this, this.showCompanyMax);
  617. GameEvent.on(GameNotificationKey.afterCatFly, this, this.showCompanyMaxAlert);
  618. GameEvent.on(GameNotificationKey.LevelHomeSpeedUp, this, this.showLevelHomeSpeedUpTips);
  619. },
  620. onDestroy() {
  621. GameEvent.off(GameNotificationKey.ShowFriendSystem, this);
  622. GameEvent.off(GameNotificationKey.VisitFriendHome, this);
  623. GameEvent.off(GameNotificationKey.HistoryBack, this);
  624. GameEvent.off(GameNotificationKey.ProcessShareAction, this);
  625. GameEvent.off(GameNotificationKey.ShowUserInfomation, this);
  626. GameEvent.off(GameNotificationKey.ShowJobChoose, this);
  627. GameEvent.off(GameNotificationKey.ShowJobPage, this);
  628. GameEvent.off(GameNotificationKey.RefreshFriendList, this);
  629. GameEvent.off(GameNotificationKey.ShowJobPageFromTalent, this);
  630. GameEvent.off(GameNotificationKey.ShowCityMap, this);
  631. GameEvent.off(GameNotificationKey.CurrentCompanyMax, this);
  632. GameEvent.off(GameNotificationKey.afterCatFly, this);
  633. GameEvent.on(GameNotificationKey.LevelHomeSpeedUp, this);
  634. },
  635. processShareAction() {
  636. console.log('processShareAction');
  637. if (Global.shareType == ShareAction.ADD_FRIEND) {
  638. let shareUid = Global.shareUid
  639. FriendSystemApi.addFriend(shareUid, () => {
  640. GameEvent.fire('refresh_friend_list');
  641. setTimeout(() => {
  642. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
  643. }, 2500)
  644. });
  645. } else if (Global.shareType == ShareAction.BECOME_ARTIST) {
  646. let shareUid = Global.shareUid
  647. FriendSystemApi.becomeArtist(shareUid, () => {
  648. GameEvent.fire('refresh_friend_list');
  649. setTimeout(() => {
  650. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
  651. }, 2500)
  652. });
  653. }
  654. Global.shareUid = -1;
  655. Global.shareType = ShareAction.None;
  656. },
  657. refreshActorNoJob() {
  658. JobApi.actorsNoJob(
  659. (response) => {
  660. if (response.list && !_.isEmpty(response.list) && response.list.length > 0) {
  661. this.chooseJob.active = true;
  662. this.noJobActors = response.list;
  663. } else {
  664. this.chooseJob.active = false;
  665. }
  666. },
  667. (code, msg) => {
  668. // this.chooseJob.active = false;
  669. }
  670. );
  671. },
  672. toastNotification(message) {
  673. this.toastScript.show(message);
  674. },
  675. showLevelHomeSpeedUpTips(name, type) {
  676. this.levelHomeSpeedUpTips.show(name, type);
  677. },
  678. });