import Util from "../../before/util/Util"; import { Data } from "../../mk/data/Data"; import { GameProp, InterAdType, InterFullAdType, VideoAdType } from "./GameData"; /** * @description 广告数据 * @author 邹勇 */ export class AdData { public placementId = ''; public adunit_format = ''; public network_type = ''; public network_placement_id = ''; public network_firm_id = ''; public adsource_id = ''; public adsource_index = ''; public adsource_price = '100'; public adsource_isheaderbidding = ''; public publisher_revenue = ''; public precision = ''; public ecpm_level = ''; public request_id = ''; /** 视频类型 */ public ad_subType: AdFun; private _watchNumToday: number = 0; /** 当天看的视频次数 */ public set watchNumToday(v: number) { this._watchNumToday = v; } public get watchNumToday(): number { return this._watchNumToday; } private adMap: Map /** 用户价值等级 1 低 2 中 3 高 等等*/ public ecpmLevel = 0; /** 自动弹窗间隔时间字典 */ private AutoRedMoneyMap: Map = new Map(); /** 弹出红包ecpm等级数组 */ private TimingRedMoneyArr = []; /** 生产按钮和菜单里的种植按钮,概率弹出恭喜发财红包ecpm等级数组 */ private ProductionButtonArr = []; /** 概率弹出全屏广告ecpm等级数组 */ private FullScreenAdArr = []; /** 弹出插屏、互推概率数组 */ private ABCInsertAdPercentArr = []; /** 概率弹出AB插屏广告ecpm等级数组 */ private ABCInsertAdArr = []; /** 提现弹出全屏ecpm等级数据 */ private FullCsahAdArr = []; public init() { this.adMap = new Map(); this.adMap.set(AdFun.bubble, gData.reward) this.adMap.set(AdFun.checkpoint, gData.reward) this.adMap.set(AdFun.settlement, gData.reward) this.adMap.set(AdFun.turntable, gData.turnable) this.adMap.set(AdFun.sign, gData.sign) this.adMap.set(AdFun.bigCash, gData.blessingBag) this.adMap.set(AdFun.cashOutAddCash, gData.walletCashOutData); this.adMap.set(AdFun.harvest, gData.harvestData); this.adMap.set(AdFun.farmMap, gData.farmMapData); this.adMap.set(AdFun.lineUp, gData.lineUpUIData); } /** * 每次视频次数是否已经到达上限 * @returns true 已达最大次数 false没有,可以有奖励 */ public checkAdMax() { this.watchNumToday++; let max = parseInt(gData.gameData.configs.ServerConfig.VideoTimesMax); mk.console.logSingle('checkAdMax watchNumToday ', this.watchNumToday); mk.console.logSingle('checkAdMax max ', max); if (this.watchNumToday > max) { mk.tip.pop("今日看广告获得奖励的次数已用完"); mk.ui.closeAllUI(); return true; } else { return false; } } public updateData(placementId, data) { mk.console.logSingle("updateADData:" + placementId, data); this.placementId = placementId; this.adunit_format = data.adunit_format; this.network_type = data.network_type; this.network_placement_id = data.network_placement_id; this.network_firm_id = data.network_firm_id; this.adsource_id = data.adsource_id; this.adsource_index = data.adsource_index; this.adsource_price = data.adsource_price; this.adsource_isheaderbidding = data.adsource_isheaderbidding; this.publisher_revenue = data.publisher_revenue; this.precision = data.precision; this.ecpm_level = data.ecpm_level; this.request_id = ''; if (data.ext_info && data.ext_info.request_id) { this.request_id = data.ext_info.request_id; } } public async watchVideo(type: AdFun, callBack: Function = null) { this.ad_subType = type; let data = { "imei": gData.appData.machineInfo.imei, "idfa": gData.appData.machineInfo.idfa, "oaid": gData.appData.machineInfo.oaid, "uin": gData.loginData.uin, "version": gData.appData.appVersion, "tf_channel": gData.appData.tfChannel, "destoon_ad_place": this.placementId, "ad_type": 1, "adunit_format": this.adunit_format, "network_type": this.network_type, "network_placement_id": this.network_placement_id, "network_firm_id": this.network_firm_id, "adsource_id": this.adsource_id, "adsource_index": this.adsource_index, "adsource_price": this.adsource_price, "adsource_isheaderbidding": this.adsource_isheaderbidding, "publisher_revenue": this.publisher_revenue, "precision_ecpm": this.precision, "ecpm_level": this.ecpm_level, "cfg_version": gData.appData.version, "adsource_ecpm": gData.gameData.adShowConfig.average_ecpm, "ad_sbuType": this.ad_subType, "request_id": this.request_id, } mk.console.logSingle("updateVideoData:", data); let response = await mk.http.sendData('updateVideo', data); if (response.errcode != 0) { return; } let times = gData.gameData.getProp(GameProp.videoTimes); if (!times) { times = 0; } gData.gameData.setProp(GameProp.videoTimes, ++times); if (times < 5) { mk.data.sendXYEvent("videoEnd_" + times, "第" + times + "次看视频"); } let curData = this.adMap.get(this.ad_subType) if (curData) { curData.setAdData(response.data); } if (callBack) { callBack(response.data); } //达到任务之后计算视频 if (gData.safeDepositBoxData.isStartBankTask > 0) { gData.safeDepositBoxData.richBankDailyVideoTimes++ if (gData.safeDepositBoxData.richBankDailyVideoTimes == gData.safeDepositBoxData.richBankDailyTotelVideoTimes) { mk.data.sendDataEvent("Bank", "银行-当日任务完成") } } } /** 更新其他广告次数 * @param type 1:激励视频完播、2:插屏展示、3:信息流展示、 4:激励视频展⽰、5:激励视频加载失败、6:开屏展示、7:banner展示、 * 8:插屏-全屏视频 完播、9:插屏-全屏视频 展示、10:插屏-全屏视频 加载失败、11:插屏加载失败、12:信息流加载失败、13:开屏加载失败、14:banner加载失败、 * 51:激励视频点击、52:插屏点击、53:信息流点击、54:开屏点击、55:banner点击、56:插屏-全屏视频点击 * 71:激励视频去重点击、72:插屏去重点击、73:信息流去重点击、74:开屏去重点击、75:banner去重点击、76:插屏-全屏视频去重点击 */ public async updateADLog(type, placementId, data = null) { let sData = null if (!data) { sData = { "imei": gData.appData.machineInfo.imei, "idfa": gData.appData.machineInfo.idfa, "oaid": gData.appData.machineInfo.oaid, "uin": gData.loginData.uin, "version": gData.appData.appVersion, "tf_channel": gData.appData.tfChannel, "destoon_ad_place": placementId, "ad_type": type, "adunit_format": '', "network_type": '', "network_placement_id": '', "network_firm_id": '', "adsource_id": '', "adsource_index": '', "adsource_price": '', "adsource_isheaderbidding": '', "publisher_revenue": '', "precision": '', "ecpm_level": '', "platformRisk": 1, "request_id": '', } } else { sData = { "imei": gData.appData.machineInfo.imei, "idfa": gData.appData.machineInfo.idfa, "oaid": gData.appData.machineInfo.oaid, "uin": gData.loginData.uin, "version": gData.appData.appVersion, "tf_channel": gData.appData.tfChannel, "destoon_ad_place": placementId, "ad_type": type, "adunit_format": data.adunit_format, "network_type": data.network_type, "network_placement_id": data.network_placement_id, "network_firm_id": data.network_firm_id, "adsource_id": data.adsource_id, "adsource_index": data.adsource_index, "adsource_price": data.adsource_price, "adsource_isheaderbidding": data.adsource_isheaderbidding, "publisher_revenue": data.publisher_revenue, "precision": data.precision, "ecpm_level": data.ecpm_level, "platformRisk": 1, "request_id": '', } if (data.ext_info && data.ext_info.request_id) { sData.request_id = data.ext_info.request_id; } } let response = await mk.http.sendData('updateADLog', sData); if (response && response.errcode == 0) { if (response.data) { mk.console.logSingle('solution ', response); //0-无处理;1-警告;2-封广告30分钟;3-封广告12小时;4-用户拉黑 gData.warnTipData.setSolution(response.data.solution); gData.warnTipData.setShutdownAds(response.data.shutdown_ads); } } } /** 初始化ecpm及弹出广告相关数据 */ initEcpmData() { gData.adData.setEcpmLevel(); gData.adData.setPopClickTimes(); this.TimingRedMoneyArr = gData.gameData.configs.ServerConfig.TimingRedMoney.split(','); this.ProductionButtonArr = gData.gameData.configs.ServerConfig.ProductionButton.split(','); this.FullScreenAdArr = gData.gameData.configs.ServerConfig.FullScreenAd.split(','); let arr = gData.gameData.configs.ServerConfig.ABInsertAdPercent.split(','); let per = 0; for (var i = 0; i < arr.length; i++) { per += parseFloat(arr[i]); this.ABCInsertAdPercentArr[i] = per; } this.ABCInsertAdArr = gData.gameData.configs.ServerConfig.ABInsertAd.split(','); this.FullCsahAdArr = gData.gameData.configs.ServerConfig.FullCsahAd.split(','); } /** 设置用户ecpm分级, 自动弹窗字典等 */ public setEcpmLevel() { // //test // this.ecpmLevel = 1; // this.AutoRedMoneyMap.set(1, 20); // return; let forceAd = gData.gameData.configs.ForceAd; let len = forceAd.length; let ecpmlevel = -1; for (var i = 0; i < len; i++) { if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { if (ecpmlevel == -1) { ecpmlevel = parseInt(forceAd[i].value); } this.AutoRedMoneyMap.set(parseInt(forceAd[i].value), parseInt(forceAd[i].autoRedMoney)) } } this.ecpmLevel = ecpmlevel; } /** 检查是否显示插屏、互推(概率弹出) * @type 1:弹出全屏插屏广告 2:延时弹出大插屏 3:先弹出插屏,再弹出大插屏 4:互推红包 5.激励视频之后弹插屏 */ checkShowFullInter(type, des = null, rateType = null) { let per = 0; let pop = true; switch (type) { case 1: if (rateType != null) { per = this.getPerByEcpm(rateType); } else { per = this.getPerByEcpm(RateConfig.RC_fullScreen); } pop = Math.random() < per; if (!pop) { return pop; } if (this.FullScreenAdArr.indexOf(this.ecpmLevel.toString()) == -1) { return; } mk.ad.showInterAd(1, des); break; case 2: if (rateType != null) { per = this.getPerByEcpm(rateType); } else { per = this.getPerByEcpm(RateConfig.RC_tableScreen); } pop = Math.random() < per; if (!pop) { return pop; } let delayArr = gData.gameData.configs.ServerConfig.AdDelay.split(','); let min = parseFloat(delayArr[0]); let max = parseFloat(delayArr[1]); let delay = (min + (max - min) * Math.random()) * 1000; setTimeout(() => { mk.ad.showInterAd(2, des); }, delay); break; case 3: if (rateType != null) { per = this.getPerByEcpm(rateType); } else { per = this.getPerByEcpm(RateConfig.RC_tableScreen); } pop = Math.random() < per; if (!pop) { return pop; } let delayArr1 = gData.gameData.configs.ServerConfig.AdDelay.split(','); let min1 = parseFloat(delayArr1[0]); let max1 = parseFloat(delayArr1[1]); let delay1 = (min1 + (max1 - min1) * Math.random()) * 1000; let delay2 = (min1 + (max1 - min1) * Math.random()) * 1000; setTimeout(() => { mk.ad.showInterAd(0, des); setTimeout(() => { mk.ad.showInterAd(2, des); }, delay2); }, delay1); break; case 4: if (rateType != null) { per = this.getPerByEcpm(rateType); } else { per = this.getPerByEcpm(RateConfig.RC_moreGameRedBag); } pop = Math.random() < per; if (!pop) { return pop; } gData.moreGame.popNewOpenRedBag(); break; } return pop; } /** 弹出插屏 */ checkPopInter(des, rateType = null) { if (this.ABCInsertAdArr.indexOf(this.ecpmLevel.toString()) == -1) { return; } let ran = Math.random(); let len = this.ABCInsertAdPercentArr.length; let index = 0; for (var i = 0; i < len; i++) { if (ran <= this.ABCInsertAdPercentArr[i]) { index = i + 2; break; } } this.checkShowFullInter(index, des, rateType); } /** 点击提现弹出全屏插屏 */ checkPopCashFull() { if (this.FullCsahAdArr.indexOf(this.ecpmLevel.toString()) == -1) { return; } mk.ad.showInterAd(1); } checkShowVideoIcon() { if (this.FullCsahAdArr.indexOf(this.ecpmLevel.toString()) == -1) { return false; } return true; } //定时弹出计时 private timeAd = 0; private test = true; /** 定时弹出红包 */ startPopRed(dt) { if (mk.guide.isGuiding() || mk.ui.getCurOnPanel('redBagTask') || mk.ui.getCurOnPanel('productReward2')) { this.timeAd = 0; return; } if (gData.gameData.isTouchScreen) { gData.gameData.isTouchScreen = false; this.timeAd = 0; return; } if (this.TimingRedMoneyArr.indexOf(this.ecpmLevel.toString()) == -1) { return; } this.timeAd += dt; let span = this.AutoRedMoneyMap.get(this.ecpmLevel); if (this.timeAd >= span) { this.timeAd = 0; //mk.ad.videoAdType = VideoAdType.video_init_19; // gData.gameData.init_hideRedBag = true; // mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag'); //this.checkPopInter(InterAdType.interstitial1_click_19); if (gData.gameData.insertAdSwitch[13] == "1") { gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_4); } } } /** 需要弹出红包的点击数 */ popClickTimes = 0; /** 累计点击数 */ clickTimesAdd = 0; setPopClickTimes() { let arr = gData.gameData.configs.ServerConfig.ClickProduction.split(','); this.popClickTimes = Util.rnd(parseInt(arr[0]), parseInt(arr[1])); } checkPopRed() { if (this.ProductionButtonArr.indexOf(this.ecpmLevel.toString()) == -1) { return; } if (mk.guide.isGuiding()) { return; } this.clickTimesAdd++; if (this.clickTimesAdd >= this.popClickTimes) { this.clickTimesAdd = 0; this.setPopClickTimes(); if (Math.random() <= this.getPerByEcpm()) { mk.ad.videoAdType = VideoAdType.video_init_17; mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag'); } } } getPerByEcpm(type: RateConfig = RateConfig.RC_fullScreen) { // //test // return 0.26; let forceAd = gData.gameData.configs.ForceAd; let len = forceAd.length; let per = 0; for (var i = 0; i < len; i++) { switch (type) { case RateConfig.RC_fullScreen: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].qpPercent); return per; } case RateConfig.RC_tableScreen: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].cpPercent); return per; } case RateConfig.RC_banner: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].baPercent); return per; } case RateConfig.RC_infrormationFlow: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].xxPercent); return per; } case RateConfig.RC_splash: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].kpPercent); return per; } case RateConfig.RC_superDouble: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].jbPercent); return per; } case RateConfig.RC_moreGameRedBag: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].htPercent); return per; } case RateConfig.RC_popSpeedUp: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].jsPercent); return per; } case RateConfig.RC_afterVideo: if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) { per = parseFloat(forceAd[i].cpjlPercent); return per; } } } return per; } async savePreLoadEcpm(data) { let times = gData.gameData.getProp(GameProp.videoTimes); console.log('savePreLoadEcpm times ', times) if (!times) { console.log('savePreLoadEcpm data ', data.adsource_price) let response = await mk.http.sendData('user/savePreLoadEcpm', data); if (response.errcode != 0) { return; } this.getOrderTaskInfo(0); } } async getOrderTaskInfo(isDefault) { if (!gData.gameData.playerProp.orderData) { let data = {}; data["isDefault"] = isDefault; let response = await mk.http.sendData('orderTask/getUserOrderTaskInfo', data); if (response.errcode != 0) { return; } gData.gameData.playerProp.orderData = response.data.userOrderTaskInfo; mk.event.emit("initOrderUi"); } } } /** * 看视频类型 */ export enum AdFun { bubble = 1, //气泡视频 checkpoint = 2, //关卡消除视频 settlement = 3, //关卡通关视频 turntable = 4, //转盘视频 sign = 5, //签到视频 bigCash = 6, //福袋视频 cashOutAddCash = 8, //钱包提现加现金视频 harvest = 9, //收获超级加倍视频 farmMap = 10, //图鉴领取视频 lineUp = 11, //插队视频 addProductTimes = 12,//获得生产次数 } export enum RateConfig { RC_fullScreen, RC_tableScreen, RC_banner, RC_infrormationFlow, RC_splash, RC_superDouble, RC_moreGameRedBag, RC_popSpeedUp, RC_afterVideo }