AbilityInfoData.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const s = t("Toast"),
  6. o = t("CurrencyService");
  7. i.default = class {
  8. constructor() {
  9. (this.cfg = null),
  10. (this.curLevel = null),
  11. (this.data = null),
  12. (this.value = 0),
  13. (this.nextLvValue = 0),
  14. (this.cost = 0),
  15. (this.installCost = 0);
  16. }
  17. getValue(t) {
  18. return this.value ? this.value / 100 : t;
  19. }
  20. init(e, t) {
  21. if (((this.cfg = e), (this.data = t), (this.installCost = e.unlock_cost), t.lv)) {
  22. this.value = this.cfg.value;
  23. const e = t.lv;
  24. (this.cost = t.lv = 0), this.unlock();
  25. for (let t = 1; t < e; t++) this.$levelUp();
  26. }
  27. }
  28. isMaxLevel() {
  29. return this.data.lv >= this.cfg.max_level;
  30. }
  31. $levelUp() {
  32. this.data.lv++,
  33. (this.value += this.cfg.value_add),
  34. (this.cost += this.cfg.upgrade_cost_add),
  35. (this.nextLvValue = this.value + this.cfg.value_add),
  36. (this.curLevel = this.data.lv);
  37. }
  38. canUnlock() {
  39. return o.default.ins.checkDiamondEnough(this.cfg.unlock_cost);
  40. }
  41. unlock() {
  42. (this.value = this.cfg.value),
  43. (this.data.lv = 1),
  44. (this.cost = this.cfg.upgrade_cost),
  45. (this.nextLvValue = this.value + this.cfg.value_add),
  46. (this.curLevel = this.data.lv);
  47. }
  48. canLvUp() {
  49. return o.default.ins.checkDiamondEnough(this.cost);
  50. }
  51. levelUp() {
  52. var t;
  53. this.isMaxLevel()
  54. ? s.default.launch("已经是最大等级!")
  55. : ((t = -this.cost),
  56. o.default.ins.checkDiamondEnough(t)
  57. ? (this.$levelUp(), o.default.ins.diamondChange(t))
  58. : s.default.launch("金币不足!"));
  59. }
  60. isUnlock() {
  61. return 0 < this.data.lv;
  62. }
  63. getAvilityIconUrl() {
  64. return `Texture/ability/ability_icon_${this.cfg.idx}`;
  65. }
  66. getAvilityLockIconUrl() {
  67. return `Texture/ability/ability_icon_lock_${this.cfg.idx}`;
  68. }
  69. };