123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- // 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: {
-
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- GameEvent.on('store_buy_coin_updateDiamond', this, () => {
- /// 说明前面没有这个商品
- if (this._diamondShopCoinTime === 0) {
- let objc2 = {'n': 2, 'e': 0};
- GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, objc2);
- GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, objc2);
- let objct = {'cdTime': 15 * 60 * 1000, 'desc': '所有金币产量增加2倍,持续15分钟', 'icon': 900004, 'sId': 12, 'type': 1};
- GameGlobal._timeInformations.push(objct);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- } 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.schedule(this.timeAction, 1);
- }
-
- });
- GameModule.userInfo.shop = this;
- 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();
- },
- /// 看是否需要添加定时器
- 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];
- }
- AlertManager.showCommonAlert(iconPath, desc, shop.name);
- /// 如果商品id小于等于0什么都不做
- if (shop.shopId > 0) {
- this.reportShop(shop.shopId);
- }
- }
- /// 如果有时间并且有cd剩余时间
- if (shop.minuteTime > 0 && shop.cdTime > 0) {
- if(shop.shopId == 12) {
- this._diamondShopCoinTime = shop.cdTime / 1000;
- } else {
- this._useTimeArr.push(shop.cdTime / 1000);
- this._mtArr.push(shop.mt);
- }
- GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': shop.mt});
- GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': shop.mt});
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- /// 说明是礼包类型
- if (shop.type == 4) {
- GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': shop.mt});
- GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': shop.mt});
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- //// 如果是长按点击的商品
- if (shop.shopId == 4) {
- GameGlobal.isLongPressClick = true;
- }
- },
- /// 处理商品的信息流信息
- handleShpDataToMessageList(shopData) {
- /// 如果有时间并且有cd剩余时间
- if (shopData.minuteTime > 0 && shopData.cdTime > 0) {
- let desc = shopData.desc + '';
- let shopObjc = {'cdTime': shopData.cdTime * 1000, 'desc': 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, 'desc': '获得' + shopData.name, '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) {
- GameModule.userInfo.perpetualMt = TapTapTool.multiple(GameModule.userInfo.perpetualMt, {'e': 0, 'n': 0.5});
- GameModule.userInfo.perpetualClickMt = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': 0.5});
- GameModule.skill.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- }
- }
- for (let i = 0; i < newArr.length; ++i) {
- this._useTimeArr[i] -= 1;
- if (this._useTimeArr[0] <= 0) {
- GameModule.userInfo.perpetualMt = TapTapTool.division(GameModule.userInfo.perpetualMt, {'e': 0, 'n': this._mtArr[i]});
- GameModule.userInfo.perpetualClickMt = TapTapTool.division(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': this._mtArr[i]});
- 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) {},
- });
|