Game.js 25 KB

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