Game.js 27 KB

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