CostumeItem.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const o = t("GameText"),
  6. a = t("GameUtils"),
  7. n = t("CurrencyService"),
  8. r = t("CostumeConst"),
  9. l = [
  10. "costume/Dynamic_Icon_CostumeType_Head",
  11. "costume/Dynamic_Icon_CostumeType_Body",
  12. "costume/Dynamic_Icon_CostumeType_Hand"
  13. ];
  14. i.default = class s {
  15. constructor() {
  16. (this.cfg = null),
  17. (this.data = null),
  18. (this.costumeUpgrade = null),
  19. (this.costumeMergeCfg = null),
  20. (this.gradeCfg = null),
  21. (this.cost = 0),
  22. (this.canMerge = !1),
  23. (this.recommend = !1),
  24. (this.isEquip = !1),
  25. (this.attr = null);
  26. }
  27. init(t, e, i, s) {
  28. (this.cfg = e),
  29. (e = i[(this.data = t).grade]),
  30. (this.costumeMergeCfg = s),
  31. (this.costumeUpgrade = i),
  32. (this.gradeCfg = e),
  33. (this.attr = {[r.CostumeAbilityType.base]: e.value + (t.lv - 1) * e.value_add}),
  34. (this.cost = e.upgrade_cost + (t.lv - 1) * e.upgrade_cost_add),
  35. this.initSpecialAbilitys();
  36. }
  37. getNextGradeItem() {
  38. const t = new s(),
  39. e = Object.assign(Object.create(null), this.data);
  40. return (e.lv = 1), e.grade++, t.init(e, this.cfg, this.costumeUpgrade, this.costumeMergeCfg), t;
  41. }
  42. getLastGradeItem() {
  43. const t = new s(),
  44. e = Object.assign(Object.create(null), this.data);
  45. return (e.lv = 1) < e.grade && e.grade--, t.init(e, this.cfg, this.costumeUpgrade, this.costumeMergeCfg), t;
  46. }
  47. getGradeItemByGrade(t) {
  48. const e = new s(),
  49. i = Object.assign(Object.create(null), this.data);
  50. return (i.lv = 1), (i.grade = t), e.init(i, this.cfg, this.costumeUpgrade, this.costumeMergeCfg), e;
  51. }
  52. getName() {
  53. return o.GameText.getTextByStr(this.cfg.name);
  54. }
  55. getValue() {
  56. return this.attr[r.CostumeAbilityType.base];
  57. }
  58. getNextLvValue() {
  59. return this.attr[r.CostumeAbilityType.base] + this.gradeCfg.value_add;
  60. }
  61. getMaxLvValue() {
  62. return this.gradeCfg.value + (this.gradeCfg.max_level - 1) * this.gradeCfg.value_add;
  63. }
  64. getLvUpAddRate() {
  65. var t = this.attr[r.CostumeAbilityType.base];
  66. return Math.round((this.gradeCfg.value_add / (t + this.gradeCfg.value_add)) * 100);
  67. }
  68. getTypeIcon() {
  69. return l[this.cfg.parts - 1];
  70. }
  71. getIcon() {
  72. return "costume/" + this.cfg.icon_basic;
  73. }
  74. toString() {
  75. var t = this.data,
  76. e = t.grade;
  77. let i = `${this.cfg.name} uuid:${t.uuid}, id:${this.cfg.idx}, lv:${t.lv}, grade:${e}(${o.GameText.getTextByStr(
  78. "str_grade" + e
  79. )}), cost:${this.cost}`;
  80. return (
  81. (i += `\n\u57fa\u7840\u5c5e\u6027\u52a0\u6210:${this.attr[r.CostumeAbilityType.base]}%`),
  82. e < r.RarityType.uncommon
  83. ? i
  84. : ((i += "\n已解锁特殊属性:"),
  85. (i += "\n 1." + this.getSpecialAbilityStr1()),
  86. e < r.RarityType.epic
  87. ? i
  88. : ((i += "\n 2." + this.getSpecialAbilityStr2()),
  89. e < r.RarityType.legendary
  90. ? i
  91. : ((i += "\n 3." + this.getSpecialAbilityStr3()),
  92. e < r.RarityType.mystic ? i : i + ("\n 4." + this.getSpecialAbilityStr4()))))
  93. );
  94. }
  95. isMaxGrade() {
  96. return this.data.grade >= r.RarityType.mystic;
  97. }
  98. getMergeCfg() {
  99. return this.costumeMergeCfg[this.data.grade];
  100. }
  101. checkIsCanMerge(t) {
  102. var e = this.costumeMergeCfg[this.data.grade];
  103. if (1 === e.ingredient_costume_type) {
  104. if (t.data.id !== this.data.id || t.data.grade !== e.costume_type_grade) return !1;
  105. } else if (t.cfg.parts !== this.cfg.parts || t.data.grade !== e.costume_type_grade) return !1;
  106. return !0;
  107. }
  108. initSpecialAbilitys() {
  109. return this.data.grade < r.RarityType.uncommon
  110. ? this.attr
  111. : ((this.attr[this.cfg.special_ability1_type] = this.cfg.special_ability1_value),
  112. this.data.grade < r.RarityType.epic
  113. ? this.attr
  114. : ((this.attr[this.cfg.special_ability2_type] = this.cfg.special_ability2_value),
  115. this.data.grade < r.RarityType.legendary
  116. ? this.attr
  117. : ((this.attr[this.cfg.special_ability3_type] = this.cfg.special_ability3_value),
  118. this.data.grade < r.RarityType.mystic
  119. ? this.attr
  120. : void (this.attr[this.cfg.special_ability4_type] = this.cfg.special_ability4_value))));
  121. }
  122. getSpecialAbilityStr1() {
  123. return a.getCostumeAttrStr(this.cfg.special_ability1_type, this.cfg.special_ability1_value);
  124. }
  125. getSpecialAbilityStr2() {
  126. return a.getCostumeAttrStr(this.cfg.special_ability2_type, this.cfg.special_ability2_value);
  127. }
  128. getSpecialAbilityStr3() {
  129. return a.getCostumeAttrStr(this.cfg.special_ability3_type, this.cfg.special_ability3_value);
  130. }
  131. getSpecialAbilityStr4() {
  132. return a.getCostumeAttrStr(
  133. this.cfg.special_ability4_type,
  134. this.cfg.special_ability4_value,
  135. this.getName(),
  136. 2 * this.getValue()
  137. );
  138. }
  139. getCurMaxSpecialAbilityStr(t) {
  140. let e = null;
  141. return (
  142. (t = t || this.data.grade) >= r.RarityType.rare && (e = this.getSpecialAbilityStr1()),
  143. t >= r.RarityType.epic && (e = this.getSpecialAbilityStr2()),
  144. t >= r.RarityType.legendary && (e = this.getSpecialAbilityStr3()),
  145. t >= r.RarityType.mystic && (e = this.getSpecialAbilityStr4()),
  146. e
  147. );
  148. }
  149. getBaseValueStr() {
  150. return `+${this.attr[r.CostumeAbilityType.base]}%`;
  151. }
  152. isMaxLv() {
  153. return this.data.lv >= this.gradeCfg.max_level;
  154. }
  155. getLvCost(t) {
  156. if (1 === t) return 0;
  157. var e = this.gradeCfg;
  158. return t > e.max_level && (t = e.max_level), --t * (e.upgrade_cost + (e.upgrade_cost_add * (t - 1)) / 2);
  159. }
  160. canLvUp() {
  161. return !this.isMaxLv() && n.default.ins.checkDiamondEnough(this.cost);
  162. }
  163. refund() {
  164. (this.data.lv = 1),
  165. (this.attr[r.CostumeAbilityType.base] = this.gradeCfg.value),
  166. (this.cost = this.gradeCfg.upgrade_cost);
  167. }
  168. lvUp() {
  169. return (
  170. !this.isMaxLv() &&
  171. (this.data.lv++,
  172. (this.attr[r.CostumeAbilityType.base] += this.gradeCfg.value_add),
  173. (this.cost += this.gradeCfg.upgrade_cost_add),
  174. !0)
  175. );
  176. }
  177. canUpgradeGrade() {
  178. return 0 < this.gradeCfg.upgrade_grade_cost;
  179. }
  180. gradeUp() {
  181. if (this.isMaxGrade()) return !1;
  182. this.data.grade++, (this.gradeCfg = this.costumeUpgrade[this.data.grade]);
  183. var t = this.gradeCfg;
  184. if (
  185. ((this.data.lv = 1),
  186. (this.attr[r.CostumeAbilityType.base] = t.value),
  187. (this.cost = t.upgrade_cost),
  188. this.attr)
  189. )
  190. switch (this.data.grade) {
  191. case r.RarityType.uncommon:
  192. this.attr[this.cfg.special_ability1_type] = this.cfg.special_ability1_value;
  193. break;
  194. case r.RarityType.epic:
  195. this.attr[this.cfg.special_ability2_type] = this.cfg.special_ability2_value;
  196. break;
  197. case r.RarityType.legendary:
  198. this.attr[this.cfg.special_ability3_type] = this.cfg.special_ability3_value;
  199. break;
  200. case r.RarityType.mystic:
  201. this.attr[this.cfg.special_ability4_type] = this.cfg.special_ability4_value;
  202. }
  203. return !0;
  204. }
  205. equip() {
  206. this.isEquip = !0;
  207. }
  208. unEquip() {
  209. this.isEquip = !1;
  210. }
  211. };