123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- import auto_obtainView from "../../../ui/uidata/Interface/auto_obtainView";
- import UIBase from "../../../framework/ui/UIBase";
- import UIHelp from "../../../framework/ui/UIHelp";
- import UIAirdropItem from "./UIAirdropItem";
- import itemDtManager from "../../../dataManager/itemDtManager";
- import modelDtlManager from "../../../dataManager/modelDtlManager";
- import gameData from "../../../gameLogic/utrl/gameData";
- import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
- import {EVENT_TYPE} from "../../../gameLogic/utrl/gameEnum";
- import AccountModel from "../../../data/Account/AccountModel";
- import EventManager from "../../../framework/event/EventManager";
- 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/UIObtainView")
- export default class UIObtainView extends UIBase {
- ui: auto_obtainView = null;
- protected static prefabUrl = "Interface/obtainView";
- protected static className = "UIObtainView";
- @property(cc.Node)
- contentNode: cc.Node = null;
- @property(cc.Node)
- optionNode: cc.Node = null;
- @property(cc.Node)
- btn_doubleNode: cc.Node = null;
- @property(cc.Node)
- btnCollectNode: cc.Node = null;
- @property(cc.Prefab)
- itemPrefab: cc.Prefab = null;
- //是模块的子节点
- private isChild = false;
- onUILoad() {
- // this.ui = this.node.addComponent(auto_obtainView);
- 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);
- }
- }
- private isSign = false;
- private param: { ids: [], nums: [], isHero?, modelIds?, type? } = null;
- onShow() {
- }
- /**
- *
- * @param params ids item的id nums 数量 isHero 是否全部是英雄 modelIds英雄id
- */
- onInit(params: []) {
- // @ts-ignore
- let param: { ids: [], nums: [], isHero?, modelIds?, type? } = params[0];
- this.param = param;
- let isHero = false;
- let ids = param.ids;
- let nums = param.nums;
- let modelIds = [];
- if (nums.length != ids.length) {
- console.error("长度不一致!");
- return;
- }
- if (param.hasOwnProperty('isHero')) {
- isHero = param.isHero;
- }
- if (param.hasOwnProperty('modelIds')) {
- modelIds = param.modelIds;
- }
- if (param.type == 'sign') {
- console.log("zh: 签到过来的.");
- this.refreshSign();
- }
- ids.forEach((value, index) => {
- const node = cc.instantiate(this.itemPrefab);
- const item = node.getComponent(UIAirdropItem);
- this.contentNode.addChild(node);
- if (isHero) {
- const modelInfo = modelDtlManager.getDataByID(value);
- item.refreshRole({
- itemname: modelInfo.desc,
- nums: 1,
- roleRes: modelInfo.modelname
- });
- } else {
- const data = itemDtManager.getDataByID(value);
- let temp = {itemname: data.itemname, nums: nums[index], resPath1: data.resPath1}
- item.refresh(temp);
- }
- })
- if (modelIds.length == 0) {
- return;
- }
- modelIds.forEach((value, index) => {
- const node = cc.instantiate(this.itemPrefab);
- const item = node.getComponent(UIAirdropItem);
- this.contentNode.addChild(node);
- const modelInfo = modelDtlManager.getDataByID(value);
- item.refreshRole({
- itemname: modelInfo.desc,
- nums: 1,
- roleRes: modelInfo.modelname
- });
- })
- }
- refreshSign() {
- this.isSign = true;
- this.optionNode.active = true;
- this.btn_doubleNode.active = true;
- this.btnCollectNode.active = false;
- }
- showByWelfare(infos: any[]) {
- this.isChild = true;
- for (let viewInfo of infos) {
- if (!viewInfo) {
- continue;
- }
- const node = cc.instantiate(this.itemPrefab);
- const itemComponent = node.getComponent(UIAirdropItem);
- const data = itemDtManager.getDataByID(viewInfo.itemID);
- //英雄
- if (viewInfo.type == 5) {
- const modelInfo = modelDtlManager.getDataByID(viewInfo.modelID);
- itemComponent.refreshRole({
- itemname: viewInfo.name,
- nums: viewInfo.nums,
- roleRes: modelInfo.modelname
- });
- } else {
- itemComponent.refresh({itemname: data.itemname, nums: viewInfo.nums, resPath1: data.resPath1});
- }
- this.contentNode.addChild(node)
- }
- }
- onHide() {
- }
- onStart() {
- }
- clickOption() {
- }
- clickDouble() {
- console.log("zh:clickDouble");
- if (!this.isSign) {
- return;
- }
- this.doDouble();
- }
- clickClose() {
- if (this.isChild) {
- this.node.destroy();
- return;
- }
- this.onClose();
- }
- onClose() {
- EventManager.emit(EVENT_TYPE.closeObtain)
- UIHelp.CloseUI(UIObtainView);
- }
- private doDouble() {
- let self = this
- if(2>1){//zh:diy
- if (cc.sys.os === cc.sys.OS_ANDROID) {
- GlobalManager.getInstance().registerMethod('doubleRewardForAdEventQd', this.doubleRewardForAdEventQd.bind(this));
- let adKey = "zh_ad_type"
-
- if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
- cc.sys.localStorage.setItem(adKey, 'doubleRewardForAdEventQd');
- console.log('zh:AD ready for idx2')
- ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
-
- } else {
- console.log('zh:AD not ready for idx2')
- self.doubleRewardForAdEventQd();
-
- }
- }
-
- return;
- }
-
- const params = {
- payType: zjSdk?.TYPE.VIDEO,
- success() {
- self.doubleReward();
- },
- fail() {
- // self.doSearch();
- }
- };
- zjSdk?.doPay(params);
- this.clickClose();
- }
- private doubleReward() {
- const itemArr = this.param.ids;
- const numArr = this.param.nums;
- const modelIds = this.param.modelIds;
- itemArr.forEach((value, index) => {
- const data = itemDtManager.getDataByID(value);
- let damage: number = 0;
- // (食物1,药品2,子弹3,近战武器4, 远程武器5)
- switch (data.type) {
- case 1:
- gameData.curPowerNum += numArr[index];
- break;
- case 2:
- break;
- case 3:
- gameData.curBulletNum += numArr[index];
- break;
- case 4:
- for (let i = 0; i < numArr[index]; i++) {
- damage = itemDtManager.getDataByID(data.id).value;
- gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
- }
- break;
- case 5:
- for (let i = 0; i < numArr[index]; i++) {
- damage = itemDtManager.getDataByID(data.id).value;
- gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
- }
- break;
- }
- })
- if (modelIds.length !== 0 && modelIds[0] != 52) {
- const fixedRoleIds = AccountModel.singleInstance.fixed_role_ids;
- fixedRoleIds.push(modelIds[0])
- AccountModel.singleInstance.fixed_role_ids = fixedRoleIds;
- gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, modelIds[0]);
- }
- }
- //zh: diy ad 签到
- public doubleRewardForAdEventQd() {
- console.log("zh:doubleRewardForAdEventQd 被触发" );
- const itemArr = this.param.ids;
- const numArr = this.param.nums;
- const modelIds = this.param.modelIds;
- itemArr.forEach((value, index) => {
- const data = itemDtManager.getDataByID(value);
- let damage: number = 0;
- // (食物1,药品2,子弹3,近战武器4, 远程武器5)
- switch (data.type) {
- case 1:
- gameData.curPowerNum += numArr[index];
- break;
- case 2:
- break;
- case 3:
- gameData.curBulletNum += numArr[index];
- break;
- case 4:
- for (let i = 0; i < numArr[index]; i++) {
- damage = itemDtManager.getDataByID(data.id).value;
- gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true);
- }
- break;
- case 5:
- for (let i = 0; i < numArr[index]; i++) {
- damage = itemDtManager.getDataByID(data.id).value;
- gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false);
- }
- break;
- }
- })
- if (modelIds.length !== 0 && modelIds[0] != 52) {
- const fixedRoleIds = AccountModel.singleInstance.fixed_role_ids;
- fixedRoleIds.push(modelIds[0])
- AccountModel.singleInstance.fixed_role_ids = fixedRoleIds;
- gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, modelIds[0]);
- }
- console.log('zh:开始关闭签到界面1')
- this.clickClose();
- }
- }
|