BagController.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0}), (i.CostType = void 0);
  5. const n = t("App"),
  6. s = t("BaseController"),
  7. o = t("NotificationConst"),
  8. r = t("GameConst"),
  9. a = t("CurrencyService"),
  10. l = t("BagConst"),
  11. h = t("BagModel");
  12. let c = null;
  13. var d;
  14. (i.default = class extends s.default {
  15. constructor() {
  16. super(), (this._model = null), (c = this).initNotificationEvent(), this.setModel(new h.BagModel(this));
  17. }
  18. static get ins() {
  19. return c;
  20. }
  21. initModuleEvent() {
  22. this.registerFunc(l.BagConst.USE_ITEM, this.useItem, this),
  23. this.registerFunc(l.BagConst.ADD_TIME, this.addItem, this),
  24. this.registerFunc(l.BagConst.USE_ITEM_ANI, this.useItemAni, this),
  25. this.registerFunc(l.BagConst.GET_ITEM, this.getItem, this),
  26. this.registerFunc(l.BagConst.GET_ITEMS_BY_TYPE, this.getItemType, this);
  27. }
  28. initNotificationEvent() {
  29. n.default.NotificationCenter.addListener(o.NotificationConst.INIT_GAME_FINISH, this.initGame, this);
  30. }
  31. initGame() {
  32. this.initModuleEvent(),
  33. n.default.NotificationCenter.removeListener(o.NotificationConst.INIT_GAME_FINISH, this.initGame, this),
  34. this._model.init();
  35. }
  36. useItemAni(t, e, i = 0) {}
  37. onLoadView(t) {}
  38. onOpenView(t) {}
  39. useItem(t, e = 1, i, s) {
  40. let o = this._model.itmes[t];
  41. if (o) {
  42. if (o.cnt >= e) {
  43. o.cnt -= e;
  44. var a = o.use(e);
  45. return n.default.NotificationCenter.dispatch(r.GameNotificationConst.USE_ITEM, t, e, a), a;
  46. }
  47. return (
  48. Log.warn(
  49. `\u7269\u54c1\u6570\u91cf\u4e0d\u8db3, \u7269\u54c1id:${t}, \u7269\u54c1\u540d\u79f0:${o.getName()}`
  50. ),
  51. {result: -1}
  52. );
  53. }
  54. return Log.error(`\u4e0d\u5b58\u5728\u7684\u7269\u54c1id:${t}`), {result: -2};
  55. }
  56. addItem(e, i = 1, t) {
  57. if (e <= 1e4) {
  58. let t = this._model.itmes[e];
  59. return t
  60. ? ((t.cnt += i),
  61. t.data.isNowUseItem
  62. ? this.useItem(e, i, !0, !0)
  63. : n.default.NotificationCenter.dispatch(r.GameNotificationConst.ADD_ITEM, e),
  64. !0)
  65. : (Log.error(`\u4e0d\u5b58\u5728\u7684\u7269\u54c1id:${e}`), !1);
  66. }
  67. this.addMoney(e, i);
  68. }
  69. addMoney(t, e) {
  70. switch (t) {
  71. case d.coin:
  72. a.default.ins.moneyChange(e);
  73. break;
  74. case d.diamond:
  75. a.default.ins.diamondChange(e);
  76. }
  77. }
  78. getItem(t) {
  79. return this._model.itmes[t];
  80. }
  81. getItemType(t) {
  82. return this._model.itmeTypes[t];
  83. }
  84. }),
  85. ((i = d = i.CostType || (i.CostType = {}))[(i.coin = 20001)] = "coin"),
  86. (i[(i.diamond = 20002)] = "diamond");