123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- 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 = `<outline color=#ffffff width=3><color=#009100>${TapTapTool.parseToString(this._gold)}</c></outline>`;
- }
- },
- //建筑每秒自动生成的金币数
- _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 = `<outline color=#ffffff width=3><color=#009100>+${TapTapTool.parseToString(newValue)}</c></outline>`;
- this.rateCoinRichText.string = `<b>${TapTapTool.parseToString(newValue)}</b>`;
- } else {
- this.rateRichText.node.active = false;
- this.rateCoinRichText.string = "<b>0</b>";
- }
- }
- },
- //自动每次点击需要的秒数
- _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 = `<outline color=#ffffff width=3><color=#009100>+${TapTapTool.parseToString(newValue)}</c></outline>`;
- this.rateCoinRichText.string = `<b>${TapTapTool.parseToString(newValue)}</b>`;
- } else {
- this.rateRichText.node.active = false;
- }
- if (GameModule.userInfo.coinTap.n > 0) {
- this.clickCoinRichText.string = `<b>${TapTapTool.parseToString(GameModule.userInfo.coinTap)}</b>`;
- } else {
- this.clickCoinRichText.string = "<b>0</b>";
- }
- },
- /**
- * 每秒自动点击次数
- */
- 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);
- }
- });
|