123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- import auto_welfareView from "../../../ui/uidata/Interface/auto_welfareView";
- import UIBase from "../../../framework/ui/UIBase";
- import UIHelp from "../../../framework/ui/UIHelp";
- import rewardDtMgr from "../../../dataManager/rewardDtMgr";
- import itemDtManager from "../../../dataManager/itemDtManager";
- import gameData from "../../../gameLogic/utrl/gameData";
- import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
- import {EVENT_TYPE, ITEM_TYPE} from "../../../gameLogic/utrl/gameEnum";
- import UIObtainView from "./UIObtainView";
- import AccountModel from "../../../data/Account/AccountModel";
- import EventManager from "../../../framework/event/EventManager";
- import game = cc.game;
- import UIAirdropItem from "./UIAirdropItem";
- import UiGuideHand from "../common/uiGuideHand";
- import {GameEvent} from "../../../constant/constant-game";
- 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;
- //奖励类型
- enum rewardType {
- npc = 'npc',
- weapon = 'weapon',
- gun = 'gun',
- bullet = 'bullet'
- }
- @ccclass
- @menu("UI/Interface/UIWelfareView")
- export default class UIWelfareView extends UIBase {
- ui: auto_welfareView = null;
- protected static prefabUrl = "Interface/welfareView";
- protected static className = "UIWelfareView";
- @property(cc.Prefab)
- itemPrefab: cc.Prefab = null;
- @property(cc.Prefab)
- guideHandPrefab: cc.Prefab = null;
- onUILoad() {
- this.ui = this.node.addComponent(auto_welfareView);
- 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 list = rewardDtMgr.getInstance().getSurvivorRewardList();
- for (let key in list) {
- const infos = list[key];
- for (let i = 1; i <= 4; i++) {
- if (infos.rewardType == rewardType.npc) {
- continue;
- }
- const node = cc.instantiate(this.itemPrefab);
- node.scale = 0.9;
- const id = infos[`rewardID${i}`];
- const itemInfo = itemDtManager.getDataByID(id);
- const component = node.getComponent(UIAirdropItem);
- if (infos.rewardType == rewardType.weapon) {
- component.refresh(itemInfo, 0, false)
- this.ui.weapon_list.addChild(node);
- } else if (infos.rewardType == rewardType.gun) {
- component.refresh(itemInfo, 1, false)
- this.ui.gun_list.addChild(node);
- } else if (infos.rewardType == rewardType.bullet) {
- component.refresh(itemInfo, 2, false)
- this.ui.bullet_list.addChild(node);
- }
- }
- this.guideHandler();
- }
- const curWelfare = AccountModel.getInstance().curWelfare;
- for (let welfare of curWelfare) {
- this.switchBtn(welfare, false);
- }
- }
- private guideHandler() {
- if (!GameEvent.isNeedGuideVideo){
- return;
- }
- if (AccountModel.getInstance().curWelfare.length != 0){
- return
- }
- if (AccountModel.getInstance().is_new == 1) {
- const node = cc.instantiate(this.guideHandPrefab);
- node.getComponent(UiGuideHand).init(this.ui.npc);
- this.node.addChild(node);
- }
- }
- onHide() {
- }
- onStart() {
- }
- clickBtn(event: any, type: string) {
- console.log('zh:clickBtn ' + type);
- let result = null;
- const infos = rewardDtMgr.getInstance().getSurvivorRewardList();
- for (let key in infos) {
- const info = infos[key];
- if (info.rewardType == type) {
- result = info;
- }
- }
- if (!result) {
- return;
- }
-
- this.showTag(type);
- console.log('zh:clickBtn 2' );
- let self = this
-
- if(2>1){//zh:diy
- if (cc.sys.os === cc.sys.OS_ANDROID) {
- // 注册方法 , this.ClickClose.bind(this));
- // result, type: string
- GlobalManager.getInstance().registerMethod('doGetForAdEvent', (result:any,type: string) => {
- //console.log();
- });
- GlobalManager.getInstance().registerMethod('doGetForAdEvent', this.doGetForAdEvent.bind(this));
- let adKey = "zh_ad_type"
-
- if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
- cc.sys.localStorage.setItem(adKey, 'doGetForAdEvent');
- let monthParams = {result,type};
- cc.sys.localStorage.setItem('doGetForAdEvent_monthParams', JSON.stringify(monthParams));
- console.log('zh:AD ready for idx2')
- ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
-
- } else {
- console.log('zh:AD not ready for idx2')
- self.doGetForAdEvent(result, type);
- }
- }
-
- return;
- }
- //下面是原始的代码
- const params = {
- payType: zjSdk?.TYPE.VIDEO,
- success() {
- self.doGet(result, type);
- },
- fail() {
- // self.doGet(result, type);
- }
- };
- console.log('zh:clickBtn 3' );
- zjSdk?.doPay(params);
- }
- showTag(type){
- if (type == rewardType.npc) {
- zjSdk?.sendEvent('点击幸存者')
- }
- if (type == rewardType.bullet) {
- zjSdk?.sendEvent('点击子弹资源')
- }
- if (type == rewardType.weapon) {
- zjSdk?.sendEvent('点击武器资源')
- }
- if (type == rewardType.gun) {
- zjSdk?.sendEvent('点击枪械资源')
- }
- }
- private doGet(result, type: string) {
- const arr = this.parseArr(result);
- let nums = [];
- for (let id of arr) {
- const data = itemDtManager.getDataByID(id);
- if (type == rewardType.npc) {
- zjSdk?.sendEvent('幸存者成功获取')
- gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, id);
- nums.push(1);
- }
- if (type == rewardType.bullet) {
- zjSdk?.sendEvent('子弹资源成功获取')
- gameData.curBulletNum += data.value;
- nums.push(data.value);
- }
- if (type == rewardType.weapon) {
- zjSdk?.sendEvent('武器资源成功获取')
- let damage = itemDtManager.getDataByID(data.id).value;
- gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
- nums.push(1);
- }
- if (type == rewardType.gun) {
- zjSdk?.sendEvent('枪械资源成功获取')
- let damage = itemDtManager.getDataByID(data.id).value;
- gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
- nums.push(1);
- }
- }
- UIHelp.ShowUI(UIObtainView, null, {ids: arr, nums: nums, isHero: type == rewardType.npc})
- // 关闭按钮
- const curWelfare = AccountModel.getInstance().curWelfare;
- curWelfare.push(type);
- AccountModel.getInstance().curWelfare = curWelfare;
- this.switchBtn(type, false);
- }
- /**
- * zh:diy
- * @param result
- * @param type
- */
- public doGetForAdEvent(result, type: string) {
- console.log('zh:doGetForAdEvent 被触发1 ' + result);
- console.log('zh:doGetForAdEvent 被触发2 ' + type);
- const arr = this.parseArr(result);
- let nums = [];
- for (let id of arr) {
- const data = itemDtManager.getDataByID(id);
- if (type == rewardType.npc) {
- zjSdk?.sendEvent('幸存者成功获取')
- gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, id);
- nums.push(1);
- }
- if (type == rewardType.bullet) {
- zjSdk?.sendEvent('子弹资源成功获取')
- gameData.curBulletNum += data.value;
- nums.push(data.value);
- }
- if (type == rewardType.weapon) {
- zjSdk?.sendEvent('武器资源成功获取')
- let damage = itemDtManager.getDataByID(data.id).value;
- gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
- nums.push(1);
- }
- if (type == rewardType.gun) {
- zjSdk?.sendEvent('枪械资源成功获取')
- let damage = itemDtManager.getDataByID(data.id).value;
- gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
- nums.push(1);
- }
- }
- UIHelp.ShowUI(UIObtainView, null, {ids: arr, nums: nums, isHero: type == rewardType.npc})
- // 关闭按钮
- const curWelfare = AccountModel.getInstance().curWelfare;
- curWelfare.push(type);
- AccountModel.getInstance().curWelfare = curWelfare;
- this.switchBtn(type, false);
- }
- private switchBtn(type: string, flag) {
- this.ui[`${type}`].getComponent(cc.Button).interactable = flag
- }
- private parseArr(result) {
- let arr = [];
- [1, 2, 3, 4].forEach(value => {
- const id = result[`rewardID${value}`];
- arr.push(id)
- })
- return arr;
- }
- clickClose() {
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false);
- this.onClose();
- }
- onClose() {
- UIHelp.CloseUI(UIWelfareView);
- }
- }
|