ShopBuffItem.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.ShopBuffItem = void 0);
  49. const o = t("App"),
  50. a = t("GameText"),
  51. n = t("AdShareBtnCtr"),
  52. r = t("ControllerConst"),
  53. l = t("NotificationConst"),
  54. h = (t("ViewConst"), t("BagConst")),
  55. c = t("BagController"),
  56. d = t("BuffMgr"),
  57. u = t("MyBigLong"),
  58. p = t("ShopConst"),
  59. f = t("ShopItem"),
  60. {property: g, ccclass: m, menu: _} = cc._decorator;
  61. t = class extends f.ShopItem {
  62. constructor() {
  63. super(...arguments),
  64. (this.title = null),
  65. (this.descLab = null),
  66. (this.buffTimeNode = null),
  67. (this.buffTimeLab = null),
  68. (this.adShareBtnCtr = null),
  69. (this.adBtn = null),
  70. (this.adNode = null),
  71. (this.coolNode = null),
  72. (this.coolTimeLab = null),
  73. (this.costBtn = null),
  74. (this.adCoolTime = 0),
  75. (this.buffEndTime = 0),
  76. (this.buffIndex = 0),
  77. (this.item = null);
  78. }
  79. initItem() {
  80. var t;
  81. (this.item = o.default.ControllerManager.applyFunc(
  82. r.ControllerConst.Item,
  83. h.BagConst.GET_ITEM,
  84. this.data.cfg.itemId
  85. )),
  86. o.default.CommonUtils.setSpriteFrame(this.item.getItemPic(), this.icon),
  87. (this.title.string = a.GameText.getTextByStr(this.item.data.name)),
  88. (this.buffIndex = this.item.data.buff ? this.item.data.buff.buffIndex : 0),
  89. this.data.cfg.ad && (this.adShareBtnCtr.adType = this.data.cfg.arg0),
  90. this.updateBtnState(),
  91. this.item.data.buff
  92. ? (this.descLab.string = a.GameText.getTextByStr(this.item.data.desc))
  93. : ((t = this.item.getCnt()),
  94. (this.node.active = !!t),
  95. (this.descLab.string = a.GameText.getText(63).format(u.default.toString(t))));
  96. }
  97. updateBtnState() {
  98. var t;
  99. this.data.cfg.ad
  100. ? ((this.adBtn.node.active = !0),
  101. (this.costBtn.active = !1),
  102. (t = o.default.DateUtils.secondNow()),
  103. (t = this.data.time + this.data.cfg.ad > t),
  104. (this.adBtn.interactable = !t),
  105. (this.adNode.active = !t),
  106. (this.coolNode.active = t) && (this.adCoolTime = 1e3 * (this.data.time + this.data.cfg.ad)))
  107. : ((this.adBtn.node.active = !1),
  108. (this.costBtn.active = !0),
  109. (this.costLab.string = this.data.cfg.diamond.toString()));
  110. }
  111. updateTime(t) {
  112. var e = o.default.DateUtils.Now();
  113. if (this.buffEndTime) {
  114. let t = (this.buffEndTime - e) / 1e3;
  115. t < 0
  116. ? ((t = 0),
  117. (this.buffEndTime = 0),
  118. (this.buffTimeLab.node.active = !1),
  119. (this.buffTimeNode.active = !1))
  120. : ((this.buffTimeLab.node.active = !0),
  121. (this.buffTimeNode.active = !0),
  122. (this.buffTimeLab.string = o.default.DateUtils.getFormatBySecond(t, 10)));
  123. }
  124. if (this.adCoolTime) {
  125. let t = (this.adCoolTime - e) / 1e3;
  126. t < 0
  127. ? ((t = 0), (this.adCoolTime = 0), this.updateBtnState())
  128. : (this.coolTimeLab.string = o.default.DateUtils.getFormatBySecond(t, 10));
  129. }
  130. }
  131. updateBuffState() {
  132. var t = d.default.ins.getGlobalBuffByIndex(this.buffIndex);
  133. t && t.buffEndTime && (this.buffEndTime = t.buffEndTime);
  134. }
  135. onTouchBuyBtn() {
  136. return s(this, void 0, void 0, function* () {
  137. var t, e;
  138. (yield o.default.ControllerManager.applyFunc(
  139. r.ControllerConst.Shop,
  140. p.ShopConst.BUY,
  141. this.data,
  142. this.adShareBtnCtr.adType
  143. )) &&
  144. (this.updateBuffState(),
  145. this.updateBtnState(),
  146. this.item.data.buff
  147. ? o.default.ViewManager.open(31, this.item)
  148. : ((t = this.item.getCnt()),
  149. (e = this.costBtn.convertToWorldSpaceAR(cc.Vec2.ZERO)),
  150. o.default.NotificationCenter.dispatch(
  151. l.NotificationConst.PLAY_MONEY_ANI,
  152. c.CostType.coin,
  153. t,
  154. e
  155. )));
  156. });
  157. }
  158. };
  159. e([g(cc.Label)], t.prototype, "title", void 0),
  160. e([g(cc.Label)], t.prototype, "descLab", void 0),
  161. e([g(cc.Node)], t.prototype, "buffTimeNode", void 0),
  162. e([g(cc.Label)], t.prototype, "buffTimeLab", void 0),
  163. e([g(n.default)], t.prototype, "adShareBtnCtr", void 0),
  164. e([g(cc.Button)], t.prototype, "adBtn", void 0),
  165. e([g(cc.Node)], t.prototype, "adNode", void 0),
  166. e([g(cc.Node)], t.prototype, "coolNode", void 0),
  167. e([g(cc.Label)], t.prototype, "coolTimeLab", void 0),
  168. e([g(cc.Node)], t.prototype, "costBtn", void 0),
  169. (t = e([m, _("view/Shop/item/ShopBuffItem")], t)),
  170. (i.ShopBuffItem = t);