CostumeController.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const h = t("App"),
  6. s = t("BaseController"),
  7. o = t("RedPointMgr"),
  8. a = t("Toast"),
  9. n = t("NotificationConst"),
  10. r = (t("ViewConst"), t("LayerManager"), t("PlatformBase"), t("GameConst")),
  11. c = t("GameUtils"),
  12. l = t("CurrencyService"),
  13. d = t("CostumeConst"),
  14. u = t("CostumeItem"),
  15. p = t("CostumeModel");
  16. let f = null;
  17. (o.RedPointMgr.types.MergeCostume = "MergeCostume"),
  18. (o.RedPointMgr.types.RecommendCostume = "RecommendCostume"),
  19. (i.default = class extends s.default {
  20. constructor() {
  21. super(),
  22. (this._model = null),
  23. (this._recalMap = []),
  24. (this._parseFuncMap = null),
  25. (this.costumeBagView = null),
  26. (this.costumeInfoView = null),
  27. (this.costumeStatisticsView = null),
  28. (f = this).initNotificationEvent(),
  29. this.setModel(new p.CostumeModel(this)),
  30. h.default.ViewManager.register(25, {
  31. prefabName: "CostumeBagView",
  32. zIndex: 100,
  33. controller: this,
  34. dir: "costume"
  35. }),
  36. h.default.ViewManager.register(26, {
  37. prefabName: "CostumeInfoView",
  38. zIndex: 100,
  39. controller: this,
  40. dir: "costume"
  41. }),
  42. h.default.ViewManager.register(27, {
  43. prefabName: "CostumeMergeView",
  44. zIndex: 100,
  45. controller: this,
  46. dir: "costume"
  47. }),
  48. h.default.ViewManager.register(33, {
  49. prefabName: "CostumeRefundView",
  50. zIndex: 100,
  51. controller: this,
  52. dir: "costume"
  53. }),
  54. h.default.ViewManager.register(34, {
  55. prefabName: "CotumeUpgradView",
  56. zIndex: 100,
  57. controller: this,
  58. dir: "costume"
  59. }),
  60. h.default.ViewManager.register(35, {
  61. prefabName: "CostumeMergeTipView",
  62. zIndex: 100,
  63. controller: this,
  64. dir: "costume"
  65. }),
  66. h.default.ViewManager.register(46, {
  67. prefabName: "CostumeStatisticsView",
  68. zIndex: 100,
  69. controller: this,
  70. dir: "costume"
  71. }),
  72. h.default.ViewManager.register(47, {
  73. prefabName: "CostumeMergeAniView",
  74. zIndex: 100,
  75. controller: this,
  76. dir: "costume"
  77. }),
  78. h.default.ViewManager.register(49, {
  79. prefabName: "CostumeCoinReturnView",
  80. zIndex: 100,
  81. controller: this,
  82. dir: "costume"
  83. });
  84. }
  85. static get ins() {
  86. return f;
  87. }
  88. initModuleEvent() {}
  89. initNotificationEvent() {
  90. h.default.NotificationCenter.addListener(n.NotificationConst.INIT_GAME_FINISH, this.initGame, this);
  91. }
  92. log(...t) {
  93. cc.log("Costume", ...t);
  94. }
  95. initGame() {
  96. this.initModuleEvent(),
  97. h.default.NotificationCenter.removeListener(n.NotificationConst.INIT_GAME_FINISH, this.initGame, this);
  98. const e = this._model;
  99. e.init();
  100. var i = e.saveData.items;
  101. let s = i.length;
  102. for (let t = 0; t < s; t++) {
  103. const s = i[t],
  104. o = new u.default(),
  105. a = e.costumeCfg[s.id];
  106. o.init(s, a, e.costumeUpgrade, e.costumeMergeCfg), e.addCostumeItem(o);
  107. }
  108. for (const h in e.saveData.equipItem) this.equipCostume(e.saveData.equipItem[h]);
  109. this.calEquipCostumeAttr(), this.checkRedpoint();
  110. }
  111. test() {
  112. const t = this._model,
  113. e = t.equipItems;
  114. if (!e[d.CostumeParts.head]) {
  115. const e = t.getCostumeItemByParts(d.CostumeParts.head);
  116. e.length && this.equipCostume(e[0].data.uuid);
  117. }
  118. if (!e[d.CostumeParts.hand]) {
  119. const e = t.getCostumeItemByParts(d.CostumeParts.hand);
  120. e.length && this.equipCostume(e[0].data.uuid);
  121. }
  122. if (!e[d.CostumeParts.body]) {
  123. const e = t.getCostumeItemByParts(d.CostumeParts.body);
  124. e.length && this.equipCostume(e[0].data.uuid);
  125. }
  126. this.log("/-----当前装备:");
  127. for (const i in this._model.equipItems) this.log(this._model.equipItems[i].toString());
  128. this.log("当前装备-------/:");
  129. }
  130. createNewCostume(t, e = 1, i = 1, s = !0) {
  131. const o = new u.default(),
  132. a = this._model,
  133. n = {id: t, lv: i, grade: e, uuid: a.saveData.uuid++};
  134. return (
  135. o.init(n, a.costumeCfg[t], a.costumeUpgrade, a.costumeMergeCfg),
  136. a.addCostumeItem(o),
  137. a.saveData.items.push(n),
  138. s && this.checkRedpoint(),
  139. o
  140. );
  141. }
  142. getTempCostume(t, e = 1, i = 1) {
  143. const s = new u.default(),
  144. o = this._model,
  145. a = {id: t, lv: i, grade: e, uuid: null};
  146. return s.init(a, o.costumeCfg[t], o.costumeUpgrade, o.costumeMergeCfg), s;
  147. }
  148. lvUp(t) {
  149. const e = this._model.getCostumeItemByUuid(t);
  150. if (e) {
  151. const t = e.cost;
  152. if (l.default.ins.checkDiamondEnough(t))
  153. return (
  154. e.lvUp(),
  155. l.default.ins.diamondChange(-t),
  156. e.isEquip && (this.record(d.CostumeAbilityType.base), this.calEquipCostumeAttr()),
  157. e.recommend || this.checkRecommand(),
  158. h.default.NotificationCenter.dispatch(r.GameNotificationConst.LV_UP_COSTUME, e),
  159. h.default.AnalyticMgr.recordDiamondCost(2, -t),
  160. !0
  161. );
  162. a.default.launch("钻石不足");
  163. } else Log.error("装备不存在:", t);
  164. return !1;
  165. }
  166. upgradeGrade(t) {
  167. const e = this._model.getCostumeItemByUuid(t);
  168. if (e) {
  169. const t = e.gradeCfg.upgrade_cost;
  170. if (l.default.ins.checkDiamondEnough(t))
  171. return (
  172. e.gradeUp(),
  173. this.refundCostume(e),
  174. l.default.ins.diamondChange(-t),
  175. e.isEquip && (this.record(d.CostumeAbilityType.base), this.calEquipCostumeAttr()),
  176. e.recommend || this.checkRecommand(),
  177. this.checkRedpoint(!1),
  178. h.default.NotificationCenter.dispatch(r.GameNotificationConst.LV_UP_COSTUME, e),
  179. h.default.AnalyticMgr.recordDiamondCost(3, -t),
  180. !0
  181. );
  182. a.default.launch("钻石不足");
  183. } else Log.error("装备不存在:", t);
  184. }
  185. equipCostume(t, e) {
  186. const i = this._model.getCostumeItemByUuid(t);
  187. if (i) {
  188. const t = this._model.equipItems[i.cfg.parts];
  189. if (
  190. ((i.isEquip = !0),
  191. (this._model.equipItems[i.cfg.parts] = i),
  192. (this._model.saveData.equipItem[i.cfg.parts] = i.data.uuid),
  193. t)
  194. ) {
  195. t.isEquip = !1;
  196. for (const e in t.attr) this.record(parseInt(e));
  197. }
  198. for (const e in i.attr) this.record(parseInt(e));
  199. e && (this.calEquipCostumeAttr(), this.checkRecommand()),
  200. h.default.NotificationCenter.dispatch(r.GameNotificationConst.EQUIP_COSTUME, i, t);
  201. } else Log.error("装备不存在:", t);
  202. }
  203. unequipCostume(t, e, i) {
  204. const s = this._model.equipItems[t];
  205. if (s) {
  206. for (const t in s.attr) this.record(parseInt(t));
  207. return (
  208. delete this._model.equipItems[t],
  209. delete this._model.saveData.equipItem[t],
  210. (s.isEquip = !1),
  211. i && (this.calEquipCostumeAttr(), this.checkRecommand()),
  212. e && h.default.NotificationCenter.dispatch(r.GameNotificationConst.UNEQUIP_COSTUME, s),
  213. s
  214. );
  215. }
  216. Log.error("这个位置没有装备物品:", t, d.CostumeParts[t]);
  217. }
  218. record(t) {
  219. this._recalMap.includes(t) || this._recalMap.push(t);
  220. }
  221. refundCostume(t) {
  222. if (1 < t.data.lv) {
  223. var e = t.getLvCost(t.data.lv);
  224. return (
  225. t.refund(),
  226. l.default.ins.diamondChange(e),
  227. t.isEquip && (this.record(d.CostumeAbilityType.base), this.calEquipCostumeAttr()),
  228. t.recommend && this.checkRecommand(),
  229. h.default.NotificationCenter.dispatch(r.GameNotificationConst.REFUND_COSTUME, t),
  230. !0
  231. );
  232. }
  233. }
  234. checkItemIsRecommand(t) {
  235. var e = this._model.items;
  236. t.cfg.parts;
  237. for (const i of e) i.cfg.parts;
  238. }
  239. checkIsCanMerge(e, i) {
  240. var t = this._model.costumeMergeCfg[e.data.grade],
  241. s = i.length;
  242. if (s !== t.costume_count) return !1;
  243. for (let t = 0; t < s; t++) if (!e.checkIsCanMerge(i[t])) return !1;
  244. return !0;
  245. }
  246. mergeCostume(e, i) {
  247. if (!this.checkIsCanMerge(e, i)) return null;
  248. let s = e.getLvCost(e.data.lv),
  249. o = e.isEquip,
  250. a = i.length;
  251. for (let t = 0; t < a; t++) {
  252. const e = i[t];
  253. (o = o || e.isEquip), (s += e.getLvCost(e.data.lv)), this.destoryCostumeItem(e);
  254. }
  255. return (
  256. e.gradeUp(),
  257. o && this.calEquipCostumeAttr(),
  258. 0 < s && l.default.ins.diamondChange(s),
  259. this.checkRedpoint(),
  260. h.default.NotificationCenter.dispatch(r.GameNotificationConst.MERGE_COSTUME, e, i),
  261. {refundDiamond: s}
  262. );
  263. }
  264. destoryCostumeItem(t) {
  265. t.isEquip && this.unequipCostume(t.cfg.parts), this._model.removeCostumeItem(t);
  266. }
  267. calEquipCostumeAttr() {
  268. const e = this._model.attr;
  269. for (let t = d.CostumeParts.head; t <= d.CostumeParts.hand; t++) {
  270. const i = this._model.equipItems[t],
  271. h = e.getAttrBute("costume" + t);
  272. i ? (h.addAttrDict("base", i.attr), h.claFinishAttr()) : h.reset();
  273. }
  274. e.claFinishAttr(),
  275. h.default.NotificationCenter.dispatch(
  276. r.GameNotificationConst.UPDATE_EQUIP_COSTUME_ATTR,
  277. this._recalMap
  278. ),
  279. (this._recalMap.length = 0);
  280. }
  281. onLoadView(t) {}
  282. onOpenView(t) {
  283. 46 == t.viewId && this.updateCostumeStatisticInfo();
  284. }
  285. checkRecommand() {
  286. const s = this._model,
  287. o = s.equipItems,
  288. a = s.items;
  289. a.sort(c.sortCostume);
  290. const n = s.recommendItems;
  291. for (const h in n) n[h] && ((n[h].recommend = !1), (n[h] = null));
  292. let r = a.length;
  293. if (0 !== r) {
  294. let e = 0,
  295. i = !1;
  296. for (let t = 0; t < r; t++) {
  297. const s = a[t],
  298. r = s.cfg.parts;
  299. if (!n[r]) {
  300. var l = o[r];
  301. if (
  302. ((!l ||
  303. s.data.grade > l.data.grade ||
  304. (s.data.grade === l.data.grade && s.data.lv > l.data.lv)) &&
  305. ((s.recommend = !0), l !== s && (i = !0), (n[r] = s), e++),
  306. 3 === e)
  307. )
  308. break;
  309. }
  310. }
  311. h.default.RedPointMgr.next(h.default.RedPointMgr.types.RecommendCostume, i);
  312. }
  313. }
  314. checkRedpoint(i = !0) {
  315. var s = this._model.items;
  316. let o = s.length;
  317. const a = {};
  318. let n = !1;
  319. for (let e = 0; e < o; e++) {
  320. const i = s[e],
  321. o = i.cfg.parts,
  322. r = i.getMergeCfg();
  323. let t = 1e4 * o + 1e3 * i.data.grade;
  324. 1 === r.ingredient_costume_type && (t += i.cfg.idx),
  325. a[t]
  326. ? (a[t].list.push(i), a[t].list.length > r.costume_count && (n = !0))
  327. : (a[t] = {list: [i], cfg: r});
  328. }
  329. h.default.RedPointMgr.next(h.default.RedPointMgr.types.MergeCostume, n), i && this.checkRecommand();
  330. }
  331. updateMergeInfo() {
  332. const i = this._model.items;
  333. let s = i.length;
  334. const o = {};
  335. for (let e = 0; e < s; e++) {
  336. const s = i[e],
  337. a = s.cfg.parts,
  338. n = s.getMergeCfg();
  339. let t = 1e4 * a + 1e3 * s.data.grade;
  340. 1 === n.ingredient_costume_type && (t += s.cfg.idx),
  341. o[t] ? o[t].list.push(s) : (o[t] = {list: [s], cfg: n});
  342. }
  343. for (const t in o) {
  344. const i = o[t],
  345. s = i.list.length > i.cfg.costume_count;
  346. for (const o of i.list) o.canMerge = s;
  347. }
  348. }
  349. checkIsCanUpgrade(t) {
  350. t.getMergeCfg().ingredient_costume_type;
  351. }
  352. onCloseView(t) {
  353. (33 != t.viewId && 34 != t.viewId) ||
  354. (this.costumeInfoView && this.costumeInfoView.isShow() && this.costumeInfoView.updateData());
  355. }
  356. updateCostumeStatisticInfo() {
  357. let i = {},
  358. s = [];
  359. for (let t = d.CostumeParts.head; t <= d.CostumeParts.hand; t++) {
  360. const n = this._model.equipItems[t];
  361. if (n) {
  362. let e = d.getGradeIndexByGrade(n.data.grade);
  363. if ((3 == e && (e--, s.push(n.getSpecialAbilityStr4())), 0 < e))
  364. for (let t = 0; t <= e; t++) {
  365. var o = n.cfg[`special_ability${t + 1}_type`],
  366. a = n.cfg[`special_ability${t + 1}_value`];
  367. i[o] || (i[o] = {value: 0, gradeIndex: t}), (i[o].value += a);
  368. }
  369. }
  370. }
  371. var t;
  372. this.costumeStatisticsView &&
  373. ((t = this._model.attr.getAttrValue(d.CostumeAbilityType.base, 0)),
  374. this.costumeStatisticsView.updateUI(i, s, t));
  375. }
  376. });