123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import auto_shopView from "../../../ui/uidata/Interface/auto_shopView";
- import UIBase from "../../../framework/ui/UIBase";
- import UIHelp from "../../../framework/ui/UIHelp";
- import Utils from "../../../framework/utils/utils";
- import EventManager from "../../../framework/event/EventManager";
- import {EVENT_TYPE} from "../../../gameLogic/utrl/gameEnum";
- import jumpBy = cc.jumpBy;
- import gameData from "../../../gameLogic/utrl/gameData";
- import UIObtainView from "./UIObtainView";
- import rewardDtMgr from "../../../dataManager/rewardDtMgr";
- import itemDtManager from "../../../dataManager/itemDtManager";
- import AccountModel from "../../../data/Account/AccountModel";
- import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
- const {ccclass, menu, property} = cc._decorator;
- const needRefreshTime = 5 * 60;
- const reward_items = [1, 2, 3, 4];
- @ccclass
- @menu("UI/Interface/UIShopView")
- export default class UIShopView extends UIBase {
- ui: auto_shopView = null;
- protected static prefabUrl = "Interface/shopView";
- protected static className = "UIShopView";
- private lastTime = null;
- private cb: Function = null;
- onUILoad() {
- this.ui = this.node.addComponent(auto_shopView);
- }
- onShow() {
- let shopTime = AccountModel.getInstance().shop_time;
- let curTime = Utils.getTimeStamp();
- if (!shopTime) {
- AccountModel.getInstance().shop_time = curTime - needRefreshTime;
- shopTime = AccountModel.getInstance().shop_time;
- }
- let time = needRefreshTime - (curTime - shopTime);
- if (time > 0) {
- this.lastTime = shopTime;
- this.ui.time.getComponent(cc.Label).string = `${Utils.getTime(time)}`;
- this.refreshTime();
- }
- }
- onHide() {
- }
- onStart() {
- }
- refreshTime() {
- this.ui.btn.getComponent(cc.Button).interactable = false;
- this.cb = () => {
- let curTime = Utils.getTimeStamp();
- let time = needRefreshTime - (curTime - this.lastTime);
- if (time <= 0) {
- this.ui.btn.getComponent(cc.Button).interactable = true;
- this.unschedule(this.cb);
- }
- this.ui.time.getComponent(cc.Label).string = `${Utils.getTime(time)}`;
- }
- this.schedule(this.cb, 1);
- }
- clickSearch() {
- let self = this
- zjSdk?.sendEvent('超市-立即搜刮')
- const params = {
- payType: zjSdk?.TYPE.VIDEO,
- success() {
- zjSdk?.sendEvent('超市-成功搜刮')
- self.doSearch();
- },
- fail() {
- // self.doSearch();
- }
- };
- zjSdk?.doPay(params);
- }
- private doSearch() {
- this.lastTime = Utils.getTimeStamp();
- AccountModel.getInstance().shop_time = this.lastTime;
- const count = Utils.random(100, 250);
- const nums = this.getNums(count);
- let all = nums.reduce(function (prev, curr, idx, arr) {
- return prev + curr;
- });
- gameData.curPowerNum += all;
- UIHelp.ShowUI(UIObtainView, null, {ids: reward_items, nums: nums});
- gameEventManager.emit(EVENT_TYPE.OFF_SHOP_TIP);
- this.refreshTime();
- }
- clickClose() {
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false);
- this.onClose();
- }
- onClose() {
- UIHelp.CloseUI(UIShopView);
- }
- /**
- * 求出数量
- * @param count
- * @private
- */
- private getNums(count: number) {
- let nums = [0, 0, 0, 0];
- while (true) {
- for (let i = reward_items.length - 1; i >= 0; i--) {
- const dataByID = itemDtManager.getDataByID(reward_items[i]);
- if (count > dataByID.value) {
- count -= dataByID.value;
- nums[i] += dataByID.value;
- } else if (i == 0) {
- // 比最小值还小
- return nums;
- }
- }
- }
- }
- }
|