| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- import { Data } from "../../mk/data/Data";
- import { GameProp } 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 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<number, Data>
- /** 全屏插屏弹出规则 */
- private fullInterShowStr = ''
- /** 是gromore */
- private isGroMore = true;
- public init() {
- this.adMap = new Map<number, Data>();
- 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)
- }
- /**
- * 每次视频次数是否已经到达上限
- * @returns true 已达最大次数 false没有,可以有奖励
- */
- public checkAdMax() {
- this.watchNumToday++;
- let max = parseInt(gData.gameData.configs.ServerConfig.VideoTimesMax);
- if (this.watchNumToday > max) {
- mk.tip.pop("今日看广告获得奖励的次数已用完", 1);
- mk.ui.closeAllUI();
- return true;
- }
- else {
- return false;
- }
- }
- public updateData(placementId, data) {
- // if (this.isGroMore) {
- // let desNum = 0;
- // switch (data.network_firm_id) {
- // case 1:
- // desNum = 15;
- // break;
- // case 3:
- // desNum = 8;
- // break;
- // case 7:
- // desNum = 28;
- // break;
- // case 8:
- // desNum = 29;
- // break;
- // case 4:
- // desNum = 6;
- // break;
- // }
- // data.network_firm_id = desNum;
- // data.adsource_price = data.adsource_price * 0.01;
- // }
- 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;
- }
- public async watchVideo(type: AdFun) {
- 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,
- }
- 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);
- gData.gameData.setProp(GameProp.videoTimes, ++times);
- if (times < 5) {
- mk.data.sendXYEvent("video_end_" + times, "第" + times + "次看视频");
- }
- let curData = this.adMap.get(this.ad_subType)
- if (curData) {
- curData.setAdData(response.data);
- }
- //达到任务之后计算视频
- if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 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:插屏-全屏视频点击
- */
- public 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": ''
- }
- }
- else {
- if (this.isGroMore) {
- let desNum = 0;
- switch (data.network_firm_id) {
- case 1:
- desNum = 15;
- break;
- case 3:
- desNum = 8;
- break;
- case 7:
- desNum = 28;
- break;
- case 8:
- desNum = 29;
- break;
- case 4:
- desNum = 6;
- break;
- }
- data.network_firm_id = desNum;
- if (data.adsource_price < 0) {
- data.adsource_price = 0;
- }
- data.adsource_price = data.adsource_price * 0.01;
- }
- 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
- }
- }
- mk.http.sendData('updateADLog', sData);
- }
- /** 设置关闭红包弹出全屏插屏序列 */
- setFullInterShowStr() {
- let fullInterShowStrArr = gData.gameData.configs.GlobalCfg.fullInterShowStrArr.split(';');
- for (var i = 0; i < fullInterShowStrArr.length; i++) {
- let tempArr = fullInterShowStrArr[i].split(',');
- if (gData.gameData.adShowConfig.average_ecpm <= tempArr[1]) {
- this.fullInterShowStr = tempArr[2];
- break;
- }
- }
- }
- /** 检查是否显示全屏插屏
- * @type 不同情况弹出类型 1:提现结束判断ecpm低于一定值弹出 2:关闭红包界面不观看激励视频有概率拉起全屏广告
- */
- checkShowFullInter(type) {
- //全屏广告开关
- if (gData.gameData.configs.GlobalCfg.popFullInter != "1") {
- return
- }
- if (type == 1) {
- if (gData.gameData.adShowConfig.average_ecpm <= gData.gameData.configs.GlobalCfg.popFullEcpmAfterCash) {
- mk.ad.showInterAd(1);
- }
- }
- else if (type == 2) {
- if (this.fullInterShowStr) {
- let popFullIndex = mk.storage.getStorage('popFullIndex');
- if (popFullIndex == null) {
- popFullIndex = 0;
- }
- else {
- popFullIndex++;
- }
- mk.storage.setStorage('popFullIndex', popFullIndex);
- let index = popFullIndex % this.fullInterShowStr.length;
- mk.console.log('checkShowFullInter this.fullInterShowStr ', this.fullInterShowStr);
- mk.console.log('checkShowFullInter index', index);
- if (this.fullInterShowStr[index] == '1') {
- mk.console.log('checkShowFullInter showInterAd');
- mk.ad.showInterAd(1);
- }
- }
- }
- }
- }
- /**
- * 看视频类型
- */
- export enum AdFun {
- bubble = 1, //气泡视频
- checkpoint = 2, //关卡消除视频
- settlement = 3, //关卡通关视频
- turntable = 4, //转盘视频
- sign = 5, //签到视频
- bigCash = 6, //福袋视频
- }
|