Game.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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(pUrl, {
  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. // 关闭好友列表时强制销毁这个节点,不然会出现滚动列表不显示问题
  438. // 国庆节后再做优化处理,暂时先这样
  439. if(!this.friendSystem.node) {
  440. let friendSystem = cc.instantiate(this.friendSystemPrefab);
  441. this.friendSystem = friendSystem.getComponent('FriendSystem');
  442. this.friendSystem.show(this.wechatFriendNode);
  443. } else {
  444. this.friendSystem.show(this.wechatFriendNode);
  445. }
  446. },
  447. _closeFriendSystem() {
  448. this.friendSystem.close();
  449. },
  450. /**
  451. * 进入城市地图界面
  452. * @param {Boolean} showAnim 是否播放迁移到新城市的动画
  453. */
  454. _onEnterCitymap(showAnim) {
  455. let self = this;
  456. let devCityId = showAnim ? (Global.devCityId - 1) : Global.devCityId;
  457. if (this.cityMap) {
  458. this.cityMap.show(showAnim, devCityId);
  459. } else {
  460. this.cityMap = cc.instantiate(this.cityMapPrefab);
  461. cc.find('Canvas').addChild(this.cityMap);
  462. this.cityMap = this.cityMap.getComponent('CityMapCtrl');
  463. this.cityMap.init(this);
  464. this.cityMap.show(showAnim, devCityId);
  465. // cc.loader.loadRes('/prefabs/map', cc.Prefab, (error, prefab) => {
  466. // if (error === null) {
  467. // this.cityMap = cc.instantiate(prefab);
  468. // cc.find('Canvas').addChild(this.cityMap);
  469. // this.cityMap = this.cityMap.getComponent('CityMapCtrl');
  470. // this.cityMap.init(this);
  471. // this.cityMap.show(showAnim, devCityId);
  472. // } else {
  473. // console.log(JSON.stringify(error));
  474. // }
  475. // });
  476. }
  477. // this._hideLevelHome();
  478. // this.hideLevelHome();
  479. },
  480. /**
  481. * 离开城市地图界面
  482. */
  483. _onLeaveCitymap() {
  484. if (this.cityMap) {
  485. this.cityMap.node.active = false;
  486. }
  487. },
  488. /**
  489. * 查看他人艺人列表
  490. */
  491. showOtherActors() {
  492. DWTool.loadResPrefab('./prefabs/other_artist_list')
  493. .then((result) => {
  494. this._otherActor = cc.instantiate(result);
  495. this._otherActor.getComponent("OtherArtistList").uid = this.friendHome.uid;
  496. this._otherActor.parent = cc.find("Canvas");
  497. }).catch((err) => {
  498. cc.error(err);
  499. });
  500. },
  501. /**
  502. * 关闭他人艺人列表
  503. */
  504. closeOtherActors() {
  505. this._otherActor.destroy();
  506. },
  507. showCompanyMax() {
  508. this.scheduleOnce(() => {
  509. if (Global.devCityId === 1) {
  510. this.showCatFlyAnimation();
  511. this.mapIcon.active = true;
  512. } else {
  513. this.showCompanyMaxAlert();
  514. }
  515. }, 1);
  516. },
  517. showCompanyMaxAlert() {
  518. cc.loader.loadRes('/prefabs/current_company_max', cc.Prefab, (error, prefab) => {
  519. if (error === null) {
  520. let companyMaxAlert = cc.instantiate(prefab);
  521. cc.find('Canvas').addChild(companyMaxAlert);
  522. } else {
  523. console.log(JSON.stringify(error));
  524. }
  525. });
  526. },
  527. //转职
  528. //选择职业
  529. //职业突破页面
  530. showJobPage(type, userInfo, zIndex) {
  531. let self = this;
  532. cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
  533. if (error === null) {
  534. let jobChange = cc.instantiate(prefab);
  535. self.jobChange = jobChange.getComponent('ChangeJob');
  536. self.jobChange.show(type, userInfo, zIndex);
  537. } else {
  538. console.log(JSON.stringify(error));
  539. }
  540. });
  541. },
  542. showChooseJob() {
  543. let self = this;
  544. cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
  545. if (error === null) {
  546. let jobChange = cc.instantiate(prefab);
  547. this.jobChange = jobChange.getComponent('ChangeJob');
  548. this.jobChange.showFromTalent(JobPageType.ChooseJob, self.noJobActors);
  549. } else {
  550. console.log(JSON.stringify(error));
  551. }
  552. });
  553. },
  554. showRank: _.debounce(() => {
  555. AlertManager.showRankPage();
  556. }, 1000, true),
  557. //关闭转职,选择职业,突破页面
  558. closeJobPage() {
  559. this.jobChange.close();
  560. },
  561. showTalentPage() {
  562. this.finder.show();
  563. },
  564. /**
  565. * 是否显示按钮提示
  566. * @param {String} type {'notice': 消息通知, 'quest': '任务大厅通知'}
  567. * @param {Boolean} flag
  568. */
  569. toggleNoticePoint(type, flag) {
  570. let target
  571. switch (type) {
  572. case 'notice':
  573. target = this.noticePoint
  574. break;
  575. case 'quest':
  576. target = this.questPoint
  577. break;
  578. default:
  579. break;
  580. }
  581. if (flag) {
  582. target.active = true
  583. } else {
  584. target.active = false
  585. }
  586. },
  587. showCatFlyAnimation() {
  588. GameEvent.fire(GameNotificationKey.showCatFlyAnimation, this.mapIcon.getPosition());
  589. },
  590. handleCityMap: _.debounce(() => {
  591. GameEvent.fire(GameNotificationKey.ShowCityMap, false);
  592. // GameEvent.fire(GameNotificationKey.showCatFlyAnimation, this.mapIcon.getPosition());
  593. }, 1000, true),
  594. handleShowTalent: _.debounce(() => {
  595. GameEvent.fire('TalentIconPoint');
  596. cc.loader.loadRes('/prefabs/talent_mission', cc.Prefab, (error, prefab) => {
  597. if (error === null) {
  598. let mission = cc.instantiate(prefab);
  599. mission = mission.getComponent('TalentMission');
  600. mission.init();
  601. } else {
  602. console.log(JSON.stringify(error));
  603. }
  604. });
  605. }, 1000, true),
  606. handleNoticePopup: _.debounce((event) => {
  607. AlertManager.showNoticePopup();
  608. event.target.getChildByName("notice_point").active = false
  609. }, 1000, true),
  610. handleQuestPopup: _.debounce((event) => {
  611. AlertManager.showQuestPopup();
  612. event.target.getChildByName("notice_point").active = false
  613. }, 1000, true),
  614. handleBack: _.debounce(() => {
  615. GameEvent.fire(GameNotificationKey.HistoryBack)
  616. }, 1000, true),
  617. // 监听事件
  618. _setEventListener() {
  619. GameEvent.on(GameNotificationKey.ShowCityMap, this, (showAnim) => {
  620. this.gameFSM.visitcitymap(showAnim);
  621. // this.showCatFlyAnimation();
  622. });
  623. GameEvent.on(GameNotificationKey.ShowFriendSystem, this, () => {
  624. this._showFriendSystem();
  625. });
  626. GameEvent.on(GameNotificationKey.VisitFriendHome, this, (uid) => {
  627. this.gameFSM.visitfriend(uid)
  628. });
  629. GameEvent.on(GameNotificationKey.HistoryBack, this, () => {
  630. this.gameFSM.historyBack()
  631. })
  632. GameEvent.on(GameNotificationKey.ShowUserInfomation, this, (uid) => {
  633. this.gameFSM.showuserinfo(uid)
  634. });
  635. GameEvent.on(GameNotificationKey.ProcessShareAction, this, this.processShareAction);
  636. GameEvent.on(GameNotificationKey.ShowJobPage, this, this.showJobPage);
  637. GameEvent.on(GameNotificationKey.ShowJobPageFromTalent, this, this.showChooseJob);
  638. GameEvent.on(GameNotificationKey.RefreshFriendList, this, this.refreshActorNoJob);
  639. GameEvent.on(GameNotificationKey.CurrentCompanyMax, this, this.showCompanyMax);
  640. GameEvent.on(GameNotificationKey.afterCatFly, this, this.showCompanyMaxAlert);
  641. GameEvent.on(GameNotificationKey.LevelHomeSpeedUp, this, this.showLevelHomeSpeedUpTips);
  642. GameEvent.on('TalentIconPoint', this, this.hideTanlentPoint);
  643. },
  644. onDestroy() {
  645. GameEvent.off(GameNotificationKey.ShowFriendSystem, this);
  646. GameEvent.off(GameNotificationKey.VisitFriendHome, this);
  647. GameEvent.off(GameNotificationKey.HistoryBack, this);
  648. GameEvent.off(GameNotificationKey.ProcessShareAction, this);
  649. GameEvent.off(GameNotificationKey.ShowUserInfomation, this);
  650. GameEvent.off(GameNotificationKey.ShowJobChoose, this);
  651. GameEvent.off(GameNotificationKey.ShowJobPage, this);
  652. GameEvent.off(GameNotificationKey.RefreshFriendList, this);
  653. GameEvent.off(GameNotificationKey.ShowJobPageFromTalent, this);
  654. GameEvent.off(GameNotificationKey.ShowCityMap, this);
  655. GameEvent.off(GameNotificationKey.CurrentCompanyMax, this);
  656. GameEvent.off(GameNotificationKey.afterCatFly, this);
  657. GameEvent.off(GameNotificationKey.LevelHomeSpeedUp, this);
  658. GameEvent.off('TalentIconPoint', this);
  659. },
  660. processShareAction() {
  661. console.log('processShareAction');
  662. if (Global.shareType == ShareAction.ADD_FRIEND) {
  663. let shareUid = Global.shareUid
  664. FriendSystemApi.addFriend(shareUid, () => {
  665. GameEvent.fire('refresh_friend_list');
  666. setTimeout(() => {
  667. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
  668. }, 2500)
  669. });
  670. } else if (Global.shareType == ShareAction.BECOME_ARTIST) {
  671. let shareUid = Global.shareUid
  672. // FriendSystemApi.becomeArtist(shareUid, () => {
  673. // GameEvent.fire('refresh_friend_list');
  674. // setTimeout(() => {
  675. // GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 11);
  676. // }, 2500)
  677. // });
  678. FriendSystemApi.becomeArtistPromise(shareUid)
  679. .then(({ code, data }) => {
  680. console.log('becomeArtist: ', code);
  681. switch (code) {
  682. case 816://成为好友
  683. GameEvent.fire('refresh_friend_list');
  684. setTimeout(() => {
  685. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
  686. }, 2500);
  687. break;
  688. case 817: // 成为对方艺人
  689. GameEvent.fire('refresh_friend_list');
  690. setTimeout(() => {
  691. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 11);
  692. }, 2500);
  693. break;
  694. case 0: //正常
  695. break;
  696. case 4002://异常
  697. break;
  698. }
  699. })
  700. .catch(() => {
  701. });
  702. }
  703. Global.shareUid = -1;
  704. Global.shareType = ShareAction.None;
  705. },
  706. hideTanlentPoint() {
  707. this.talentPoint.active = false;
  708. },
  709. refreshActorNoJob() {
  710. JobApi.actorsNoJob(
  711. (response) => {
  712. if (response.list && !_.isEmpty(response.list) && response.list.length > 0) {
  713. this.chooseJob.active = true;
  714. this.noJobActors = response.list;
  715. } else {
  716. this.chooseJob.active = false;
  717. }
  718. },
  719. (code, msg) => {
  720. // this.chooseJob.active = false;
  721. }
  722. );
  723. },
  724. toastNotification(message) {
  725. if (this.node.active) {
  726. this.toastScript.show(message);
  727. }
  728. },
  729. showLevelHomeSpeedUpTips(name, type) {
  730. if (this.node.active) {
  731. this.levelHomeSpeedUpTips.show(name, type);
  732. }
  733. },
  734. });