import auto_airdropView from "../../../ui/uidata/Interface/auto_airdropView"; import UIBase from "../../../framework/ui/UIBase"; import UIHelp from "../../../framework/ui/UIHelp"; import rewardDtMgr from "../../../dataManager/rewardDtMgr"; import UIAirdropItem from "./UIAirdropItem"; import gameData from "../../../gameLogic/utrl/gameData"; import itemDtManager from "../../../dataManager/itemDtManager"; import gameEventManager from "../../../gameLogic/utrl/gameEventManager"; import {EVENT_TYPE} from "../../../gameLogic/utrl/gameEnum"; import Utils from "../../../framework/utils/utils"; import UIObtainView from "./UIObtainView"; import modelDtlManager from "../../../dataManager/modelDtlManager"; import AccountModel from "../../../data/Account/AccountModel"; import {Log, LOG_TAG} from "../../../framework/log/Log"; 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 enum ItemType { food = 1, bullet = 2, coldWeapon = 3, hotWeapon = 4, role = 5, } // ui 打开暂停游戏 const needRefreshTime = 10 * 60; @ccclass @menu("UI/Interface/UIAirdropView") export default class UIAirdropView extends UIBase { ui: auto_airdropView = null; // protected static prefabUrl = "Interface/airdropView"; protected static className = "UIAirdropView"; @property(cc.Prefab) itemPrefab: cc.Prefab = null; @property(cc.Prefab) obtainPrefab: cc.Prefab = null; /** * 对应上面的枚举 * @private */ private typeData = { 1: [], 2: [], 3: [], 4: [], 5: [], } private result: any[] = []; private lastTime = null; private cb: Function = null; onUILoad() { this.ui = this.node.addComponent(auto_airdropView); 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() { const infos = rewardDtMgr.getInstance().getAirDropRewardList(); for (let key in infos) { const info = infos[key]; this.typeData[info.type].push(info); } const airdropRewards = AccountModel.getInstance().airdrop_rewards; if (airdropRewards.length == 0) { this.refreshInfo(); }else { this.result = airdropRewards; this.refreshItemView(this.result); } let airdrop_time = AccountModel.getInstance().airdrop_time; if (!airdrop_time) { airdrop_time = Utils.getTimeStamp(); } let curTime = Utils.getTimeStamp(); let time = needRefreshTime - (curTime - airdrop_time); if (time > 0) { //上次的 this.lastTime = airdrop_time; this.ui.time.getComponent(cc.Label).string = `${Utils.getTime(time)}`; if (AccountModel.getInstance().is_airdrop) { this.changeBtnState(false); } } else { AccountModel.getInstance().is_airdrop = false; this.lastTime = curTime; } this.refreshTime(); } refreshInfo() { let result = []; for (let key in this.typeData) { const arr = this.typeData[key]; const info = arr[Math.floor(Math.random() * arr.length)]; result[key] = info; } this.refreshItemView(result); AccountModel.singleInstance.airdrop_rewards = result; this.result = result; } //zh ad diy public refreshInfoForAdEventKtsx() { let result = []; for (let key in this.typeData) { const arr = this.typeData[key]; const info = arr[Math.floor(Math.random() * arr.length)]; result[key] = info; } this.refreshItemView(result); AccountModel.singleInstance.airdrop_rewards = result; this.result = result; } /** *刷新view层 * @param result * @private */ private refreshItemView(result: any[]) { this.ui.content.destroyAllChildren(); for (let viewInfo of result) { if (!viewInfo) { continue; } const node = cc.instantiate(this.itemPrefab); const itemComponent = node.getComponent(UIAirdropItem); const data = itemDtManager.getDataByID(viewInfo.itemID); if (viewInfo.type == ItemType.role) { const modelInfo = modelDtlManager.getDataByID(viewInfo.modelID); itemComponent.refreshRole({ itemname: modelInfo.desc, nums: viewInfo.nums, roleRes: modelInfo.modelname }); } else { itemComponent.refresh({itemname: data.itemname, nums: viewInfo.nums, resPath1: data.resPath1}); } this.ui.content.addChild(node) } } refreshTime() { AccountModel.getInstance().airdrop_time = this.lastTime; this.cb = () => { let curTime = Utils.getTimeStamp(); let time = needRefreshTime - (curTime - this.lastTime); if (time <= 0) { this.changeBtnState(true); this.refreshInfo(); this.lastTime = curTime; AccountModel.getInstance().airdrop_time = this.lastTime; } this.ui.time.getComponent(cc.Label).string = `${Utils.getTime(time)}`; } this.schedule(this.cb, 1); } onHide() { } onStart() { } /** * 添加数值 * * */ clickGet() { if (!this.result) { return; } zjSdk?.sendEvent('空投-全部获取') let self = this if(2>1){//zh:diy if (cc.sys.os === cc.sys.OS_ANDROID) { GlobalManager.getInstance().registerMethod('doGetForAdEventKt', self.doGetForAdEventKt.bind(this)); let adKey = "zh_ad_type" if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) { cc.sys.localStorage.setItem(adKey, 'doGetForAdEventKt'); console.log('zh:AD ready for idx2') ATRewardedVideoSDK.showAd(AAJS2.getPlacementId()); } else { console.log('zh:AD not ready for idx2') self.doGetForAdEventKt(); } }else{ self.doGetForAdEventKt(); } return; } const params = { payType: zjSdk?.TYPE.VIDEO, success() { zjSdk?.sendEvent('空投-成功获取') self.doGet(); }, fail() { // self.doGet(); } }; zjSdk?.doPay(params); } private doGet() { console.log('zh:doGet 被触发'); const food = this.result[ItemType.food]; const bullet = this.result[ItemType.bullet]; const coldWeapon = this.result[ItemType.coldWeapon]; const hotWeapon = this.result[ItemType.hotWeapon]; const role = this.result[ItemType.role]; let incNum = this.getIncNums(food); gameData.curPowerNum += incNum; incNum = this.getIncNums(bullet); gameData.curBulletNum += incNum; let damage = itemDtManager.getDataByID(coldWeapon.itemID).value; gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, coldWeapon.itemID, damage, true); damage = itemDtManager.getDataByID(hotWeapon.itemID).value; gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, hotWeapon.itemID, damage, false); gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, role.modelID); //奖励 const node = cc.instantiate(this.obtainPrefab); const obtainView = node.getComponent(UIObtainView); obtainView.showByWelfare(this.result); this.node.addChild(node); AccountModel.getInstance().is_airdrop = true; this.changeBtnState(false); } //ZH DIY AD 空投获得 private doGetForAdEventKt() { console.log('zh:doGetForAdEventKt 被触发'); const food = this.result[ItemType.food]; const bullet = this.result[ItemType.bullet]; const coldWeapon = this.result[ItemType.coldWeapon]; const hotWeapon = this.result[ItemType.hotWeapon]; const role = this.result[ItemType.role]; let incNum = this.getIncNums(food); gameData.curPowerNum += incNum; incNum = this.getIncNums(bullet); gameData.curBulletNum += incNum; let damage = itemDtManager.getDataByID(coldWeapon.itemID).value; gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, coldWeapon.itemID, damage, true); damage = itemDtManager.getDataByID(hotWeapon.itemID).value; gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, hotWeapon.itemID, damage, false); gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, role.modelID); //奖励 const node = cc.instantiate(this.obtainPrefab); const obtainView = node.getComponent(UIObtainView); obtainView.showByWelfare(this.result); this.node.addChild(node); AccountModel.getInstance().is_airdrop = true; this.changeBtnState(false); } private changeBtnState(flag: boolean) { this.ui.btn_get.getComponent(cc.Button).interactable = flag; this.ui.btn_refrsh.getComponent(cc.Button).interactable = flag; } private getIncNums(item) { const itemValue = itemDtManager.getItemValue(item.itemID); let incNum = itemValue ; return incNum; } clickRefresh() { let self = this zjSdk?.sendEvent('空投-刷新按钮') if(2>1){//zh:diy if (cc.sys.os === cc.sys.OS_ANDROID) { GlobalManager.getInstance().registerMethod('refreshInfoForAdEventKtsx', this.refreshInfoForAdEventKtsx.bind(this)); let adKey = "zh_ad_type" if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) { cc.sys.localStorage.setItem(adKey, 'refreshInfoForAdEventKtsx'); console.log('zh:AD ready for idx2') ATRewardedVideoSDK.showAd(AAJS2.getPlacementId()); } else { console.log('zh:AD not ready for idx2') self.refreshInfoForAdEventKtsx(); } }else{ self.refreshInfoForAdEventKtsx(); } return; } //下面是原始的代码 const params = { payType: zjSdk?.TYPE.VIDEO, success() { zjSdk?.sendEvent('空投-成功刷新') self.refreshInfo() }, fail() { Log.log(LOG_TAG.DEBUG,"失败") // self.refreshInfo() } }; zjSdk?.doPay(params); } clickClose() { gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false); this.onClose(); } onClose() { UIHelp.CloseUI(UIAirdropView); } }