AdData.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. */
  125. public updateADLog(type, placementId, data = null) {
  126. let sData = null
  127. if (!data) {
  128. sData = {
  129. "imei": gData.appData.machineInfo.imei,
  130. "idfa": gData.appData.machineInfo.idfa,
  131. "oaid": gData.appData.machineInfo.oaid,
  132. "uin": gData.loginData.uin,
  133. "version": gData.appData.appVersion,
  134. "tf_channel": gData.appData.tfChannel,
  135. "destoon_ad_place": placementId,
  136. "ad_type": type,
  137. "adunit_format": '',
  138. "network_type": '',
  139. "network_placement_id": '',
  140. "network_firm_id": '',
  141. "adsource_id": '',
  142. "adsource_index": '',
  143. "adsource_price": '',
  144. "adsource_isheaderbidding": '',
  145. "publisher_revenue": '',
  146. "precision": '',
  147. "ecpm_level": ''
  148. }
  149. }
  150. else {
  151. sData = {
  152. "imei": gData.appData.machineInfo.imei,
  153. "idfa": gData.appData.machineInfo.idfa,
  154. "oaid": gData.appData.machineInfo.oaid,
  155. "uin": gData.loginData.uin,
  156. "version": gData.appData.appVersion,
  157. "tf_channel": gData.appData.tfChannel,
  158. "destoon_ad_place": placementId,
  159. "ad_type": type,
  160. "adunit_format": data.adunit_format,
  161. "network_type": data.network_type,
  162. "network_placement_id": data.network_placement_id,
  163. "network_firm_id": data.network_firm_id,
  164. "adsource_id": data.adsource_id,
  165. "adsource_index": data.adsource_index,
  166. "adsource_price": data.adsource_price,
  167. "adsource_isheaderbidding": data.adsource_isheaderbidding,
  168. "publisher_revenue": data.publisher_revenue,
  169. "precision": data.precision,
  170. "ecpm_level": data.ecpm_level
  171. }
  172. }
  173. mk.http.sendData('updateADLog', sData);
  174. }
  175. /** 设置关闭红包弹出全屏插屏序列 */
  176. setFullInterShowStr() {
  177. let fullInterShowStrArr = gData.gameData.configs.GlobalCfg.fullInterShowStrArr.split(';');
  178. for (var i = 0; i < fullInterShowStrArr.length; i++) {
  179. let tempArr = fullInterShowStrArr[i].split(',');
  180. if (gData.gameData.adShowConfig.average_ecpm <= tempArr[1]) {
  181. this.fullInterShowStr = tempArr[2];
  182. break;
  183. }
  184. }
  185. }
  186. /** 检查是否显示全屏插屏
  187. * @type 不同情况弹出类型 1:提现结束判断ecpm低于一定值弹出 2:关闭红包界面不观看激励视频有概率拉起全屏广告
  188. */
  189. checkShowFullInter(type) {
  190. //全屏广告开关
  191. if (gData.gameData.configs.GlobalCfg.popFullInter != "1") {
  192. return
  193. }
  194. if (type == 1) {
  195. if (gData.gameData.adShowConfig.average_ecpm <= gData.gameData.configs.GlobalCfg.popFullEcpmAfterCash) {
  196. mk.ad.showInterAd(1);
  197. }
  198. }
  199. else if (type == 2) {
  200. if (this.fullInterShowStr) {
  201. let popFullIndex = mk.storage.getStorage('popFullIndex');
  202. if (popFullIndex == null) {
  203. popFullIndex = 0;
  204. }
  205. else {
  206. popFullIndex++;
  207. }
  208. mk.storage.setStorage('popFullIndex', popFullIndex);
  209. let index = popFullIndex % this.fullInterShowStr.length;
  210. mk.console.log('checkShowFullInter this.fullInterShowStr ', this.fullInterShowStr);
  211. mk.console.log('checkShowFullInter index', index);
  212. if (this.fullInterShowStr[index] == '1') {
  213. mk.console.log('checkShowFullInter showInterAd');
  214. mk.ad.showInterAd(1);
  215. }
  216. }
  217. }
  218. }
  219. }
  220. /**
  221. * 看视频类型
  222. */
  223. export enum AdFun {
  224. bubble = 1, //气泡视频
  225. checkpoint = 2, //关卡消除视频
  226. settlement = 3, //关卡通关视频
  227. turntable = 4, //转盘视频
  228. sign = 5, //签到视频
  229. bigCash = 6, //福袋视频
  230. }