ADController.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", { value: !0 }),
  5. (i.ADController = i.AdSharePriority = i.AdShareStatus = i.InterAdType = i.AdType = void 0);
  6. const c = t("App"),
  7. n = t("GameText"),
  8. s = t("BaseController"),
  9. o = t("ViewManager"),
  10. r = t("Toast"),
  11. a = t("NotificationConst"),
  12. l = t("ViewConst"),
  13. h = t("ADManageBase"),
  14. d = t("ADModel");
  15. var u, p;
  16. ((t = i.AdType || (i.AdType = {}))[(t.IDLE_DOUBLE = 0)] = "IDLE_DOUBLE"),
  17. (t[(t.IDLE_5X = 1)] = "IDLE_5X"),
  18. (t[(t.AD_RATE_BUFF = 2)] = "AD_RATE_BUFF"),
  19. (t[(t.AD_REWRAD = 3)] = "AD_REWRAD"),
  20. (t[(t.BUFF_EMPLOYEE_PRODUCTION_SPEED = 4)] = "BUFF_EMPLOYEE_PRODUCTION_SPEED"),
  21. (t[(t.BUFF_EMPLOYEE_MOVE_SPEED = 5)] = "BUFF_EMPLOYEE_MOVE_SPEED"),
  22. (t[(t.BUFF_CUSTOMER_MOVE_SPEED = 6)] = "BUFF_CUSTOMER_MOVE_SPEED"),
  23. (t[(t.SHOP_BOX = 7)] = "SHOP_BOX"),
  24. ((t = i.InterAdType || (i.InterAdType = {}))[(t.normal = 0)] = "normal"),
  25. (t[(t.full = 1)] = "full"),
  26. ((t = u = i.AdShareStatus || (i.AdShareStatus = {}))[(t.NONE = 0)] = "NONE"),
  27. (t[(t.AD = 1)] = "AD"),
  28. (t[(t.SHARE = 2)] = "SHARE"),
  29. (t[(t.PAY = 3)] = "PAY"),
  30. (t[(t.SUPER_CASH = 4)] = "SUPER_CASH"),
  31. (t[(t.FREE = 5)] = "FREE"),
  32. ((t = p = i.AdSharePriority || (i.AdSharePriority = {}))[(t.NONE = 0)] = "NONE"),
  33. (t[(t.AD = 1)] = "AD"),
  34. (t[(t.SHARE = 2)] = "SHARE"),
  35. (t[(t.PAY = 3)] = "PAY"),
  36. (t[(t.SUPER_CASH = 4)] = "SUPER_CASH");
  37. class f extends s.default {
  38. constructor() {
  39. super(),
  40. (this.adResolve = null),
  41. (this.curAdType = null),
  42. (this.curAdStatus = null),
  43. (this._model = null),
  44. this.init(),
  45. (this._model = new d.ADModel(this)),
  46. c.default.NotificationCenter.addListener(a.NotificationConst.INIT_GAME_FINISH, this.initGame, this, 1);
  47. }
  48. static getInstance() {
  49. return null == this.instance && (this.instance = new f()), this.instance;
  50. }
  51. get isRemoveAD() {
  52. return false;//this._model.adAndShareData.isRemoveAd;
  53. }
  54. init() {
  55. this.registerFunc(0, this.openAdByTypeAsync, this),
  56. this.registerFunc(1, this.registerItem, this),
  57. this.registerFunc(2, this.unregisterItem, this),
  58. this.registerFunc(3, this.getAdTabData, this),
  59. this.registerFunc(4, this.getAdCntData, this),
  60. this.registerFunc(5, this.adIsHas, this),
  61. this.registerFunc(8, this.onGetIsFree, this),
  62. this.registerFunc(
  63. 6,
  64. t => {
  65. this._model.adAndShareData.isRemoveAd = false// t ? 1 : 0;
  66. },
  67. this
  68. ),
  69. c.default.NotificationCenter.addListener(h.AdEvent.AD_SWITCH_STATUS, this.changeBtnWithADStatus, this),
  70. c.default.NotificationCenter.addListener(h.AdEvent.SHOW_AD_RESULT, this.onShowAdResult, this),
  71. c.default.NotificationCenter.addListener(a.NotificationConst.ON_HIDE, this.onHide, this),
  72. c.default.NotificationCenter.addListener(a.NotificationConst.LOGOUT, this.onLogout, this);
  73. }
  74. onHide() {
  75. this.adResolve;
  76. }
  77. initGame() {
  78. this._model.initShareStaticData(),
  79. c.default.NotificationCenter.removeListener(a.NotificationConst.INIT_GAME_FINISH, this.initGame, this);
  80. }
  81. onSystemOpen(t, e) { }
  82. initInteractionAd() {
  83. c.default.NotificationCenter.addListener(o.default.VIEW_IS_OPEN, this.onViewOpen, this),
  84. (this._model.interactionAdConf = c.default.ConfigManager.gameConf.interactionAd),
  85. c.default.TimerManager.doTimer(
  86. this._model.interactionAdConf.startShowTime,
  87. 1,
  88. this.showInteractionAdTimer,
  89. this
  90. );
  91. }
  92. showInteractionAdTimer() {
  93. this.showInteractionAd();
  94. }
  95. onViewOpen(t) { }
  96. onViewClose(t) {
  97. t = l.ViewConst[t];
  98. this._model.interactionAdConf.view[t] &&
  99. (Math.random() < this._model.interactionAdConf.view[t] + this._model.interProbability
  100. ? (this.showInteractionAd(), (this._model.interProbability = 0))
  101. : this._model.interProbability < 0.5 && (this._model.interProbability += 0.04));
  102. }
  103. showInteractionAd() { }
  104. getAdTabData(t) {
  105. return this._model.getAdShareConf(t);
  106. }
  107. getAdCntData(t) {
  108. return this._model.getData(t);
  109. }
  110. adIsHas(t) {
  111. var e = this._model.getAdShareConf(t),
  112. t = this._model.getData(t);
  113. return e.adTimes > t.adCnt;
  114. }
  115. onLogout() {
  116. this._model.reset(),
  117. c.default.NotificationCenter.addListener(a.NotificationConst.INIT_GAME_FINISH, this.initGame, this, 1);
  118. }
  119. changeBtnWithADStatus() {
  120. for (var t in this._model.registerItems) {
  121. var e = parseInt(t);
  122. for (const i of this._model.registerItems[t]) this.checkItem(e, i);
  123. }
  124. }
  125. onShowAdResult(e) {
  126. var i = 0 === e.code;
  127. if (i && null !== this.curAdType) {
  128. e.status = this.curAdStatus;
  129. let t = this._model.getData(this.curAdType);
  130. this.curAdStatus === u.AD
  131. ? (t.adCnt++, this._model.addAdNum(), c.default.AnalyticMgr.AD(this.curAdType, i ? 1 : 0))
  132. : this.curAdStatus === u.FREE
  133. ? this.isRemoveAD
  134. ? t.adCnt++
  135. : t.freeCnt++
  136. : this.curAdStatus === u.SHARE
  137. ? (t.shareCnt++, c.default.AnalyticMgr.AD(this.curAdType + 1e3, i ? 1 : 0))
  138. : this.curAdStatus === u.SUPER_CASH && t.superCashCnt++,
  139. (this.curAdStatus = this.curAdType = null),
  140. localStorage.getItem("isfirstAD") ||
  141. (localStorage.setItem("isfirstAD", "isfirstAD"),
  142. console.log("第一次观看广告"),
  143. c.default.AnalyticMgr.recordFirstAD({
  144. api_token: c.default.GameDataMsr.playerInfo.token,
  145. type: this.curAdType,
  146. module: "first_ad"
  147. }));
  148. }
  149. this.adResolve && (this.adResolve(e), (this.adResolve = null)),
  150. this.changeBtnWithADStatus(),
  151. c.default.TimerManager.doTimer(
  152. 1e3,
  153. 1,
  154. () => {
  155. c.default.SoundManager.resumeMusic();
  156. },
  157. this
  158. );
  159. }
  160. openAdByTypeAsync(o, a) {
  161. return new Promise(t => {
  162. let e = this._model.adShareStatus[o];
  163. isNaN(e) && t(!1);
  164. var i = c.default.Platform.getAdState(o);
  165. if (1 == i) return r.default.launch(n.GameText.getText(61)), void t(!1);
  166. if (3 == i) return r.default.launch(n.GameText.getText(62)), void t(!1);
  167. if (
  168. ((this.curAdType = o),
  169. (this.adResolve = t),
  170. (this.curAdStatus = e),
  171. e == u.NONE && r.default.launch(n.GameText.getText(60)),
  172. e == u.AD)
  173. )
  174. c.default.SoundManager.pauseMusic(), c.default.Platform.showAD(o);
  175. else if (e == u.FREE) this.onShowAdResult({ code: 0 });
  176. else if (e == u.SHARE) {
  177. c.default.SoundManager.pauseMusic();
  178. var s = this._model.getShareData();
  179. c.default.Platform.share(o, {
  180. url: s.sharePic,
  181. title: s.shareMessage,
  182. description: "",
  183. paramList: {
  184. chl: c.default.ConfigManager.gameConf.channel,
  185. playerid: c.default.GameDataMsr.playerInfo.id + "",
  186. shareType: o
  187. },
  188. extraParam: a
  189. });
  190. } else if (e == u.SUPER_CASH) {
  191. (t = this._model.getAdShareConf(o)), (s = this._model.getData(o));
  192. const e = (t.price - s.superCashCnt * t.addSuperCash) * (a || 1);
  193. WorldScene.instance.subSuperMoney(e)
  194. ? (this.onShowAdResult({ code: 0 }), c.default.Platform.recordDiamondCost(o + 100, e))
  195. : this.onShowAdResult({ code: -1 });
  196. } else this.onShowAdResult({ code: -1 });
  197. });
  198. }
  199. unregisterItem(t, e) {
  200. this._model.registerItems[t] &&
  201. (-1 < (e = this._model.registerItems[t].indexOf(e)) && this._model.registerItems[t].splice(e, 1),
  202. 0 === this._model.registerItems[t].length && delete this._model.registerItems[t]);
  203. }
  204. registerItem(t, e) {
  205. this._model.registerItems[t]
  206. ? -1 === this._model.registerItems[t].indexOf(e) &&
  207. (this._model.registerItems[t].push(e), this.checkItem(t, e))
  208. : ((this._model.registerItems[t] = [e]), this.checkItem(t, e));
  209. }
  210. isCanToShare(t) {
  211. var e = this._model.getData(t),
  212. t = this._model.getAdShareConf(t);
  213. return e.shareCnt < t.shareTimes;
  214. }
  215. checkItem(t, e) {
  216. var i = this._model.getData(t);
  217. if (i) {
  218. var s = this._model.getAdShareConf(t);
  219. if (e && s) {
  220. var o = i.adCnt,
  221. a = i.shareCnt,
  222. n = i.freeCnt || 0,
  223. r = o + a + n,
  224. l = c.default.Platform.isCanShare() && 0 < s.shareTimes && s.shareTimes > a;
  225. if (s.totalTimes > r) {
  226. if (s.freeCnt && s.freeCnt > n)
  227. return e.toFree && e.toFree(t, s, i), void (this._model.adShareStatus[t] = u.FREE);
  228. switch (s.type) {
  229. case p.AD:
  230. if (this.isRemoveAD && s.adTimes > o)
  231. return e.toFree && e.toFree(t, s, i), void (this._model.adShareStatus[t] = u.FREE);
  232. if (3 !== (h = c.default.Platform.getAdState(t)) && s.adTimes > o)
  233. return e.toAd && e.toAd(t, s, i, h), void (this._model.adShareStatus[t] = u.AD);
  234. if (l)
  235. return e.toShare && e.toShare(t, s, i), void (this._model.adShareStatus[t] = u.SHARE);
  236. if (0 < s.superCashTimes && s.superCashTimes > a)
  237. return (
  238. e.toSupercash && e.toSupercash(t, s, i),
  239. void (this._model.adShareStatus[t] = u.SUPER_CASH)
  240. );
  241. if (3 === h && s.adTimes > o)
  242. return e.toAd && e.toAd(t, s, i, h), void (this._model.adShareStatus[t] = u.AD);
  243. break;
  244. case p.SHARE:
  245. var h = c.default.Platform.getAdState(t);
  246. if (l)
  247. return e.toShare && e.toShare(t, s, i), void (this._model.adShareStatus[t] = u.SHARE);
  248. if (0 < s.adTimes && s.adTimes > o && 3 !== h)
  249. return e.toAd && e.toAd(t, s, i, h), void (this._model.adShareStatus[t] = u.AD);
  250. if (0 < s.superCashTimes && s.superCashTimes > a)
  251. return (
  252. e.toSupercash && e.toSupercash(t, s, i),
  253. void (this._model.adShareStatus[t] = u.SUPER_CASH)
  254. );
  255. break;
  256. case p.PAY:
  257. if (s.payTimes > r)
  258. return e.toPay && e.toPay(t, s, i), void (this._model.adShareStatus[t] = u.PAY);
  259. break;
  260. case p.SUPER_CASH:
  261. if (s.superCashTimes > i.superCashCnt)
  262. return (
  263. e.toSupercash && e.toSupercash(t, s, i),
  264. void (this._model.adShareStatus[t] = u.SUPER_CASH)
  265. );
  266. }
  267. }
  268. }
  269. e.toFail && e.toFail(t, s, i, 3), (this._model.adShareStatus[t] = u.NONE);
  270. }
  271. }
  272. onGetIsFree(t) {
  273. var e = this._model.getData(t);
  274. if (!e) return !1;
  275. var i = this._model.getAdShareConf(t);
  276. if (i) {
  277. var s = e.adCnt,
  278. t = e.shareCnt,
  279. e = e.freeCnt || 0;
  280. if (i.totalTimes > s + t + e && i.freeCnt && i.freeCnt > e) return !0;
  281. }
  282. return !1;
  283. }
  284. }
  285. i.ADController = f;