NativeAdAwardData.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /** 点击信息流奖励数据类 */
  2. import NativeADAwardNode from "../ui/NativeAdAwardNode"
  3. import LogUtil from "../utils/LogUtil"
  4. import AdM from "./AdM"
  5. import GameM from "./GameM"
  6. import UiM from "./UiM"
  7. export default class NativeAdAwardData {
  8. ///单例
  9. private static instance: NativeAdAwardData = null
  10. public static get Instance() {
  11. if (this.instance == null) {
  12. this.instance = new NativeAdAwardData()
  13. }
  14. return this.instance
  15. }
  16. /** 打开点击信息流生效 */
  17. openNativeState = false
  18. /** 已点击信息流 */
  19. hasClickNative = false
  20. nativeAwardChanceArr = null;
  21. nativeShowLevel = 1
  22. nativeAwardTimes = 10
  23. /** 是否可显示领取奖励
  24. * @type 界面类型 1 工厂过热冷却 2 热气球奖励 3 车位上领取金币
  25. */
  26. canGetAward(type) {
  27. let value = GameM.globalStorage.getStorage('nativeAdAwardGet' + type)
  28. if (value == 1) {
  29. return true
  30. }
  31. else {
  32. return false
  33. }
  34. }
  35. /** 设置是否可显示领取奖励
  36. * @type 界面类型 1 工厂过热冷却 2 热气球奖励 3 车位上领取金币
  37. */
  38. setGetAward(type) {
  39. if (GameM.commonData.maxCarLevel < this.nativeShowLevel) {
  40. GameM.globalStorage.setStorage('nativeAdAwardGet' + type, 0)
  41. return
  42. }
  43. let value = GameM.globalStorage.getStorage('lastNativeAdAwardGet' + type)
  44. let chance = Number(this.nativeAwardChanceArr[type - 1])
  45. LogUtil.logV('NativeAdAward ', 'type ' + type)
  46. LogUtil.logV('NativeAdAward ', 'chance ' + chance)
  47. let can = false
  48. switch (type) {
  49. case 1:
  50. //上次出现过,此次必定不出现
  51. if (value != null && value != 0) {
  52. GameM.globalStorage.setStorage('lastNativeAdAwardGet' + type, 0)
  53. return
  54. }
  55. if (Math.random() <= chance) {
  56. can = true
  57. }
  58. break
  59. case 2:
  60. //上次出现过,此次必定不出现
  61. if (value != null && value != 0) {
  62. GameM.globalStorage.setStorage('lastNativeAdAwardGet' + type, 0)
  63. return
  64. }
  65. if (Math.random() <= chance) {
  66. can = true
  67. }
  68. break
  69. case 3:
  70. if (Math.random() <= chance) {
  71. can = true
  72. }
  73. break
  74. }
  75. LogUtil.logV('NativeAdAward ', 'can ' + can)
  76. if (can) {
  77. GameM.globalStorage.setStorage('nativeAdAwardGet' + type, 1)
  78. GameM.globalStorage.setStorage('lastNativeAdAwardGet' + type, 1)
  79. // AdM.onSendEvent('NativeAdAwardCreate' + type, `信息流变现触发${type}`, 'NativeAdAwardCreate')
  80. }
  81. else {
  82. GameM.globalStorage.setStorage('nativeAdAwardGet' + type, 0)
  83. }
  84. }
  85. /**
  86. * 重置是否可显示领取奖励
  87. * @param type 1 工厂过热冷却 2 热气球奖励 3 车位上领取金币
  88. */
  89. resetGetAward(type) {
  90. GameM.globalStorage.setStorage('nativeAdAwardGet' + type, 0)
  91. }
  92. setHasClickNative() {
  93. this.hasClickNative = true
  94. if (UiM.Instance.nativeAdAwardNode) {
  95. UiM.Instance.nativeAdAwardNode.getComponent(NativeADAwardNode).setCanGet()
  96. }
  97. }
  98. }