ShopBoxItem.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var e =
  5. (this && this.__decorate) ||
  6. function (t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. },
  16. s =
  17. (this && this.__awaiter) ||
  18. function (t, n, r, l) {
  19. return new (r = r || Promise)(function (i, e) {
  20. function s(t) {
  21. try {
  22. a(l.next(t));
  23. } catch (t) {
  24. e(t);
  25. }
  26. }
  27. function o(t) {
  28. try {
  29. a(l.throw(t));
  30. } catch (t) {
  31. e(t);
  32. }
  33. }
  34. function a(t) {
  35. var e;
  36. t.done
  37. ? i(t.value)
  38. : ((e = t.value) instanceof r
  39. ? e
  40. : new r(function (t) {
  41. t(e);
  42. })
  43. ).then(s, o);
  44. }
  45. a((l = l.apply(t, n || [])).next());
  46. });
  47. };
  48. Object.defineProperty(i, "__esModule", {value: !0}), (i.ShopBoxItem = void 0);
  49. const o = t("App"),
  50. a = t("GameText"),
  51. n = t("ControllerConst"),
  52. r = (t("ViewConst"), t("ADController"), t("ADManageBase"), t("BagConst")),
  53. l = t("ShopConst"),
  54. h = t("ShopItem"),
  55. {property: c, ccclass: d, menu: u} = cc._decorator;
  56. t = class extends h.ShopItem {
  57. constructor() {
  58. super(...arguments),
  59. (this.title = null),
  60. (this.descLab = null),
  61. (this.costIcon = null),
  62. (this.adBtn = null),
  63. (this.adLab = null),
  64. (this.progressBar = null),
  65. (this.progessLab = null),
  66. (this.adCoolTimeLab = null),
  67. (this.adCoolTime = null),
  68. (this.item = null),
  69. (this.tempTime = 0);
  70. }
  71. initItem() {
  72. (this.item = o.default.ControllerManager.applyFunc(
  73. n.ControllerConst.Item,
  74. r.BagConst.GET_ITEM,
  75. this.data.cfg.itemId
  76. )),
  77. (this.title.string = a.GameText.getTextByStr(this.item.data.name)),
  78. this.data.cfg.diamond && (this.costLab.string = this.data.cfg.diamond.toString()),
  79. this.updateItem(),
  80. this.updateAdState();
  81. }
  82. updateItem() {
  83. var t, e, i, s;
  84. this.data && this.data.cfg.ad
  85. ? ((i = o.default.ControllerManager.applyFunc(n.ControllerConst.AD, 4, 7)),
  86. (e = o.default.ControllerManager.applyFunc(n.ControllerConst.AD, 3, 7)),
  87. i.freeCnt >= e.freeCnt &&
  88. ((this.adLab.string = `${e.adTimes - i.adCnt}/${e.adTimes}`), i.adCnt || (this.data.time = 0)),
  89. (t = this.item.getUseCnt()),
  90. (i = (e = this.item.getCurSuitcaseUpgradeCfg()).level),
  91. (this.title.string = `Lv.${i} ${a.GameText.getTextByStr(this.item.data.name)} `),
  92. 0 < e.upgrade_count
  93. ? ((s = e.upgrade_count),
  94. (this.progessLab.string = `${t} /${s}`),
  95. (this.progressBar.progress = t / s))
  96. : ((this.progessLab.node.active = !1), (this.progressBar.progress = 1)))
  97. : this.item &&
  98. (this.item.cnt
  99. ? ((this.costIcon.active = !1), (this.costLab.string = `${this.item.cnt}/1`))
  100. : ((this.costIcon.active = !0), (this.costLab.string = this.data.cfg.diamond.toString())),
  101. this.descLab) &&
  102. ((s = this.item.getRuleByKey(r.CostumeItemRuleKey.NORMAL)),
  103. (this.descLab.string = "" + (s.cnt - this.item.getSpecialRuleCnt(r.CostumeItemRuleKey.NORMAL))));
  104. }
  105. updateTime() {
  106. var e = o.default.DateUtils.Now();
  107. if (this.adCoolTime) {
  108. let t = this.adCoolTime - e;
  109. t < 0 && ((t = 0), (this.adCoolTime = 0), this.updateAdState()),
  110. (this.adCoolTimeLab.string = "下一次广告奖励:\n" + o.default.DateUtils.getFormatBySecond(t / 1e3, 10));
  111. }
  112. }
  113. update(t) {
  114. this.adCoolTime && ((this.tempTime -= t), this.tempTime <= 0 && ((this.tempTime = 0.5), this.updateTime()));
  115. }
  116. updateAdState() {
  117. var t, e;
  118. this.data.cfg.ad &&
  119. ((t = o.default.ControllerManager.applyFunc(n.ControllerConst.AD, 5, 7)),
  120. o.default.DateUtils.secondNow() < (e = this.data.cfg.ad + this.data.time) && t
  121. ? ((this.adCoolTime = 1e3 * e), (this.adBtn.node.active = !1), (this.adCoolTimeLab.node.active = !0))
  122. : ((this.adBtn.node.active = t), (this.adCoolTimeLab.node.active = !1)));
  123. }
  124. onTouchUseBtn() {
  125. return s(this, void 0, void 0, function* () {
  126. o.default.ControllerManager.applyFunc(n.ControllerConst.Shop, l.ShopConst.USE, this.data),
  127. this.updateItem(),
  128. this.updateAdState();
  129. });
  130. }
  131. onTouchBuyBtn() {
  132. return s(this, void 0, void 0, function* () {
  133. this.item.cnt
  134. ? o.default.ControllerManager.applyFunc(n.ControllerConst.Shop, l.ShopConst.USE, this.data)
  135. : yield o.default.ControllerManager.applyFunc(n.ControllerConst.Shop, l.ShopConst.BUY, this.data, 7),
  136. this.updateItem(),
  137. this.updateAdState();
  138. });
  139. }
  140. onTouchTip() {
  141. o.default.ViewManager.open(30, this.item);
  142. }
  143. };
  144. e([c(cc.Label)], t.prototype, "title", void 0),
  145. e([c(cc.Label)], t.prototype, "descLab", void 0),
  146. e([c(cc.Node)], t.prototype, "costIcon", void 0),
  147. e([c(cc.Button)], t.prototype, "adBtn", void 0),
  148. e([c(cc.Label)], t.prototype, "adLab", void 0),
  149. e([c(cc.ProgressBar)], t.prototype, "progressBar", void 0),
  150. e([c(cc.Label)], t.prototype, "progessLab", void 0),
  151. e([c(cc.Label)], t.prototype, "adCoolTimeLab", void 0),
  152. (t = e([d, u("view/Shop/item/ShopBoxItem")], t)),
  153. (i.ShopBoxItem = t);