const GameModule = require("../utils/GameModule"); const DWTool = require("../utils/DWTool"); const Api = require('../net/Api'); const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const TapTapTool = require("../utils/TapTapTool"); // var cityList = require('../data/city'); // const BuildingModel = require('./utils/BuildingModel'); // const AlertManager = require('./utils/AlertManager'); // const ReportType = require("./utils/GameEnum").ReportType; cc.Class({ extends: cc.Component, properties: { _reportFailDuration: 0, grossIncomeLabel: cc.Label, grossCoin: sp.Skeleton, grossIncomeRichText: cc.RichText, rateRichText: cc.RichText, clickCoinRichText: cc.RichText, rateCoinRichText: cc.RichText, headSprite: cc.Sprite, starsLabel: cc.Label, starsProgress: cc.ProgressBar, diamondLabel: cc.Label, recordModify: [], recordUnlockModify: [], buildingData: [], _stars: 0, stars: { get: function () { return this._stars; }, set: function (value) { console.log('星星增加数 ' + value); this._stars = value; } }, _gold: 0, gold: { get: function () { return this._gold; }, set: function (value) { cc.sys.localStorage.setItem(`localGold_${GameGlobal.user.uid}`, JSON.stringify(this._gold)); this._gold = value; this.grossIncomeRichText.string = `${TapTapTool.parseToString(this._gold)}`; } }, //建筑每秒自动生成的金币数 _rateGold: 0, rateGold: { get: function () { return this._rateGold; }, set: function (value) { this._rateGold = value; if (this._rateGold.n > 0) { this.rateRichText.node.active = true; let rate = TapTapTool.multiple(GameModule.skill.multiple, this.perpetualMt); rate = TapTapTool.multiple(rate, {'n': GameModule.shop.multiple, 'e': 0}); let newValue = TapTapTool.multiple(rate, this._rateGold); this.rateRichText.string = `+${TapTapTool.parseToString(newValue)}`; this.rateCoinRichText.string = `${TapTapTool.parseToString(newValue)}`; } else { this.rateRichText.node.active = false; this.rateCoinRichText.string = "0"; } } }, //自动每次点击需要的秒数 _secondClick: 0, secondClick: { get: function () { return this._secondClick; }, set: function (value) { this._secondClick = value < 0 ? 0 : parseFloat(value); this.unschedule(this.autoClickGetGold, this); if (this._secondClick > 0) { this.schedule(this.autoClickGetGold, this._secondClick); } } }, _diamond: 0, diamond: { get: function () { return this._diamond; }, set: function (value) { this._diamond = value; this.diamondLabel.string = this._diamond; } }, _clickCount: 0, clickCount: { get: function () { return this._clickCount; }, set: function (value) { this._clickCount = value; } }, _buyStarCount: 0, buyStarCount: { get: function () { return this._buyStarCount; }, set: function (value) { this._buyStarCount = value; } }, _buildingLevel: 1, buildingLevel: { get: function () { return this._buildingLevel; }, set: function (value) { this._buildingLevel = value; if (CC_WECHATGAME) { // 把用户的总部等级上报给微信 DWTool.submitWechatScore(this._buildingLevel); } else if (CC_QQPLAY) { // 把用户的总部等级上报给QQ玩一玩 DWTool.submitQQScore(this._buildingLevel); } } }, levelHomeItemFullCount: 0 }, onLoad() { GameModule.userInfo = this; this._rate = 0; this._isPlayAnimation = false; this.seq = 1; this._rateGold = {'n': 0, 'e': 0}; this._gold = {'n': 0, 'e': 0}; this.coinTap = {'n': 0, 'e': 0}; this.buildingLevel = GameGlobal.userData.buildingLevel; // let objc = TapTapTool.goldStrToClass('3.265;29'); // let str = TapTapTool.parseToString(objc); // let sub = TapTapTool.compare({'n': 323, 'e': 25}, objc); // let n = {'n': 423, 'e': 0}; // let m = {'n': 1.1, 'e': 0}; // console.log(TapTapTool.multiple(n, m)); // console.log(sub); // console.log(str); // 初始化用户信息 this.initUserInfo(); // 轮询上报游戏数据 this.reportFunc = () => { if (this._reportFailDuration > 0) { this._reportFailDuration -= 3; return; } this.doReport(); }; this.schedule(this.reportFunc, 3.0); //建筑每秒自动赚的钱 this.addMoneyFunc = () => { this.buildingAddMoney(); }; this.schedule(this.addMoneyFunc, 1.0); this.reportFirst(); }, /** * 每秒增加金币 */ buildingAddMoney() { if (this.rateGold.n > 0) { // this.gold = TapTapTool.add(this.rateGold, this.gold); let add = TapTapTool.multiple(this.rateGold, GameModule.skill.multiple); add = TapTapTool.multiple(add, {'n': GameModule.shop.multiple, 'e': 0}); this.gold = TapTapTool.add(this.gold, TapTapTool.multiple(add, this.perpetualMt)); // this.gold += (this.rateGold * GameModule.skill.multiple * this.perpetualMt); this.secondRateTextAnimation(); } }, secondRateTextAnimation() { let fadeIn = cc.fadeIn(0.2); let delay = cc.delayTime(0.3); let fadeOut = cc.fadeOut(0.3); let action = cc.sequence(fadeIn, delay, fadeOut); this.rateRichText.node.runAction(action); }, refreshSecondText() { if (this._rateGold.n > 0) { this.rateRichText.node.active = true; let rate = TapTapTool.multiple(GameModule.skill.multiple, this.perpetualMt); rate = TapTapTool.multiple(rate, {'n': GameModule.shop.multiple, 'e': 0}); let newValue = TapTapTool.multiple(rate, this._rateGold); this.rateRichText.string = `+${TapTapTool.parseToString(newValue)}`; this.rateCoinRichText.string = `${TapTapTool.parseToString(newValue)}`; } else { this.rateRichText.node.active = false; } if (GameModule.userInfo.coinTap.n > 0) { this.clickCoinRichText.string = `${TapTapTool.parseToString(GameModule.userInfo.coinTap)}`; } else { this.clickCoinRichText.string = "0"; } }, /** * 每秒自动点击次数 */ autoClickGetGold() { GameEvent.fire(GameNotificationKey.AutoClickGold); }, /** * 上报用户数据 */ doReport() { // return; let goldStr = this._gold.n + ";" + this._gold.e; DWTool.reportInfo(this.seq, goldStr, this.stars, this.clickCount, this.recordModify, this.recordUnlockModify, () => { this._reportFailDuration = 0; this.recordModify = []; this.recordUnlockModify = []; this.seq += 1; }, (err) => { if (err.code === -4) { this._reportFailDuration = 60; } console.log('上报失败 ' + err.msg); }) }, reportFirst() { //如果为true则以网络数据为主不用覆盖 if (GameGlobal.localData) { cc.sys.localStorage.removeItem(`localGold_${GameGlobal.user.uid}`); cc.sys.localStorage.removeItem(`localRooms_${GameGlobal.user.uid}`); return; } this.compareRoomsLocalData(); let goldStr = this._gold.n + ";" + this._gold.e; DWTool.reportRoomsInfo(goldStr, this.buildingData); }, /** * 初始化用户数据 */ initUserInfo() { let userInfo = this.userInfo = GameGlobal.userData; if (userInfo != undefined) { let goldObj = this.compareGoldLocalData(); this.updateUserRes({ gold: goldObj, stars: userInfo.ogStars, diamond: userInfo.diamond, ticket: userInfo.ticket, clickCount: userInfo.clickCount }); this.perpetualMt = userInfo.mtObj; this.perpetualClickMt = userInfo.clickMtObj; this.buyStarCount = userInfo.buyStarCount; } }, compareGoldLocalData() { let localGold = cc.sys.localStorage.getItem(`localGold_${GameGlobal.user.uid}`); if (this.userInfo != undefined && localGold!= undefined && localGold && !GameGlobal.localData) { let goldObj = JSON.parse(localGold); if (goldObj != undefined) { return goldObj; } else { return this.userInfo.goldObj; } } else { return this.userInfo.goldObj; } }, compareRoomsLocalData() { let localData = cc.sys.localStorage.getItem(`localRooms_${GameGlobal.user.uid}`); this.buildingData = GameGlobal.BuildingManager.networkRooms; if (this.userInfo != undefined && localData!= undefined && localData && !GameGlobal.localData) { let userRooms = JSON.parse(localData); if (GameGlobal.BuildingManager.networkRooms && GameGlobal.BuildingManager.networkRooms.length > 0 && userRooms.length > 0) { userRooms.forEach(room => { this.buildingData.forEach(n => { if (room.roomId == n.roomId) { n.roomLevel = Math.max(room.level, n.roomLevel); } }); }); } } }, /** * 更新用户资源数据 * @param {object} data 更新资源对象 * @param {number} data.grossIncome 增加的金币 * @param {number} data.stars 星星 * @param {number} data.diamond 钻石 * @param {number} data.ticket 艺人券 */ updateUserRes(data) { // console.log("Update userData: ", JSON.stringify(data)); if (data.gold) { this.gold = TapTapTool.add(data.gold, this.gold); } if (data.stars) { this.stars += parseInt(data.stars); } if (data.diamond) { this.diamond += parseInt(data.diamond); } if (data.ticket) { this.ticket += parseInt(data.ticket); } if (data.clickCount) { this.clickCount += parseInt(data.clickCount); } }, updateRecordModify(buildingInfo) { for (let i = 0; i < this.recordModify.length; i++) { let temp = this.recordModify[i]; if (buildingInfo.roomId == temp.roomId) { this.recordModify.splice(i, 1, buildingInfo); return; } } this.recordModify.push(buildingInfo); } });