Game.js 27 KB

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