123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 |
- const GameModule = require("./utils/GameModule");
- const FriendSystemApi = require('./net/FriendSystemApi');
- const ShareAction = require('./utils/ShareAction');
- const DWTool = require('./utils/DWTool');
- const DWAlert = require('./utils/DWAlert');
- const HomeApi = require("./net/HomeApi");
- const JobApi = require('./net/JobApi');
- const { GameNotificationKey, SenceMap, JobPageType } = require('./utils/GameEnum');
- const AlertManager = require('./utils/AlertManager');
- const tutorial = require('./utils/Bundle').tutorial;
- const StateMachine = require('./lib/StateMachine');
- const StateMachineHistory = require('./lib/StateMachineHistory');
- const WsManager = require('./net/Ws');
- cc.Class({
- extends: cc.Component,
- properties: {
- levelHomePrefab: cc.Prefab,
- levelFriendHomePrefab: cc.Prefab,
- wechatFriendNode: cc.Node,
-
- userInfoPrefab: cc.Prefab,
- myInfoTop: cc.Node,
- myTabBottom: cc.Node,
- friendInfoTop: cc.Node,
- friendTabBottom: cc.Node,
- _otherActor: cc.Node,
- friendSystemPrefab: cc.Prefab,
- friendHeadSprite: cc.Sprite,
- talentPagePrefab: cc.Prefab,
- noticePoint: cc.Node,
- chooseJob: cc.Node,
- transition: cc.Node,
- mapIcon: cc.Node,
- homeGuide: cc.Node
- },
- onLoad() {
- GameModule.game = this.node;
- this.homeGuide.zIndex = 99;
- GameModule.homeGuide = this.homeGuide;
-
- GameEvent.init();
-
- let levelHome = cc.instantiate(this.levelHomePrefab);
- levelHome = levelHome.getComponent('LevelHome');
- levelHome.init(Global.user.uid, Global.devCityId);
- this.levelHome = levelHome;
-
- let friendSystem = cc.instantiate(this.friendSystemPrefab);
- this.friendSystem = friendSystem.getComponent('FriendSystem');
-
- let friendHome = cc.instantiate(this.levelFriendHomePrefab);
- friendHome = friendHome.getComponent('LevelFriendHome')
- this.friendHome = friendHome;
-
- let breakOut = "";
- this.breakOut = breakOut;
-
-
-
-
- this.finder = cc.instantiate(this.talentPagePrefab);
- this.finder = this.finder.getComponent('TalentPage');
-
- this.homeGuide = this.homeGuide.getComponent('HomeGuide')
- this.homeGuide.init(this)
-
-
-
-
-
- this._setEventListener();
-
- this._initFSM()
-
- this._initSocketMng();
- if (Global.shareUid != -1) {
- console.log('shareUid: ' + Global.shareUid);
- this.processShareAction();
- }
- this.friendHeadSprite.node.on(cc.Node.EventType.TOUCH_END, () => {
- GameEvent.fire(GameNotificationKey.ShowUserInfomation, this.friendHome.uid);
- }, this);
- this.setMapIconVisible(true);
-
-
-
-
- },
- setMapIconVisible(visible) {
- if (Global.devCityId > 1) {
- this.mapIcon.active = visible;
- } else {
- this.mapIcon.active = false;
- }
- },
- updateUIState(state) {
- if (!!state['state6'].pass) {
- if (!this.myTabBottom.active) {
- this.myTabBottom.active = true
- let actionBottom = cc.moveBy(0.4, cc.v2(0, this.myTabBottom.height + 27));
- this.myTabBottom.runAction(actionBottom);
- }
- }
- },
- _initSocketMng() {
- let ja0ckUrl = `ws://172.16.15.170:8108/connect?uid=${Global.user.uid}&token=${Global.user.token}&channel=LuciferChannel&ver=1&os=1`
- let testUrl = `wss://test-message-allstar.duowan.com/connect?uid=${Global.user.uid}&token=${Global.user.token}&channel=LuciferChannel&ver=1&os=1`
- let saUrl = "ws://172.16.12.245:3000"
- let Message = tutorial.Message;
- let ws = new WsManager(testUrl, {
- binaryType: 'arraybuffer',
- autoConnect: true,
- reconnection: true,
- reconnectionDelay: 3000,
- reconnectionAttempts: 5
- })
- let seq = 1;
- ws.on('open', (res) => {
-
- GameEvent.on(GameNotificationKey.NoticeRoleOpt, this, (targetUid, opt, exBossUid) => {
- let payload = {
- roleOptMessage: {
- targetUid: targetUid,
- opt: opt
- },
- type: 3
- }
-
- if (opt == 2) {
- payload.roleOptMessage['exBossUid'] = exBossUid
- }
- let msg = Message.create(payload);
- let buffer = Message.encode(msg).finish()
- console.log('[Send msg]: ', msg);
- ws.send(buffer);
- });
- })
- ws.on('message', (data) => {
- let u8Arr = new Uint8Array(data)
- let decodeMsg = Message.decode(u8Arr);
- console.log("[Response text msg]: ", decodeMsg);
- if (decodeMsg.notificationMessage) {
- switch (decodeMsg.notificationMessage.nType) {
- case 1:
-
- this.toggleNoticePoint(true)
- break;
- case 2:
-
- GameEvent.fire(GameNotificationKey.RefreshFriendList)
-
- break;
- case 3:
-
- GameEvent.fire(GameNotificationKey.RefreshArtistManagerList)
- break;
- case 4:
-
- GameEvent.fire(GameNotificationKey.ReloadLevelHomeData)
- break;
- default:
- break;
- }
- }
- })
- ws.on('close', () => {
- GameEvent.off(GameNotificationKey.NoticeRoleOpt, this);
- })
- ws.on('error', () => {
- GameEvent.off(GameNotificationKey.NoticeRoleOpt, this);
- })
- },
- _initFSM() {
- let self = this
- let gameFSM = StateMachine.factory({
- init: 'levelhome',
- transitions: [
- { name: 'visitfriend', from: ['levelhome', 'userinfo', 'friendhome'], to: 'friendhome' },
- { name: 'showuserinfo', from: ['levelhome', 'friendhome'], to: 'userinfo' },
- { name: 'visitcitymap', from: 'levelhome', to: 'citymap' },
- { name: 'visitcity', from: 'citymap', to: 'levelhome' },
- { name: 'changejob', from: '', to: '' }
- ],
- methods: {
- onBeforeVisitcity(lifecycle, cid) {
-
- self.levelHome.init(Global.user.uid, cid);
- },
- onVisitfriend(lifecycle, uid) {
-
- let toggleTop = true, toggleBottom = cc.Node;
- if (lifecycle.from == "friendhome") {
- self._onLeaveFriendhome(toggleTop, toggleBottom)
- self._onEnterFriendhome(uid, toggleTop, toggleBottom)
- }
- self._closeFriendSystem();
- self.setMapIconVisible(false);
- },
- onShowuserinfo() {
- },
- onVisitcitymap() {
- },
- onEnterFriendhome(lifecycle, uid) {
- self._onEnterFriendhome(uid)
- },
- onLeaveFriendhome() {
- self._onLeaveFriendhome()
- },
- onEnterLevelhome() {
- self.setMapIconVisible(true);
- self._onEnterLevelhome()
- },
- onLeaveLevelhome() {
- self._onLeaveLevelhome()
- },
- onEnterUserinfo(lifecycle, uid) {
- self._enterUserInfo(uid)
- self._hideTabbar();
- },
- onLeaveUserinfo() {
- self._showTabbar();
- },
- onEnterCitymap(lifecycle, showAnim) {
- self._onEnterCitymap(showAnim);
- },
- onLeaveCitymap() {
- self._onLeaveCitymap()
- }
- },
- plugins: [
- new StateMachineHistory()
- ]
- })
- this.gameFSM = new gameFSM('levelhome')
- },
-
- _onEnterFriendhome(uid, showTop = true, showBottom = true) {
- if (uid) {
- this.friendHome.initFriend(uid, res => {
- this._showFriendUI(showTop, showBottom)
- this.friendHome.node.active = true;
- })
- } else {
- this.friendHome.reInitFriend(() => {
- this._showFriendUI(showTop, showBottom)
- this.friendHome.node.active = true;
- });
- }
- },
-
- _onLeaveFriendhome(hideTop = true, hideBottom = true) {
- this._hideFriendUI(hideTop, hideBottom)
- this.friendHome.node.active = false;
- },
-
- _onEnterLevelhome() {
- this._showHomeUI()
- if (!this.isFirstLoad) {
- this.isFirstLoad = true;
- this.transition.active = true;
- let actionFade = cc.sequence(cc.fadeOut(2), cc.callFunc(() => {
- this.transition.active = false;
- }))
- this.transition.runAction(actionFade.easing(cc.easeIn(1.5)));
- } else {
- this.transition.active = true;
- this.transition.opacity = 200;
- let actionFade = cc.sequence(cc.fadeOut(1), cc.callFunc(() => {
- this.transition.active = false;
- }))
- this.transition.runAction(actionFade.easing(cc.easeIn(1.5)));
- }
- this.levelHome.node.active = true;
- this.refreshActorNoJob();
- },
-
- _onLeaveLevelhome() {
- this._hideHomeUI()
- },
-
- _showHomeUI() {
- let actionTop = cc.moveBy(0.4, cc.v2(0, -this.myInfoTop.height));
- this.myInfoTop.runAction(actionTop);
- this.levelHome.node.x = 0;
- },
-
- _hideHomeUI() {
- let actionTop = cc.moveBy(0.4, cc.v2(0, this.myInfoTop.height));
- this.myInfoTop.runAction(actionTop);
- setTimeout(() => {
- this.levelHome.node.x = -800;
- }, 500)
- },
-
- _showFriendUI(showTop = true, showBottom = true) {
- if (showTop) {
- let actionTop = cc.moveBy(0.4, cc.v2(0, -this.friendInfoTop.height));
- this.friendInfoTop.runAction(actionTop);
- }
- if (showBottom) {
- let actionRight = cc.moveBy(0.4, cc.v2(-270, 0));
- this.friendTabBottom.runAction(actionRight);
- }
- },
-
- _hideFriendUI(hideTop = true, hideBottom = true) {
- if (hideTop) {
- let actionTop = cc.moveBy(0.3, cc.v2(0, this.friendInfoTop.height));
- this.friendInfoTop.runAction(actionTop);
- }
- if (hideBottom) {
- let actionRight = cc.moveBy(0.3, cc.v2(270, 0));
- this.friendTabBottom.runAction(actionRight);
- }
- },
-
- _showTabbar() {
- this.myTabBottom.x = 0;
- },
-
- _hideTabbar() {
- setTimeout(() => {
- this.myTabBottom.x = -800;
- }, 200)
- },
-
- _enterUserInfo(uid) {
- if (this.userInfo) {
- this.userInfo.init(this, uid);
- } else {
- DWTool.loadResPrefab('./prefabs/user_information')
- .then((result) => {
- this.userInfo = cc.instantiate(result);
- this.userInfo = this.userInfo.getComponent('UserInformation');
- this.userInfo.init(this, uid);
- }).catch((err) => {
- cc.error(err);
- });
- }
- },
- _showFriendSystem() {
- this.friendSystem.show(this.wechatFriendNode);
- },
- _closeFriendSystem() {
- this.friendSystem.close();
- },
-
- _onEnterCitymap(showAnim) {
- let self = this;
- let devCityId = showAnim ? Global.devCityId - 1 : Global.devCityId;
- if (this.cityMap) {
- this.cityMap.show(showAnim, devCityId);
- } else {
- cc.loader.loadRes('/prefabs/map', cc.Prefab, (error, prefab) => {
- if (error === null) {
- this.cityMap = cc.instantiate(prefab);
- cc.find('Canvas').addChild(this.cityMap);
- this.cityMap = this.cityMap.getComponent('CityMapCtrl');
- this.cityMap.init(this);
- this.cityMap.show(showAnim, devCityId);
- } else {
- console.log(JSON.stringify(error));
- }
- });
- }
-
-
- },
-
- _onLeaveCitymap() {
- if (this.cityMap) {
- this.cityMap.node.active = false;
- }
- },
-
- showOtherActors() {
- DWTool.loadResPrefab('./prefabs/other_artist_list')
- .then((result) => {
- this._otherActor = cc.instantiate(result);
- this._otherActor.getComponent("OtherArtistList").uid = this.friendHome.uid;
- this._otherActor.parent = cc.find("Canvas");
- }).catch((err) => {
- cc.error(err);
- });
- },
-
- closeOtherActors() {
- this._otherActor.destroy();
- },
- showCompanyMax() {
-
- this.scheduleOnce(() => {
- if (Global.devCityId === 1) {
- this.showCatFlyAnimation();
- this.mapIcon.active = true;
- } else {
- this.showCompanyMaxAlert();
- }
- }, 5);
- },
- showCompanyMaxAlert() {
- cc.loader.loadRes('/prefabs/current_company_max', cc.Prefab, (error, prefab) => {
- if (error === null) {
- let companyMaxAlert = cc.instantiate(prefab);
- cc.find('Canvas').addChild(companyMaxAlert);
- } else {
- console.log(JSON.stringify(error));
- }
- });
- },
-
-
-
- showJobPage(type, userInfo, zIndex) {
- let self = this;
- cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
- if (error === null) {
- let jobChange = cc.instantiate(prefab);
- self.jobChange = jobChange.getComponent('ChangeJob');
- self.jobChange.show(type, userInfo, zIndex);
- } else {
- console.log(JSON.stringify(error));
- }
- });
- },
- showChooseJob() {
- let self = this;
- cc.loader.loadRes('/prefabs/change_job', cc.Prefab, (error, prefab) => {
- if (error === null) {
- let jobChange = cc.instantiate(prefab);
- this.jobChange = jobChange.getComponent('ChangeJob');
- this.jobChange.showFromTalent(JobPageType.ChooseJob, self.noJobActors);
- } else {
- console.log(JSON.stringify(error));
- }
- });
- },
- showRank: _.debounce(() => {
- AlertManager.showRankPage();
- }, 1000, true),
- showMission: _.debounce(() => {
- AlertManager.showQuestPopup();
- }, 1000, true),
-
- closeJobPage() {
- this.jobChange.close();
- },
- showTalentPage() {
- this.finder.show();
- },
-
- toggleNoticePoint(flag) {
- if (flag) {
- this.noticePoint.active = true
- } else {
- this.noticePoint.active = false
- }
- },
- showCatFlyAnimation() {
- GameEvent.fire(GameNotificationKey.showCatFlyAnimation, this.mapIcon.getPosition());
- },
- handleCityMap: _.debounce(() => {
- GameEvent.fire(GameNotificationKey.ShowCityMap, false);
-
- }, 1000, true),
- handleNoticePopup: _.debounce((event) => {
- AlertManager.showNoticePopup();
- event.target.getChildByName("notice_point").active = false
- }, 1000, true),
- handleBack: _.debounce(() => {
- GameEvent.fire(GameNotificationKey.HistoryBack)
- }, 1000, true),
-
- _setEventListener() {
- GameEvent.on(GameNotificationKey.ShowCityMap, this, (showAnim) => {
- this.gameFSM.visitcitymap(showAnim);
-
- });
- GameEvent.on(GameNotificationKey.ShowFriendSystem, this, () => {
- this._showFriendSystem();
- });
- GameEvent.on(GameNotificationKey.VisitFriendHome, this, (uid) => {
- this.gameFSM.visitfriend(uid)
- });
- GameEvent.on(GameNotificationKey.HistoryBack, this, () => {
- this.gameFSM.historyBack()
- })
- GameEvent.on(GameNotificationKey.ShowUserInfomation, this, (uid) => {
- this.gameFSM.showuserinfo(uid)
- });
- GameEvent.on(GameNotificationKey.ProcessShareAction, this, this.processShareAction);
- GameEvent.on(GameNotificationKey.ShowJobPage, this, this.showJobPage);
- GameEvent.on(GameNotificationKey.ShowJobPageFromTalent, this, this.showChooseJob);
- GameEvent.on(GameNotificationKey.RefreshFriendList, this, this.refreshActorNoJob);
- GameEvent.on(GameNotificationKey.CurrentCompanyMax, this, this.showCompanyMax);
- GameEvent.on(GameNotificationKey.afterCatFly, this, this.showCompanyMaxAlert);
- },
- onDestroy() {
- GameEvent.off(GameNotificationKey.ShowFriendSystem, this);
- GameEvent.off(GameNotificationKey.VisitFriendHome, this);
- GameEvent.off(GameNotificationKey.HistoryBack, this);
- GameEvent.off(GameNotificationKey.ProcessShareAction, this);
- GameEvent.off(GameNotificationKey.ShowUserInfomation, this);
- GameEvent.off(GameNotificationKey.ShowJobChoose, this);
- GameEvent.off(GameNotificationKey.ShowJobPage, this);
- GameEvent.off(GameNotificationKey.RefreshFriendList, this);
- GameEvent.off(GameNotificationKey.ShowJobPageFromTalent, this);
- GameEvent.off(GameNotificationKey.ShowCityMap, this);
- GameEvent.off(GameNotificationKey.CurrentCompanyMax, this);
- GameEvent.off(GameNotificationKey.afterCatFly, this);
- },
- processShareAction() {
- console.log('processShareAction');
- if (Global.user != null) {
- if (Global.shareType == ShareAction.ADD_FRIEND) {
- let shareUid = Global.shareUid
- FriendSystemApi.addFriend(shareUid, () => {
- GameEvent.fire('refresh_friend_list');
- setTimeout(() => {
- GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
- }, 2500)
- });
- } else if (Global.shareType == ShareAction.BECOME_ARTIST) {
- let shareUid = Global.shareUid
- FriendSystemApi.becomeArtist(shareUid, () => {
- GameEvent.fire('refresh_friend_list');
- setTimeout(() => {
- GameEvent.fire(GameNotificationKey.NoticeRoleOpt, shareUid, 10);
- }, 2500)
- });
- }
- Global.shareUid = -1;
- Global.shareType = ShareAction.None;
- }
- },
- refreshActorNoJob() {
- JobApi.actorsNoJob(
- (response) => {
- if (response.list && !_.isEmpty(response.list) && response.list.length > 0) {
- this.chooseJob.active = true;
- this.noJobActors = response.list;
- } else {
- this.chooseJob.active = false;
- }
- },
- (code, msg) => {
-
- }
- );
- }
- });
|