| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- import Util from "../../before/util/Util";
- 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 = ''
- 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) {
- 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);
- }
- }
- /** 更新其他广告次数
- * @param type 1:激励视频完播、2:插屏展示、3:信息流展示、 4:激励视频展⽰、5:激励视频加载失败、6:开屏展示、7:banner展示、
- * 8:插屏-全屏视频 完播、9:插屏-全屏视频 展示、10:插屏-全屏视频 加载失败、11:插屏加载失败、12:信息流加载失败、13:开屏加载失败、14:banner加载失败
- */
- 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 {
- 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);
- }
- /** 检查是否显示全屏插屏
- * @type 1:只对 ecpmLevel == 1 生效; 2:对所有玩家生效 3:延时弹出 4:先弹出插屏,再弹出全屏插屏
- */
- checkShowFullInter(type) {
- let per = this.getPerByEcpm();
- let pop = Math.random() < per;
- if (!pop) {
- return;
- }
- switch (type) {
- case 1:
- if (gData.gameData.ecpmLevel == 1) {
- mk.ad.showInterAd(1);
- }
- break;
- case 2:
- mk.ad.showInterAd(1);
- break;
- case 3:
- 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(1);
- }, delay);
- break;
- case 4:
- 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);
- setTimeout(() => {
- mk.ad.showInterAd(1);
- }, delay2);
- }, delay1);
- break;
- }
- }
- //定时弹出计时
- private timeAd = 0;
- /** 定时弹出红包 */
- startPopRed(dt) {
- this.timeAd += dt;
- switch (gData.gameData.ecpmLevel) {
- case 1:
- if (this.timeAd >= 30 * 1000) {
- this.timeAd = 0;
- mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
- }
- break;
- case 2:
- if (this.timeAd >= 60 * 1000) {
- this.timeAd = 0;
- mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
- }
- break;
- case 3:
- this.timeAd = 0;
- break;
- }
- }
- /** 需要弹出红包的点击数 */
- popClickTimes = 0;
- /** 累计点击数 */
- clickTimesAdd = 0;
- setPopClickTimes() {
- let arr = gData.gameData.configs.ServerConfig.ClickProduction.split(',');
- this.popClickTimes = Util.rnd(parseInt(arr[0]), parseInt(arr[1]));
- }
- checkPopRed() {
- this.clickTimesAdd++;
- if (this.clickTimesAdd >= this.popClickTimes) {
- this.clickTimesAdd = 0;
- this.setPopClickTimes();
- if (Math.random() <= this.getPerByEcpm()) {
- mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
- }
- }
- }
- getPerByEcpm() {
- //test
- return 1;
- let forceAd = gData.gameData.configs.forceAd;
- let len = forceAd.length;
- let per = 0;
- for (var i = 0; i < len; i++) {
- if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
- per = parseFloat(forceAd[i].percent);
- break;
- }
- }
- return per;
- }
- }
- /**
- * 看视频类型
- */
- export enum AdFun {
- bubble = 1, //气泡视频
- checkpoint = 2, //关卡消除视频
- settlement = 3, //关卡通关视频
- turntable = 4, //转盘视频
- sign = 5, //签到视频
- bigCash = 6, //福袋视频
- cashOutNoviceWelfare = 7, //钱包提现新手福利视频
- cashOutAddCash = 8, //钱包提现加现金视频
- harvest = 9, //收获超级加倍视频
- }
|