import auto_crazyAwardView from "../../../ui/uidata/Interface/auto_crazyAwardView"; import UIBase from "../../../framework/ui/UIBase"; import UIHelp from "../../../framework/ui/UIHelp"; import PlayerView from "../../../gameLogic/gameObject/player/playerView"; import PlayerObject from "../../../gameLogic/gameObject/player/playerObject"; import Utils from "../../../framework/utils/utils"; import ZomBieObject from "../../../gameLogic/gameObject/zombie/zombieObject"; import BulletObject from "../../../gameLogic/gameObject/bullet/bulletObject"; import gameData from "../../../gameLogic/utrl/gameData"; import gameEventManager from "../../../gameLogic/utrl/gameEventManager"; import {EVENT_TYPE, FALLITEM_TYPE, ITEM_TYPE} from "../../../gameLogic/utrl/gameEnum"; import UIObtainView from "./UIObtainView"; import UIMng from "../../../framework/ui/UIMng"; import UIGameScene from "../scene/UIGameScene"; import EventManager from "../../../framework/event/EventManager"; import tween = cc.tween; import AccountModel from "../../../data/Account/AccountModel"; 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; @ccclass @menu("UI/Interface/UICrazyAwardView") export default class UICrazyAwardView extends UIBase { ui: auto_crazyAwardView = null; protected static prefabUrl = "Interface/crazyAwardView"; protected static className = "UICrazyAwardView"; @property(cc.Prefab) heroPrefab: cc.Prefab = null; @property(cc.Prefab) zombiePrefab: cc.Prefab = null; @property(cc.Prefab) bulletPrefab: cc.Prefab = null; playerObjects: PlayerObject [] = []; zomBieObjects: ZomBieObject [] = []; lastClickTime = -1; nowClickTIme = -1; curProgress = 100; isShowBanner = false; bannerClick = false; triggerCloseSecond = -1; bannerType = 0; temp = 0; isClosing = false; isADShowed = false; onUILoad() { this.ui = this.node.addComponent(auto_crazyAwardView); AccountModel.getInstance().show_crazy_in_level ++; UIMng.getInstance().setLock(true) 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() { tween(this.ui.kdzl) .repeatForever( cc.tween(this.ui.kdzl) .to(0.8,{scale:0.5,opacity:0}) .to(0.8,{scale:1,opacity:255}) ) .start(); tween(this.ui.fxtsjs_btn) .repeatForever( cc.tween(this.ui.fxtsjs_btn) .to(0.8,{scale:0.8}) .to(0.8,{scale:1}) ) .start(); tween(this.ui.point) .repeatForever( cc.tween(this.ui.point) .to(0.8,{opacity:0}) .to(0.8,{opacity:255}) ) .start(); this.bannerType = Utils.random(0, 2); // 随机一个banner的显示方案 for (let i = 1; i <= 4; i++) { this.randomHero(i); } this.randomZombie(1); } randomZombie(index: number) { let id = 0; // let isBoss = false; // if (Utils.random(0, 1)) { id = Utils.random(53, 56); if (id == 54){ id = 56 } // }else { // id = Utils.random(22, 48); // } let nd = cc.instantiate(this.zombiePrefab); // if (isBoss){ nd.scale = 0.8; // } let comp = nd.getComponent(ZomBieObject); this.zomBieObjects.push(comp); this.ui[`zombieSlot${index}`].addChild(nd) nd.group = 'default'; comp.init(id, cc.v3(0, 0, 0), [], false, true); this.scheduleOnce(() => { nd.setPosition(cc.v3(0, 0, 0)); comp.cur_hp_bar.parent.active = false; }) } private randomHero(index: number) { let id = Utils.random(1, 9); let nd = cc.instantiate(this.heroPrefab); let playerViewCom = nd.getChildByName('view').getComponent(PlayerView); let playerObjCom = nd.getComponent(PlayerObject); this.playerObjects.push(playerObjCom); playerObjCom.init(id, []); nd.group = 'default'; nd.scaleX *= -1; this.scheduleOnce(() => { nd.setPosition(cc.v3(0, 0, 0)); const randomWeapon = 41; playerObjCom.player_prop.setWeapon(randomWeapon, false); playerObjCom.player_prop.cur_weapon = playerObjCom.player_prop.remote_weapon; playerViewCom.init(id); this.scheduleOnce(() => { playerViewCom.playIdle(randomWeapon) },0) }, 0); // playerObjCom.setLeader(false); this.ui[`heroSlot${index}`].addChild(nd) } onHide() { } onStart() { } update(dt) { let speed = 60 * dt; let subNum = this.curProgress + speed; this.curProgress = subNum < 100 ? subNum : 100; this.ui.nodeProgress.getComponent(cc.Sprite).fillRange = this.curProgress / 100; if (this.triggerCloseSecond !== -1 && this.triggerCloseSecond > 0) { this.triggerCloseSecond -= dt; if (this.triggerCloseSecond <= 0) { if (this.bannerClick) { if (this.isADShowed) { zjSdk?.hideBannerAd(); this.toClose(); } } else { this.triggerCloseSecond = -1 this.isShowBanner = false; zjSdk?.hideBannerAd(); this.toClose(); } } } } toClose() { this.isClosing = true; this.schedule(() => { this.clickCrazy(); }, 0.1) } clickCrazy() { this.heroAttack(); // 存储上一次点击时间与当前点击时间 const clickTime = new Date().getTime() / 1000; if (this.lastClickTime <= 0) { this.lastClickTime = clickTime; } else { this.lastClickTime = this.nowClickTIme; } this.nowClickTIme = clickTime; const addProgress = Utils.random(12, 15); this.curProgress -= addProgress; if (this.curProgress < 0) { this.curProgress = 0; } this.ui.nodeProgress.getComponent(cc.Sprite).fillRange = this.curProgress / 100; this.checkShow(); } checkShow() { if (this.curProgress == 0) { this.reword(); return; } if (this.isShowBanner) { return; } if (this.isClosing) { return; } // 每次点击均有50%的几率出现banner if (this.bannerType === 0) { if (Math.random() <= 0.5) { this.showBanner(); } return; } // 进度条到达20%出现banner if (this.bannerType === 1) { if (this.curProgress < 20) { this.showBanner(); } return; } // 阶段点击按钮时显示banner的概率 if (this.bannerType === 2) { if (this.curProgress < 25 && Math.random() < 0.75) { this.showBanner(); } else if (this.curProgress < 50 && Math.random() < 0.5) { this.showBanner(); } else if (this.curProgress < 75 && Math.random() < 0.25) { this.showBanner(); } else { this.showBanner(); } return; } // 两次点击间隔小于0.3秒时出现banner if (this.bannerType === 3) { if (this.nowClickTIme !== this.lastClickTime && this.nowClickTIme - this.lastClickTime < 0.31) { this.showBanner(); } return; } } private heroAttack() { for (let i = 0; i < 4; i++) { this.fire(this.playerObjects[i], i); } } private reword() { gameData.curPowerNum += 100; gameData.curBulletNum += 100; const randomId = Utils.random(1, 10); gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, randomId); this.clickClose(); gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS,true) EventManager.once(EVENT_TYPE.closeObtain, () => { gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS,false) }) UIHelp.ShowUI(UIObtainView, null, { ids: [FALLITEM_TYPE.qiaokeli, FALLITEM_TYPE.zidan1], nums: [100, 100], modelIds: [randomId] }) } private fire(playerObject: PlayerObject, i) { let b = cc.instantiate(this.bulletPrefab); this.node.addChild(b); let com = b.getComponent(BulletObject); com.max_dis = 400; const pos = playerObject.node.position; pos.x += this.ui.heroContent.x; pos.y += this.ui.heroContent.y; pos.x += this.ui[`heroSlot${i + 1}`].x; pos.y += this.ui[`heroSlot${i + 1}`].y; let red = 0; if (i == 0) { red = -0.1; } else if (i == 3) { red = 0.1; } com.init(pos.add(cc.v3(0, 30, 0)), red, 50, playerObject); com.destroyCall = () => { const zombieView = this.zomBieObjects[0].zombie_view; if (zombieView) { zombieView.hitEff(); } } } clickClose() { gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false); this.onClose(); } showBanner() { this.isShowBanner = true; zjSdk?.showBannerAd({ adPlaceName: '大按钮狂点', success: () => { this.isADShowed = true; }, fail: (err) => { this.isADShowed = true; }, }, (isStateClick) => { this.bannerClick = isStateClick; }); this.triggerCloseSecond = 2; } onClose() { zjSdk?.hideBannerAd(); cc.Canvas.instance.scheduleOnce(() => { UIMng.getInstance().setLock(false) }, 1) UIHelp.CloseUI(UICrazyAwardView); } }