Game.js 28 KB

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