123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- const HomeApi = require("../net/HomeApi");
- const AlertManager = require('../utils/AlertManager');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const ShareAction = require('../utils/ShareAction');
- const GameModule = require("../utils/GameModule");
- const WsManager = require('../net/Ws');
- const GameRedDot = require('../utils/GameEnum').GameRedDot;
- const TapTapTool = require("../utils/TapTapTool");
- // import DwSdk from "../duowansdk/DwSdk";
- // let debug = false;
- // var objSdk = new DwSdk("点点大明星", debug);
- // // 注册sdk的update事件
- // cc.director.on(cc.Director.EVENT_AFTER_DRAW, objSdk.update);
- cc.Class({
- extends: cc.Component,
- properties: {
- levelHomePrefab: cc.Prefab,
- myInfoTop: cc.Node,
- sidebar: cc.Node,
- clickAddMoney: cc.Prefab,
- additionTipsNode: cc.Node,
- homeGuide: cc.Node,
- storeNode: cc.Node,
- drawNode: cc.Node,
- messageListNode: cc.Node,
- taskRedNode: cc.Node,
- storeRedNode: cc.Node,
- drawRedNode: cc.Node,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.isShowBar = false;
- this._isTimer = false;
- this.winSize = cc.view.getVisibleSize();
- GameGlobal.winSize = this.winSize;
- // 创建一个事件监听实例, 用来实现跨节点监听事件
- GameEvent.init();
- this._setEventListener();
- this._initSocketMng();
- this._getInformation();
- if (CC_WECHATGAME) {
- GameGlobal.wechatScoreKey = GameGlobal.debug ? 'buildingLevel_test' : 'buildingLevel';
- window.wx.postMessage({
- messageType: 5,
- key1: GameGlobal.debug
- });
- window.wx.postMessage({
- messageType: 6,
- winSize: GameGlobal.winSize
- });
- } else if (CC_QQPLAY) {
- if (window.GameStatusInfo) {
- GameStatusInfo.startMs = ((new Date()).getTime()).toString();
- }
- }
- // 引导界面
- this.homeGuide.zIndex = 200;
- GameModule.homeGuide = this.homeGuide;
- this.homeGuide = this.homeGuide.getComponent('HomeGuide');
- this.homeGuide.init();
- cc.debug.setDisplayStats(false);
- //建筑展示
- let levelHome = cc.instantiate(this.levelHomePrefab);
- levelHome = levelHome.getComponent('LevelHome');
- levelHome.init(GameGlobal.user.uid);
- this.levelHome = levelHome;
- this.levelHome.node.active = true;
- let XHeight = 1624;
- console.log('game ======================= ' + this.winSize);
- if (this.winSize.height >= XHeight) {
- this.myInfoTop.height = 200;
- this.sidebar.getComponent(cc.Widget).top = 180;
- this.messageListNode.getComponent(cc.Widget).top = 250 + 30;
- }
- this.additionTipsNode = this.additionTipsNode.getComponent('AdditionTips');
- if (GameGlobal.shareType == ShareAction.SHOW_GROUP_RANK && GameGlobal.shareTicket.length > 0) {
- if (this.homeGuide.guideState.state1.pass) {
- GameEvent.fire(GameNotificationKey.GameShowGroupRank);
- }
- }
- if (GameGlobal.isCheck) {
- this.storeNode.active = false;
- this.drawNode.active = false;
- }
- if (GameGlobal.messageNotice !== undefined && GameGlobal.messageNotice.length > 0) {
- AlertManager.showNoticeAlert(GameGlobal.messageNotice);
- }
- },
- start () {
- if (!this.homeGuide.guideState.state1.pass) {
- // 触发引导系统state1状态
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state1');
- }
- GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state4', 'state5');
- GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state6', 'state7');
- // GameModule.homeGuide.getComponent('HomeGuide').handleState('state31');
- GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state29', 'state31');
- GameModule.homeGuide.on('Fire_state29', this.finishState29, this);
- GameModule.homeGuide.on('Fire_state31', this.handleQuestPopup, this);
- if (this.homeGuide.guideState.state7.pass || this.homeGuide.guideState.state11.pass) {
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state13');
- GameModule.homeGuide.getComponent('HomeGuide').changeGuideTask1315(false);
- if (this.homeGuide.guideState.state13.pass) {
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state15');
- GameModule.homeGuide.getComponent('HomeGuide').changeGuideTask1315(false);
- }
- }
- this._showSidebarUI();
- },
- update (dt) {
- if (GameModule.skill != null && GameModule.skill != undefined && GameModule.skill.isUsingSkill3) {
- GameEvent.fire(GameNotificationKey.PlaySuccessAnimation);
- }
- },
- _setEventListener() {
- GameEvent.on(GameNotificationKey.GameRedDotUpdate, this, this.handelShowRedDot);
- GameEvent.on(GameNotificationKey.GameShowAdditionTips, this, this.showAdditionTips);
- GameEvent.on(GameNotificationKey.GameShowGroupRank, this, this.showGroupRank);
- //// 重连socket
- GameEvent.on(GameNotificationKey.GameShowNotificationKey, this, this._initSocketMng);
- },
- _initSocketMng() {
- let testUrl = 'wss://test-message-taptap.duowan.com/connect';
- // let pUrl = 'wss://new-message-taptap.duowan.com/connect';
- let pUrl = 'wss://message-taptap.duowan.com/connect';
- let socketUrl = GameGlobal.debug ? testUrl : pUrl;
- // let socketUrl = 'ws://172.16.15.196:9099/connect';
- let ws = new WsManager(socketUrl, {
- binaryType: 'arraybuffer',
- autoConnect: true, // 自动连接
- reconnection: true, // 断开自动重连
- reconnectionDelay: 3000, // 重连间隔时间,单位毫秒
- reconnectionAttempts: 5 // 最大重连尝试次数,默认为Infinity
- });
- GameGlobal._wxSocket = ws;
- ws.on('open', (res) => {
- console.log('socket 打开');
- });
- ws.on('message', (data) => {
- let typeStr = typeof data;
- if (typeStr !== 'string' || data.indexOf('type') == -1) {
- return;
- }
- data = JSON.parse(data);
- if (data.type != undefined) {
- // GameGlobal._redTypes = data.type;
- /// 商品购买的通知
- if (data.type.indexOf(1) != -1 && data.userShops.length > 0) {
- let userShops = data.userShops;
- for (let i = 0; i < data.userShops.length; ++ i) {
- let shopData = userShops[i];
- GameModule.userInfo.shop.handelShop(shopData);
- GameModule.userInfo.shop.updateTimeSchedule();
- /// 处理信息流信息
- GameModule.userInfo.shop.handleShpDataToMessageList(shopData);
- /// 说明购买了金币加速器,那么需要发通知告知商城的金币页面重新拉去数据
- if (shopData.shopId == 13 || shopData.shopId == 14 || shopData.shopId == 15) {
- GameEvent.fire('storeCoin_need_update');
- }
- /// 增加商品钻石
- if (shopData.diamond !== undefined && shopData.diamond > 0) {
- GameModule.userInfo.diamond += shopData.diamond;
- }
- if (shopData.type == 4) {
- //// 更新购买明星数量
- GameEvent.fire(GameNotificationKey.GameUpdateStarContentBuyGold);
- }
- }
- return;
- }
- if (TapTapTool.compare(GameGlobal._buyStarGold, GameGlobal.userData.goldObj)) {
- GameGlobal._redTypes.push(GameRedDot.star);
- }
- //// 下面这段代码只是去重,不要重复的更新
- let isContain = false;
- for (let i = 0; i < data.type.length; ++ i) {
- /// 如果包含它就什么都不管
- let type = data.type[i];
- if (GameGlobal._redTypes.indexOf(type) != -1) {
- isContain = true;
- } else {
- GameGlobal._redTypes.push(type);
- isContain = false;
- }
- }
- if (isContain == false) {
- GameEvent.fire(GameNotificationKey.GameRedDotUpdate);
- // this.handelShowRedDot();
- }
- }
- });
- ws.on('close', () => {
- console.log('socket 关闭');
- });
- ws.on('error', () => {
- console.log('sockete 错误');
- });
- },
- /// 获取信息流
- _getInformation() {
- GameGlobal._redTypes = [];
- GameGlobal._timeInformations = [];
- GameGlobal._fixInformations = [];
- GameGlobal._gold10 = {'n': 0, 'e': 0};
- GameGlobal._buyStarGold = {'n': 0, 'e': 0};
- this.getInformation((respondData) => {
- console.log(respondData);
- GameGlobal._gold10 = respondData.gold10;
- GameGlobal._buyStarGold = respondData.buyStarGold;
- GameGlobal._isSkillReset = respondData.isSkillReset;
- if (respondData.types !== undefined) {
- GameGlobal._redTypes = respondData.types;
- }
- if (TapTapTool.compare(GameGlobal.userData.goldObj, respondData.buyStarGold)) {
- GameGlobal._redTypes.push(GameRedDot.star);
- }
- GameEvent.fire(GameNotificationKey.GameRedDotUpdate);
- // this.handelShowRedDot();
- //// 更新信息流数据
- if (respondData.informations !== undefined) {
- GameGlobal._timeInformations = respondData.informations;
- /// 如果是技能可以重置
- // if (respondData.isSkillReset) {
- // /// 添加技能可重置的信息流
- // let objct = {'cdTime': 0, 'desc': '重置技能可使用', 'name': '重置技能', 'icon': 900012, 'sId': 4, 'type': 2, 'skillStatus': 0};
- // GameGlobal._timeInformations.push(objct);
- // }
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, GameGlobal._timeInformations.length);
- }
- }, ({code, msg}) => {
- console.log(code, msg);
- });
- },
- /// 网络请求
- getInformation(success, fail) {
- // 获取目标用户的建筑
- HomeApi.getInformation(success, fail);
- },
- onDestroy() {
- GameEvent.off(GameNotificationKey.GameShowAdditionTips, this);
- GameEvent.off(GameNotificationKey.GameShowGroupRank, this);
- },
- _showSidebarUI() {
- let isOk = false;
- //教程31还没有完成不显示
- if (!this.homeGuide.guideState.state31.pass) {
- // 1. 总部大楼大于25级
- // 2. 已拥有1个明星
- let unLockStatus1 = GameModule.userInfo.buildingLevel >= 25;
- let unLockStatus2 = GameModule.userInfo.buyStarCount > 0;
- if (unLockStatus1 && unLockStatus2) {
- isOk = true
- }
- } else {
- isOk = true;
- }
- if (!isOk) {
- return;
- }
- this.isShowBar = true;
- let action = cc.moveBy(0.3, cc.v2(-this.sidebar.width, 0));
- this.sidebar.runAction(action);
- this.handelShowRedDot();
- },
- finishState29() {
- if (this.isShowBar) {
- return;
- }
- this.isShowBar = true;
- let action = cc.moveBy(0.3, cc.v2(-this.sidebar.width, 0));
- this.sidebar.runAction(action);
- this.handelShowRedDot();
- },
- handelShowRedDot() {
- if (GameGlobal._redTypes == null || GameGlobal._redTypes == undefined || GameGlobal._redTypes.length == 0) {
- this.taskRedNode.active = false;
- this.drawRedNode.active = false;
- this.storeRedNode.active = false;
- return;
- }
- let redTypes = GameGlobal._redTypes;
- this.taskRedNode.active = (redTypes.indexOf(GameRedDot.mainTask) != -1 || redTypes.indexOf(GameRedDot.dayTask) != -1);
- this.drawRedNode.active = redTypes.indexOf(GameRedDot.draw) != -1;
-
- if (this.isShowBar) {
- let isStoreRed = (redTypes.indexOf(GameRedDot.storeDiamond) != -1 || redTypes.indexOf(GameRedDot.storeCoin) != -1);
- this.storeRedNode.active = isStoreRed;
- if (isStoreRed) {
- if (this._isTimer === false) {
- this._isTimer = true;
- this._storeTimeCount = 0;
- this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0))));
- this.schedule(this.storeTimeAction, 6);
- }
- } else {
- if (this._isTimer == true) {
- this.unschedule(this.storeTimeAction, this);
- this._isTimer = false;
- }
- }
- } else {
- if (this._isTimer === true) {
- this.unschedule(this.storeTimeAction, this);
- this._isTimer = false;
- }
- this.storeRedNode.active = false;
- }
-
- },
- /// 商城未读消息的显示
- storeTimeAction() {
- this._storeTimeCount += 1;
- /// 第一个6秒的时候
- if (this._storeTimeCount === 1) {
- this.storeRedNode.active = false;
- } else if (this._storeTimeCount === 6) {
- this.storeRedNode.active = true;
- this._storeTimeCount = 0;
-
- // this.storeRedNode.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.2, 3, 0), cc.moveBy(0.2, -3, 0))));
- }
- },
- //
- handleQuestPopup: _.debounce((event) => {
- AlertManager.showQuestPopup();
- // if (event) {
- // event.target.getChildByName("notice_point").active = false;
- // }
- }, 1000, true),
- //显示抽奖界面
- handleShowDraw: _.debounce((event) => {
- AlertManager.showDrawAlert();
- }, 1000, true),
- //显示商城界面
- handleShowStore: _.debounce((event) => {
- AlertManager.showStoreAlert();
- // GameEvent.fire(GameNotificationKey.StarLeaveRoom, 1, 1);
- // GameEvent.fire(GameNotificationKey.AllStarLeaveRoom);
- }, 1000, true),
- //显示排行榜界面
- handleShowRank: _.debounce((event) => {
- AlertManager.showRankAlert();
- }, 1000, true),
- showGroupRank() {
- AlertManager.showRankAlert(2);
- },
- showAdditionTips(text, type) {
- if (this.node.active) {
- this.additionTipsNode.show(text, type);
- }
- },
- // update (dt) {},
- });
|