AdData.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import { Data } from "../../mk/data/Data";
  2. import { GameProp } from "./GameData";
  3. /**
  4. * @description 广告数据
  5. * @author 邹勇
  6. */
  7. export class AdData {
  8. public placementId = '';
  9. public adunit_format = '';
  10. public network_type = '';
  11. public network_placement_id = '';
  12. public network_firm_id = '';
  13. public adsource_id = '';
  14. public adsource_index = '';
  15. public adsource_price = '100';
  16. public adsource_isheaderbidding = '';
  17. public publisher_revenue = '';
  18. public precision = '';
  19. public ecpm_level = '';
  20. /** 视频类型 */
  21. public ad_subType: AdFun;
  22. private _watchNumToday: number = 0;
  23. /** 当天看的视频次数 */
  24. public set watchNumToday(v: number) {
  25. this._watchNumToday = v;
  26. }
  27. public get watchNumToday(): number {
  28. return this._watchNumToday;
  29. }
  30. private adMap: Map<number, Data>
  31. /** 全屏插屏弹出规则 */
  32. private fullInterShowStr = ''
  33. public init() {
  34. this.adMap = new Map<number, Data>();
  35. this.adMap.set(AdFun.bubble, gData.reward)
  36. this.adMap.set(AdFun.checkpoint, gData.reward)
  37. this.adMap.set(AdFun.settlement, gData.reward)
  38. this.adMap.set(AdFun.turntable, gData.turnable)
  39. this.adMap.set(AdFun.sign, gData.sign)
  40. this.adMap.set(AdFun.bigCash, gData.blessingBag)
  41. }
  42. /**
  43. * 每次视频次数是否已经到达上限
  44. * @returns true 已达最大次数 false没有,可以有奖励
  45. */
  46. public checkAdMax() {
  47. this.watchNumToday++;
  48. let max = parseInt(gData.gameData.configs.ServerConfig.VideoTimesMax);
  49. if (this.watchNumToday > max) {
  50. mk.tip.pop("今日看广告获得奖励的次数已用完", 1);
  51. mk.ui.closeAllUI();
  52. return true;
  53. }
  54. else {
  55. return false;
  56. }
  57. }
  58. public updateData(placementId, data) {
  59. mk.console.logSingle("updateADData:" + placementId, data);
  60. this.placementId = placementId;
  61. this.adunit_format = data.adunit_format;
  62. this.network_type = data.network_type;
  63. this.network_placement_id = data.network_placement_id;
  64. this.network_firm_id = data.network_firm_id;
  65. this.adsource_id = data.adsource_id;
  66. this.adsource_index = data.adsource_index;
  67. this.adsource_price = data.adsource_price;
  68. this.adsource_isheaderbidding = data.adsource_isheaderbidding;
  69. this.publisher_revenue = data.publisher_revenue;
  70. this.precision = data.precision;
  71. this.ecpm_level = data.ecpm_level;
  72. }
  73. public async watchVideo(type: AdFun) {
  74. this.ad_subType = type;
  75. let data = {
  76. "imei": gData.appData.machineInfo.imei,
  77. "idfa": gData.appData.machineInfo.idfa,
  78. "oaid": gData.appData.machineInfo.oaid,
  79. "uin": gData.loginData.uin,
  80. "version": gData.appData.appVersion,
  81. "tf_channel": gData.appData.tfChannel,
  82. "destoon_ad_place": this.placementId,
  83. "ad_type": 1,
  84. "adunit_format": this.adunit_format,
  85. "network_type": this.network_type,
  86. "network_placement_id": this.network_placement_id,
  87. "network_firm_id": this.network_firm_id,
  88. "adsource_id": this.adsource_id,
  89. "adsource_index": this.adsource_index,
  90. "adsource_price": this.adsource_price,
  91. "adsource_isheaderbidding": this.adsource_isheaderbidding,
  92. "publisher_revenue": this.publisher_revenue,
  93. "precision_ecpm": this.precision,
  94. "ecpm_level": this.ecpm_level,
  95. "cfg_version": gData.appData.version,
  96. "adsource_ecpm": gData.gameData.adShowConfig.average_ecpm,
  97. "ad_sbuType": this.ad_subType,
  98. }
  99. mk.console.logSingle("updateVideoData:", data);
  100. let response = await mk.http.sendData('updateVideo', data);
  101. if (response.errcode != 0) {
  102. return;
  103. }
  104. let times = gData.gameData.getProp(GameProp.videoTimes);
  105. gData.gameData.setProp(GameProp.videoTimes, ++times);
  106. if (times < 5) {
  107. mk.data.sendXYEvent("video_end_" + times, "第" + times + "次看视频");
  108. }
  109. let curData = this.adMap.get(this.ad_subType)
  110. if (curData) {
  111. curData.setAdData(response.data);
  112. }
  113. //达到任务之后计算视频
  114. if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) {
  115. gData.safeDepositBoxData.richBankDailyVideoTimes++
  116. if (gData.safeDepositBoxData.richBankDailyVideoTimes == gData.safeDepositBoxData.richBankDailyTotelVideoTimes) {
  117. mk.data.sendDataEvent("Bank", "银行-当日任务完成")
  118. }
  119. }
  120. }
  121. /** 更新其他广告次数
  122. * @param type 1:激励视频完播、2:插屏展示、3:信息流展示、 4:激励视频展⽰、5:激励视频加载失败、6:开屏展示、7:banner展示、
  123. * 8:插屏-全屏视频 完播、9:插屏-全屏视频 展示、10:插屏-全屏视频 加载失败、11:插屏加载失败、12:信息流加载失败、13:开屏加载失败、14:banner加载失败、
  124. * 51:激励视频点击、52:插屏点击、53:信息流点击、54:开屏点击、55:banner点击、56:插屏-全屏视频点击
  125. * 71:激励视频去重点击、72:插屏去重点击、73:信息流去重点击、74:开屏去重点击、75:banner去重点击、76:插屏-全屏视频去重点击
  126. */
  127. public async updateADLog(type, placementId, data = null) {
  128. let sData = null
  129. if (!data) {
  130. sData = {
  131. "imei": gData.appData.machineInfo.imei,
  132. "idfa": gData.appData.machineInfo.idfa,
  133. "oaid": gData.appData.machineInfo.oaid,
  134. "uin": gData.loginData.uin,
  135. "version": gData.appData.appVersion,
  136. "tf_channel": gData.appData.tfChannel,
  137. "destoon_ad_place": placementId,
  138. "ad_type": type,
  139. "adunit_format": '',
  140. "network_type": '',
  141. "network_placement_id": '',
  142. "network_firm_id": '',
  143. "adsource_id": '',
  144. "adsource_index": '',
  145. "adsource_price": '',
  146. "adsource_isheaderbidding": '',
  147. "publisher_revenue": '',
  148. "precision": '',
  149. "ecpm_level": '',
  150. "platformRisk": 1
  151. }
  152. }
  153. else {
  154. sData = {
  155. "imei": gData.appData.machineInfo.imei,
  156. "idfa": gData.appData.machineInfo.idfa,
  157. "oaid": gData.appData.machineInfo.oaid,
  158. "uin": gData.loginData.uin,
  159. "version": gData.appData.appVersion,
  160. "tf_channel": gData.appData.tfChannel,
  161. "destoon_ad_place": placementId,
  162. "ad_type": type,
  163. "adunit_format": data.adunit_format,
  164. "network_type": data.network_type,
  165. "network_placement_id": data.network_placement_id,
  166. "network_firm_id": data.network_firm_id,
  167. "adsource_id": data.adsource_id,
  168. "adsource_index": data.adsource_index,
  169. "adsource_price": data.adsource_price,
  170. "adsource_isheaderbidding": data.adsource_isheaderbidding,
  171. "publisher_revenue": data.publisher_revenue,
  172. "precision": data.precision,
  173. "ecpm_level": data.ecpm_level,
  174. "platformRisk": 1
  175. }
  176. }
  177. let response = await mk.http.sendData('updateADLog', sData);
  178. if (response && response.errcode == 0) {
  179. if (response.data) {
  180. mk.console.logSingle('solution ', response);
  181. //0-无处理;1-警告;2-封广告30分钟;3-封广告12小时;4-用户拉黑
  182. gData.warnTipData.setSolution(response.data.solution);
  183. gData.warnTipData.setShutdownAds(response.data.shutdown_ads);
  184. }
  185. }
  186. }
  187. /** 设置关闭红包弹出全屏插屏序列 */
  188. setFullInterShowStr() {
  189. let fullInterShowStrArr = gData.gameData.configs.GlobalCfg.fullInterShowStrArr.split(';');
  190. for (var i = 0; i < fullInterShowStrArr.length; i++) {
  191. let tempArr = fullInterShowStrArr[i].split(',');
  192. if (gData.gameData.adShowConfig.average_ecpm <= tempArr[1]) {
  193. this.fullInterShowStr = tempArr[2];
  194. break;
  195. }
  196. }
  197. }
  198. /** 检查是否显示全屏插屏
  199. * @type 不同情况弹出类型 1:提现结束判断ecpm低于一定值弹出 2:关闭红包界面不观看激励视频有概率拉起全屏广告
  200. */
  201. checkShowFullInter(type) {
  202. //全屏广告开关
  203. if (gData.gameData.configs.GlobalCfg.popFullInter != "1") {
  204. return
  205. }
  206. if (type == 1) {
  207. if (gData.gameData.adShowConfig.average_ecpm <= gData.gameData.configs.GlobalCfg.popFullEcpmAfterCash) {
  208. mk.ad.showInterAd(1);
  209. }
  210. }
  211. else if (type == 2) {
  212. if (this.fullInterShowStr) {
  213. let popFullIndex = mk.storage.getStorage('popFullIndex');
  214. if (popFullIndex == null) {
  215. popFullIndex = 0;
  216. }
  217. else {
  218. popFullIndex++;
  219. }
  220. mk.storage.setStorage('popFullIndex', popFullIndex);
  221. let index = popFullIndex % this.fullInterShowStr.length;
  222. mk.console.log('checkShowFullInter this.fullInterShowStr ', this.fullInterShowStr);
  223. mk.console.log('checkShowFullInter index', index);
  224. if (this.fullInterShowStr[index] == '1') {
  225. mk.console.log('checkShowFullInter showInterAd');
  226. mk.ad.showInterAd(1);
  227. }
  228. }
  229. }
  230. }
  231. }
  232. /**
  233. * 看视频类型
  234. */
  235. export enum AdFun {
  236. bubble = 1, //气泡视频
  237. checkpoint = 2, //关卡消除视频
  238. settlement = 3, //关卡通关视频
  239. turntable = 4, //转盘视频
  240. sign = 5, //签到视频
  241. bigCash = 6, //福袋视频
  242. }