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"; import AESUtil from "../../../AESUtil" import ATSDK from "../../../AnyThinkAds/ATJSSDK"; import ATRewardedVideoSDK from "../../../AnyThinkAds/ATRewardedVideoJSSDK"; import AAJS2 from "../../../ATAndroidJS2"; import GlobalManager from '../../../GlobalManager'; 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); this.initAdForPage(); } initAdForPage() { if (cc.sys.os === cc.sys.OS_ANDROID) { let deviceId = AAJS2.getDeviceUserId(); console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId())); var setting = {}; setting[ATRewardedVideoSDK.userIdKey] = deviceId; ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting); } } 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('超市-立即搜刮') if(2>1){//zh:diy if (cc.sys.os === cc.sys.OS_ANDROID) { GlobalManager.getInstance().registerMethod('doSearchForAdEvent', this.doSearchForAdEvent.bind(this)); let adKey = "zh_ad_type" if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) { cc.sys.localStorage.setItem(adKey, 'doSearchForAdEvent'); console.log('zh:AD ready for idx2') ATRewardedVideoSDK.showAd(AAJS2.getPlacementId()); } else { console.log('zh:AD not ready for idx2') self.doSearchForAdEvent(); } }else{ self.doSearchForAdEvent(); } return; } //下面是原始的代码 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(); } //AD zh public doSearchForAdEvent() { console.log('zh: doSearchForAdEvent 被触发' ) 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; } } } } }