123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- // const DWTool = require("../utils/DWTool");
- const AlertManager = require('../utils/AlertManager');
- const StoreApi = require('../net/StoreApi');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const TapTapTool = require("../utils/TapTapTool");
- const GameModule = require("../utils/GameModule");
- var Promise = require('../lib/es6-promise').Promise;
- cc.Class({
- extends: cc.Component,
- properties: {
- _diamondShopCoinTime: 0,
- /// 有时间商品的id数组
- _timeShopIdArr: [],
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.multiple = 1;
- GameModule.shop = this;
- this.handelUserShops();
- this.setUpNotification();
- },
- handelUserShops() {
- let shops = GameGlobal.shops;
- this._mtArr = [];
- this._useTimeArr = [];
- this._diamondShopCoinTime = 0;
- if (shops == undefined || shops.length == 0) {
- return;
- }
- for (let i = 0; i < shops.length; ++ i) {
- let shop = shops[i];
- this.handelShop(shop);
- }
- this.updateTimeSchedule();
- },
- /// 设置通知
- setUpNotification() {
- GameEvent.on('store_buy_coin_updateDiamond', this, (infoDesc) => {
- /// 说明前面没有这个商品
- if (this._diamondShopCoinTime <= 0) {
- this.multiple *= 2;
- if (GameModule.skill !== undefined && GameModule.skill !== null) {
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- let objct = {'cdTime': 15 * 60 * 1000, 'infoDesc': infoDesc, 'icon': 900004, 'sId': 12, 'type': 1};
- GameGlobal._timeInformations.push(objct);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
- } else {
- for(let i = 0; i < GameGlobal._timeInformations.length; ++i) {
- let information = GameGlobal._timeInformations[i];
- if (information.type == 1 && information.sId == 12) {
- information.cdTime += 15 * 60 * 1000;
- break;
- }
- }
- }
- this._diamondShopCoinTime += 15 * 60;
- if (!this._isTimer) {
- this._isTimer = true;
- this.schedule(this.timeAction, 1);
- }
-
- });
- },
- /// 看是否需要添加定时器
- updateTimeSchedule() {
- this._isTimer = false;
- if (this._useTimeArr.length > 0 || this._diamondShopCoinTime > 0) {
- this.schedule(this.timeAction, 1);
- this._isTimer = true;
- }
- },
- ///根据商品信息作出处处理 是否是初始化 如果是初始化那么不做弹窗
- handelShop(shop) {
- /// 没有显示过 那么就显示弹窗
- if (shop.isAlert == 0) {
- let iconPath = './textures/store/' + shop.picId;
- let desc = shop.desc + '';
- let stringArr = desc.split('n');
- if (stringArr.length > 1) {
- desc = stringArr[0] + '<br/>' + stringArr[1];
- }
- /// 如果是每天获取钻石的数量 那么点击确定之后才更新砖石数量
- if (shop.shopId === 0 && shop.diamond !== undefined && shop.diamond > 0) {
- AlertManager.showGetDiamondEveryDayAlert(iconPath, desc, shop.name, shop.diamond);
- } else {
- AlertManager.showCommonAlert(iconPath, desc, shop.name);
- }
- /// 如果商品id小于等于0什么都不做
- if (shop.shopId > 0) {
- this.reportShop(shop.shopId);
- }
- }
- /// 如果有时间并且有cd剩余时间
- if (shop.minuteTime > 0 && shop.cdTime > 0) {
- /// 这个是本地处理不走socket的
- if(shop.shopId == 12) {
- this._diamondShopCoinTime += shop.cdTime / 1000;
- this.multiple *= 2;
- if (GameModule.skill !== undefined && GameModule.skill !== null) {
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- } else {
- let shopIndex = this._timeShopIdArr.indexOf(shop.shopId);
- /// 如果以前没有过当前商品
- if (shopIndex == -1) {
- this._timeShopIdArr.push(shop.shopId);
- this._useTimeArr.push(shop.cdTime / 1000);
- this._mtArr.push(shop.mt);
- this.multiple *= shop.mt;
- if (GameModule.skill !== undefined && GameModule.skill !== null) {
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- /// 以前有过,直接增加时间
- } else {
- /// 说明已经停止使用
- if (this._useTimeArr[shopIndex] <= 0) {
- this.multiple *= shop.mt;
- if (GameModule.skill !== undefined && GameModule.skill !== null) {
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- }
- this._useTimeArr[shopIndex] += shop.cdTime / 1000;
- }
- }
- }
- /// 说明是礼包类型
- if (shop.type == 4 && shop.mt > 0) {
- this.multiple *= shop.mt;
- if (GameModule.skill !== undefined && GameModule.skill !== null) {
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- }
- //// 如果是长按点击的商品
- if (shop.shopId == 4) {
- GameGlobal.isLongPressClick = true;
- }
- },
- /// 处理商品的信息流信息
- handleShpDataToMessageList(shopData) {
- /// 如果有时间并且有cd剩余时间
- let desc = shopData.infoDesc + '';
- if (shopData.minuteTime > 0 && shopData.cdTime > 0) {
- let shopObjc = {'cdTime': shopData.cdTime, 'infoDesc': desc, 'icon': shopData.icon, 'sId': shopData.shopId, 'type': 1};
- GameGlobal._timeInformations.push(shopObjc);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
- /// 说明不是需要时间cd的
- } else {
- let shopObjc = {'cdTime': -6 * 1000, 'infoDesc': desc, 'icon': shopData.icon, 'sId': shopData.shopId, 'type': 1};
- GameGlobal._fixInformations.push(shopObjc);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1);
- }
- },
- timeAction () {
- let newArr = this._useTimeArr.filter((n) => {
- return n > 0;
- })
- if (newArr.length <= 0 && this._diamondShopCoinTime <= 0) {
- this.unschedule(this.timeAction, this);
- this._isTimer = false;
- return;
- }
- if (this._diamondShopCoinTime > 0) {
- this._diamondShopCoinTime -= 1;
- if (this._diamondShopCoinTime <= 0) {
- this.multiple *= 0.5;
- if (this.multiple < 1) {
- this.multiple = 1;
- }
- if (GameModule.skill !== undefined && GameModule.skill !== null) {
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- }
- }
- for (let i = 0; i < newArr.length; ++i) {
- this._useTimeArr[i] -= 1;
- if (this._useTimeArr[0] <= 0) {
- this.multiple *= 1 / this._mtArr[i];
- if (this.multiple < 1) {
- this.multiple = 1;
- }
- if (GameModule.skill !== undefined && GameModule.skill !== null) {
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- }
- }
- },
- reportShop(shopId) {
- return new Promise((resolve, reject) => {
- //// 购买明星
- StoreApi.reportShop(shopId, (respondData) => {
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- });
- },
- // update (dt) {},
- });
|