AdData.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. import Util from "../../before/util/Util";
  2. import { Data } from "../../mk/data/Data";
  3. import { GameProp, InterAdType, InterFullAdType, VideoAdType } from "./GameData";
  4. /**
  5. * @description 广告数据
  6. * @author 邹勇
  7. */
  8. export class AdData {
  9. public placementId = '';
  10. public adunit_format = '';
  11. public network_type = '';
  12. public network_placement_id = '';
  13. public network_firm_id = '';
  14. public adsource_id = '';
  15. public adsource_index = '';
  16. public adsource_price = '100';
  17. public adsource_isheaderbidding = '';
  18. public publisher_revenue = '';
  19. public precision = '';
  20. public ecpm_level = '';
  21. public request_id = '';
  22. /** 视频类型 */
  23. public ad_subType: AdFun;
  24. private _watchNumToday: number = 0;
  25. /** 当天看的视频次数 */
  26. public set watchNumToday(v: number) {
  27. this._watchNumToday = v;
  28. }
  29. public get watchNumToday(): number {
  30. return this._watchNumToday;
  31. }
  32. private adMap: Map<number, Data>
  33. /** 用户价值等级 1 低 2 中 3 高 等等*/
  34. public ecpmLevel = 0;
  35. /** 自动弹窗间隔时间字典 */
  36. private AutoRedMoneyMap: Map<number, number> = new Map();
  37. /** 弹出红包ecpm等级数组 */
  38. private TimingRedMoneyArr = [];
  39. /** 生产按钮和菜单里的种植按钮,概率弹出恭喜发财红包ecpm等级数组 */
  40. private ProductionButtonArr = [];
  41. /** 概率弹出全屏广告ecpm等级数组 */
  42. private FullScreenAdArr = [];
  43. /** 弹出插屏、互推概率数组 */
  44. private ABCInsertAdPercentArr = [];
  45. /** 概率弹出AB插屏广告ecpm等级数组 */
  46. private ABCInsertAdArr = [];
  47. /** 提现弹出全屏ecpm等级数据 */
  48. private FullCsahAdArr = [];
  49. public init() {
  50. this.adMap = new Map<number, Data>();
  51. this.adMap.set(AdFun.bubble, gData.reward)
  52. this.adMap.set(AdFun.checkpoint, gData.reward)
  53. this.adMap.set(AdFun.settlement, gData.reward)
  54. this.adMap.set(AdFun.turntable, gData.turnable)
  55. this.adMap.set(AdFun.sign, gData.sign)
  56. this.adMap.set(AdFun.bigCash, gData.blessingBag)
  57. this.adMap.set(AdFun.cashOutAddCash, gData.walletCashOutData);
  58. this.adMap.set(AdFun.harvest, gData.harvestData);
  59. this.adMap.set(AdFun.farmMap, gData.farmMapData);
  60. this.adMap.set(AdFun.lineUp, gData.lineUpUIData);
  61. }
  62. /**
  63. * 每次视频次数是否已经到达上限
  64. * @returns true 已达最大次数 false没有,可以有奖励
  65. */
  66. public checkAdMax() {
  67. this.watchNumToday++;
  68. let max = parseInt(gData.gameData.configs.ServerConfig.VideoTimesMax);
  69. mk.console.logSingle('checkAdMax watchNumToday ', this.watchNumToday);
  70. mk.console.logSingle('checkAdMax max ', max);
  71. if (this.watchNumToday > max) {
  72. mk.tip.pop("今日看广告获得奖励的次数已用完");
  73. mk.ui.closeAllUI();
  74. return true;
  75. }
  76. else {
  77. return false;
  78. }
  79. }
  80. public updateData(placementId, data) {
  81. mk.console.logSingle("updateADData:" + placementId, data);
  82. this.placementId = placementId;
  83. this.adunit_format = data.adunit_format;
  84. this.network_type = data.network_type;
  85. this.network_placement_id = data.network_placement_id;
  86. this.network_firm_id = data.network_firm_id;
  87. this.adsource_id = data.adsource_id;
  88. this.adsource_index = data.adsource_index;
  89. this.adsource_price = data.adsource_price;
  90. this.adsource_isheaderbidding = data.adsource_isheaderbidding;
  91. this.publisher_revenue = data.publisher_revenue;
  92. this.precision = data.precision;
  93. this.ecpm_level = data.ecpm_level;
  94. this.request_id = '';
  95. if (data.ext_info && data.ext_info.request_id) {
  96. this.request_id = data.ext_info.request_id;
  97. }
  98. }
  99. public async watchVideo(type: AdFun, callBack: Function = null) {
  100. this.ad_subType = type;
  101. let data = {
  102. "imei": gData.appData.machineInfo.imei,
  103. "idfa": gData.appData.machineInfo.idfa,
  104. "oaid": gData.appData.machineInfo.oaid,
  105. "uin": gData.loginData.uin,
  106. "version": gData.appData.appVersion,
  107. "tf_channel": gData.appData.tfChannel,
  108. "destoon_ad_place": this.placementId,
  109. "ad_type": 1,
  110. "adunit_format": this.adunit_format,
  111. "network_type": this.network_type,
  112. "network_placement_id": this.network_placement_id,
  113. "network_firm_id": this.network_firm_id,
  114. "adsource_id": this.adsource_id,
  115. "adsource_index": this.adsource_index,
  116. "adsource_price": this.adsource_price,
  117. "adsource_isheaderbidding": this.adsource_isheaderbidding,
  118. "publisher_revenue": this.publisher_revenue,
  119. "precision_ecpm": this.precision,
  120. "ecpm_level": this.ecpm_level,
  121. "cfg_version": gData.appData.version,
  122. "adsource_ecpm": gData.gameData.adShowConfig.average_ecpm,
  123. "ad_sbuType": this.ad_subType,
  124. "request_id": this.request_id,
  125. }
  126. mk.console.logSingle("updateVideoData:", data);
  127. let response = await mk.http.sendData('updateVideo', data);
  128. if (response.errcode != 0) {
  129. return;
  130. }
  131. let times = gData.gameData.getProp(GameProp.videoTimes);
  132. if (!times) {
  133. times = 0;
  134. }
  135. gData.gameData.setProp(GameProp.videoTimes, ++times);
  136. if (times < 5) {
  137. mk.data.sendXYEvent("videoEnd_" + times, "第" + times + "次看视频");
  138. }
  139. let curData = this.adMap.get(this.ad_subType)
  140. if (curData) {
  141. curData.setAdData(response.data);
  142. }
  143. if (callBack) {
  144. callBack(response.data);
  145. }
  146. //达到任务之后计算视频
  147. if (gData.safeDepositBoxData.isStartBankTask > 0) {
  148. gData.safeDepositBoxData.richBankDailyVideoTimes++
  149. if (gData.safeDepositBoxData.richBankDailyVideoTimes == gData.safeDepositBoxData.richBankDailyTotelVideoTimes) {
  150. mk.data.sendDataEvent("Bank", "银行-当日任务完成")
  151. gData.safeDepositBoxData.addJGTags();
  152. }
  153. }
  154. }
  155. /** 更新其他广告次数
  156. * @param type 1:激励视频完播、2:插屏展示、3:信息流展示、 4:激励视频展⽰、5:激励视频加载失败、6:开屏展示、7:banner展示、
  157. * 8:插屏-全屏视频 完播、9:插屏-全屏视频 展示、10:插屏-全屏视频 加载失败、11:插屏加载失败、12:信息流加载失败、13:开屏加载失败、14:banner加载失败、
  158. * 51:激励视频点击、52:插屏点击、53:信息流点击、54:开屏点击、55:banner点击、56:插屏-全屏视频点击
  159. * 71:激励视频去重点击、72:插屏去重点击、73:信息流去重点击、74:开屏去重点击、75:banner去重点击、76:插屏-全屏视频去重点击
  160. */
  161. public async updateADLog(type, placementId, data = null) {
  162. let sData = null
  163. if (!data) {
  164. sData = {
  165. "imei": gData.appData.machineInfo.imei,
  166. "idfa": gData.appData.machineInfo.idfa,
  167. "oaid": gData.appData.machineInfo.oaid,
  168. "uin": gData.loginData.uin,
  169. "version": gData.appData.appVersion,
  170. "tf_channel": gData.appData.tfChannel,
  171. "destoon_ad_place": placementId,
  172. "ad_type": type,
  173. "adunit_format": '',
  174. "network_type": '',
  175. "network_placement_id": '',
  176. "network_firm_id": '',
  177. "adsource_id": '',
  178. "adsource_index": '',
  179. "adsource_price": '',
  180. "adsource_isheaderbidding": '',
  181. "publisher_revenue": '',
  182. "precision": '',
  183. "ecpm_level": '',
  184. "platformRisk": 1,
  185. "request_id": '',
  186. }
  187. }
  188. else {
  189. sData = {
  190. "imei": gData.appData.machineInfo.imei,
  191. "idfa": gData.appData.machineInfo.idfa,
  192. "oaid": gData.appData.machineInfo.oaid,
  193. "uin": gData.loginData.uin,
  194. "version": gData.appData.appVersion,
  195. "tf_channel": gData.appData.tfChannel,
  196. "destoon_ad_place": placementId,
  197. "ad_type": type,
  198. "adunit_format": data.adunit_format,
  199. "network_type": data.network_type,
  200. "network_placement_id": data.network_placement_id,
  201. "network_firm_id": data.network_firm_id,
  202. "adsource_id": data.adsource_id,
  203. "adsource_index": data.adsource_index,
  204. "adsource_price": data.adsource_price,
  205. "adsource_isheaderbidding": data.adsource_isheaderbidding,
  206. "publisher_revenue": data.publisher_revenue,
  207. "precision": data.precision,
  208. "ecpm_level": data.ecpm_level,
  209. "platformRisk": 1,
  210. "request_id": '',
  211. }
  212. if (data.ext_info && data.ext_info.request_id) {
  213. sData.request_id = data.ext_info.request_id;
  214. }
  215. }
  216. let response = await mk.http.sendData('updateADLog', sData);
  217. if (response && response.errcode == 0) {
  218. if (response.data) {
  219. mk.console.logSingle('solution ', response);
  220. //0-无处理;1-警告;2-封广告30分钟;3-封广告12小时;4-用户拉黑
  221. gData.warnTipData.setSolution(response.data.solution);
  222. gData.warnTipData.setShutdownAds(response.data.shutdown_ads);
  223. }
  224. }
  225. }
  226. /** 初始化ecpm及弹出广告相关数据 */
  227. initEcpmData() {
  228. gData.adData.setEcpmLevel();
  229. gData.adData.setPopClickTimes();
  230. this.TimingRedMoneyArr = gData.gameData.configs.ServerConfig.TimingRedMoney.split(',');
  231. this.ProductionButtonArr = gData.gameData.configs.ServerConfig.ProductionButton.split(',');
  232. this.FullScreenAdArr = gData.gameData.configs.ServerConfig.FullScreenAd.split(',');
  233. let arr = gData.gameData.configs.ServerConfig.ABInsertAdPercent.split(',');
  234. let per = 0;
  235. for (var i = 0; i < arr.length; i++) {
  236. per += parseFloat(arr[i]);
  237. this.ABCInsertAdPercentArr[i] = per;
  238. }
  239. this.ABCInsertAdArr = gData.gameData.configs.ServerConfig.ABInsertAd.split(',');
  240. this.FullCsahAdArr = gData.gameData.configs.ServerConfig.FullCsahAd.split(',');
  241. }
  242. /** 设置用户ecpm分级, 自动弹窗字典等 */
  243. public setEcpmLevel() {
  244. // //test
  245. // this.ecpmLevel = 1;
  246. // this.AutoRedMoneyMap.set(1, 20);
  247. // return;
  248. let forceAd = gData.gameData.configs.ForceAd;
  249. let len = forceAd.length;
  250. let ecpmlevel = -1;
  251. for (var i = 0; i < len; i++) {
  252. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  253. if (ecpmlevel == -1) {
  254. ecpmlevel = parseInt(forceAd[i].value);
  255. }
  256. this.AutoRedMoneyMap.set(parseInt(forceAd[i].value), parseInt(forceAd[i].autoRedMoney))
  257. }
  258. }
  259. this.ecpmLevel = ecpmlevel;
  260. }
  261. /** 检查是否显示插屏、互推(概率弹出)
  262. * @type 1:弹出全屏插屏广告 2:延时弹出大插屏 3:先弹出插屏,再弹出大插屏 4:互推红包
  263. */
  264. checkShowFullInter(type, des = null, rateType = null) {
  265. let per = 0;
  266. let pop = true;
  267. switch (type) {
  268. case 1:
  269. if (rateType != null) {
  270. per = this.getPerByEcpm(rateType);
  271. } else {
  272. per = this.getPerByEcpm(RateConfig.RC_fullScreen);
  273. }
  274. pop = Math.random() < per;
  275. if (!pop) {
  276. return pop;
  277. }
  278. if (this.FullScreenAdArr.indexOf(this.ecpmLevel.toString()) == -1) {
  279. return;
  280. }
  281. mk.ad.showInterAd(1, des);
  282. break;
  283. case 2:
  284. if (rateType != null) {
  285. per = this.getPerByEcpm(rateType);
  286. } else {
  287. per = this.getPerByEcpm(RateConfig.RC_tableScreen);
  288. }
  289. pop = Math.random() < per;
  290. if (!pop) {
  291. return pop;
  292. }
  293. let delayArr = gData.gameData.configs.ServerConfig.AdDelay.split(',');
  294. let min = parseFloat(delayArr[0]);
  295. let max = parseFloat(delayArr[1]);
  296. let delay = (min + (max - min) * Math.random()) * 1000;
  297. setTimeout(() => {
  298. mk.ad.showInterAd(2, des);
  299. }, delay);
  300. break;
  301. case 3:
  302. if (rateType != null) {
  303. per = this.getPerByEcpm(rateType);
  304. } else {
  305. per = this.getPerByEcpm(RateConfig.RC_tableScreen);
  306. }
  307. pop = Math.random() < per;
  308. if (!pop) {
  309. return pop;
  310. }
  311. let delayArr1 = gData.gameData.configs.ServerConfig.AdDelay.split(',');
  312. let min1 = parseFloat(delayArr1[0]);
  313. let max1 = parseFloat(delayArr1[1]);
  314. let delay1 = (min1 + (max1 - min1) * Math.random()) * 1000;
  315. let delay2 = (min1 + (max1 - min1) * Math.random()) * 1000;
  316. setTimeout(() => {
  317. mk.ad.showInterAd(0, des);
  318. setTimeout(() => {
  319. mk.ad.showInterAd(2, des);
  320. }, delay2);
  321. }, delay1);
  322. break;
  323. case 4:
  324. if (rateType != null) {
  325. per = this.getPerByEcpm(rateType);
  326. } else {
  327. per = this.getPerByEcpm(RateConfig.RC_moreGameRedBag);
  328. }
  329. pop = Math.random() < per;
  330. if (!pop) {
  331. return pop;
  332. }
  333. gData.moreGame.popNewOpenRedBag();
  334. break;
  335. }
  336. return pop;
  337. }
  338. /** 弹出插屏 */
  339. checkPopInter(des, rateType = null) {
  340. if (this.ABCInsertAdArr.indexOf(this.ecpmLevel.toString()) == -1) {
  341. return;
  342. }
  343. let ran = Math.random();
  344. let len = this.ABCInsertAdPercentArr.length;
  345. let index = 0;
  346. for (var i = 0; i < len; i++) {
  347. if (ran <= this.ABCInsertAdPercentArr[i]) {
  348. index = i + 2;
  349. break;
  350. }
  351. }
  352. this.checkShowFullInter(index, des, rateType);
  353. }
  354. /** 点击提现弹出全屏插屏 */
  355. checkPopCashFull() {
  356. if (this.FullCsahAdArr.indexOf(this.ecpmLevel.toString()) == -1) {
  357. return;
  358. }
  359. mk.ad.showInterAd(1);
  360. }
  361. checkShowVideoIcon() {
  362. if (this.FullCsahAdArr.indexOf(this.ecpmLevel.toString()) == -1) {
  363. return false;
  364. }
  365. return true;
  366. }
  367. //定时弹出计时
  368. private timeAd = 0;
  369. private test = true;
  370. /** 定时弹出红包 */
  371. startPopRed(dt) {
  372. if (mk.guide.isGuiding() || mk.ui.getCurOnPanel('redBagTask') || mk.ui.getCurOnPanel('productReward2')) {
  373. this.timeAd = 0;
  374. return;
  375. }
  376. if (gData.gameData.isTouchScreen) {
  377. gData.gameData.isTouchScreen = false;
  378. this.timeAd = 0;
  379. return;
  380. }
  381. if (this.TimingRedMoneyArr.indexOf(this.ecpmLevel.toString()) == -1) {
  382. return;
  383. }
  384. this.timeAd += dt;
  385. let span = this.AutoRedMoneyMap.get(this.ecpmLevel);
  386. if (this.timeAd >= span) {
  387. this.timeAd = 0;
  388. // mk.ad.videoAdType = VideoAdType.video_init_19;
  389. // gData.gameData.init_hideRedBag = true;
  390. // mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  391. //this.checkPopInter(InterAdType.interstitial1_click_19);
  392. if (gData.gameData.insertAdSwitch[13] == "1") {
  393. gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_4);
  394. }
  395. }
  396. }
  397. /** 需要弹出红包的点击数 */
  398. popClickTimes = 0;
  399. /** 累计点击数 */
  400. clickTimesAdd = 0;
  401. setPopClickTimes() {
  402. let arr = gData.gameData.configs.ServerConfig.ClickProduction.split(',');
  403. this.popClickTimes = Util.rnd(parseInt(arr[0]), parseInt(arr[1]));
  404. }
  405. checkPopRed() {
  406. if (this.ProductionButtonArr.indexOf(this.ecpmLevel.toString()) == -1) {
  407. return;
  408. }
  409. if (mk.guide.isGuiding()) {
  410. return;
  411. }
  412. this.clickTimesAdd++;
  413. if (this.clickTimesAdd >= this.popClickTimes) {
  414. this.clickTimesAdd = 0;
  415. this.setPopClickTimes();
  416. if (Math.random() <= this.getPerByEcpm()) {
  417. mk.ad.videoAdType = VideoAdType.video_init_17;
  418. mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  419. }
  420. }
  421. }
  422. getPerByEcpm(type: RateConfig = RateConfig.RC_fullScreen) {
  423. // //test
  424. // return 0.26;
  425. let forceAd = gData.gameData.configs.ForceAd;
  426. let len = forceAd.length;
  427. let per = 0;
  428. for (var i = 0; i < len; i++) {
  429. switch (type) {
  430. case RateConfig.RC_fullScreen:
  431. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  432. per = parseFloat(forceAd[i].qpPercent);
  433. return per;
  434. }
  435. case RateConfig.RC_tableScreen:
  436. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  437. per = parseFloat(forceAd[i].cpPercent);
  438. return per;
  439. }
  440. case RateConfig.RC_banner:
  441. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  442. per = parseFloat(forceAd[i].baPercent);
  443. return per;
  444. }
  445. case RateConfig.RC_infrormationFlow:
  446. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  447. per = parseFloat(forceAd[i].xxPercent);
  448. return per;
  449. }
  450. case RateConfig.RC_splash:
  451. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  452. per = parseFloat(forceAd[i].kpPercent);
  453. return per;
  454. }
  455. case RateConfig.RC_superDouble:
  456. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  457. per = parseFloat(forceAd[i].jbPercent);
  458. return per;
  459. }
  460. case RateConfig.RC_moreGameRedBag:
  461. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  462. per = parseFloat(forceAd[i].htPercent);
  463. return per;
  464. }
  465. case RateConfig.RC_popSpeedUp:
  466. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  467. per = parseFloat(forceAd[i].jsPercent);
  468. return per;
  469. }
  470. case RateConfig.RC_afterVideo:
  471. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  472. per = parseFloat(forceAd[i].cpjlPercent);
  473. return per;
  474. }
  475. }
  476. }
  477. return per;
  478. }
  479. async savePreLoadEcpm(data) {
  480. let times = gData.gameData.getProp(GameProp.videoTimes);
  481. console.log('savePreLoadEcpm times ', times)
  482. if (!times) {
  483. console.log('savePreLoadEcpm data ', data.adsource_price)
  484. let response = await mk.http.sendData('user/savePreLoadEcpm', data);
  485. if (response.errcode != 0) {
  486. return;
  487. }
  488. this.getOrderTaskInfo(0);
  489. }
  490. }
  491. async getOrderTaskInfo(isDefault) {
  492. if (!gData.gameData.playerProp.orderData) {
  493. let data = {};
  494. data["isDefault"] = isDefault;
  495. let response = await mk.http.sendData('orderTask/getUserOrderTaskInfo', data);
  496. if (response.errcode != 0) {
  497. return;
  498. }
  499. gData.gameData.playerProp.orderData = response.data.userOrderTaskInfo;
  500. mk.event.emit("initOrderUi");
  501. }
  502. }
  503. }
  504. /**
  505. * 看视频类型
  506. */
  507. export enum AdFun {
  508. bubble = 1, //气泡视频
  509. checkpoint = 2, //关卡消除视频
  510. settlement = 3, //关卡通关视频
  511. turntable = 4, //转盘视频
  512. sign = 5, //签到视频
  513. bigCash = 6, //福袋视频
  514. cashOutAddCash = 8, //钱包提现加现金视频
  515. harvest = 9, //收获超级加倍视频
  516. farmMap = 10, //图鉴领取视频
  517. lineUp = 11, //插队视频
  518. addProductTimes = 12,//获得生产次数
  519. }
  520. export enum RateConfig {
  521. RC_fullScreen,
  522. RC_tableScreen,
  523. RC_banner,
  524. RC_infrormationFlow,
  525. RC_splash,
  526. RC_superDouble,
  527. RC_moreGameRedBag,
  528. RC_popSpeedUp,
  529. RC_afterVideo
  530. }