HelperCatService.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. o,
  6. a =
  7. (this && this.__decorate) ||
  8. function (t, e, i, s) {
  9. var o,
  10. a = arguments.length,
  11. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  12. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  13. else
  14. for (var r = t.length - 1; 0 <= r; r--)
  15. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  16. return 3 < a && n && Object.defineProperty(e, i, n), n;
  17. };
  18. Object.defineProperty(i, "__esModule", {value: !0}), (i.HelperCatState = void 0);
  19. const h = t("App"),
  20. n = t("ControllerConst"),
  21. c = t("CostumeConst"),
  22. d = t("CostumeController"),
  23. r = t("HelperCatData"),
  24. l = t("GameConst"),
  25. u = t("GlobalAttr"),
  26. p = t("CatTimeOut"),
  27. f = t("BaseService"),
  28. g = t("RoleService");
  29. ((e = o = i.HelperCatState || (i.HelperCatState = {}))[(e.NONE = 0)] = "NONE"),
  30. (e[(e.READY = 1)] = "READY"),
  31. (e[(e.WORKING = 2)] = "WORKING"),
  32. (e[(e.CD = 3)] = "CD");
  33. var {ccclass: t} = cc._decorator,
  34. e = (s = class extends f.default {
  35. constructor() {
  36. super(...arguments),
  37. (this.helperCatDatas = []),
  38. (this.curHelprCatData = null),
  39. (this.cfgs = []),
  40. (this.define = null),
  41. (this.saveData = null),
  42. (this._curCat = null);
  43. }
  44. onLoad() {
  45. s.ins = this;
  46. }
  47. getCfgsByTier(t) {
  48. const e = [];
  49. for (const i of this.cfgs) i.tier === t && e.push(i);
  50. return e;
  51. }
  52. isCatTimeOut() {
  53. return h.default.DateUtils.Now() - this.saveData.hireTime > 1e3 * this.define.invite_appear_timer;
  54. }
  55. getCatLeftTime() {
  56. return 1e3 * this.define.invite_appear_timer - h.default.DateUtils.Now() + this.saveData.hireTime;
  57. }
  58. getCatLeftCDTime() {
  59. return 1e3 * this.define.invite_appear_cooltime - h.default.DateUtils.Now() + this.saveData.hireTime;
  60. }
  61. refresh() {
  62. this._curCat && this._curCat.getComponent(p.default).removeImmediately(),
  63. (this.saveData.hireTime = 0),
  64. (this._curCat = null);
  65. }
  66. getState() {
  67. var t = (h.default.DateUtils.Now() - this.saveData.hireTime) / 1e3;
  68. return !this.curHelprCatData || t > this.define.invite_appear_timer
  69. ? t > this.define.invite_appear_cooltime
  70. ? o.READY
  71. : o.CD
  72. : o.WORKING;
  73. }
  74. init() {
  75. const t = h.default.ControllerManager.getControllerModel(n.ControllerConst.Game);
  76. if (
  77. ((this.define = h.default.ConfigManager.getConfig("Define")),
  78. (this.cfgs = h.default.ConfigManager.getConfig("Helper")),
  79. t.data.helper || (t.data.helper = {hireTime: 0}),
  80. (this.saveData = t.data.helper),
  81. this.saveData.cur)
  82. )
  83. if (this.isCatTimeOut()) delete this.saveData.cur;
  84. else {
  85. const t = new r.default();
  86. t.init(this.saveData.cur, this.getCfgById(this.saveData.cur.id)),
  87. t.initAttr(),
  88. this.setCurHelperCatData(t),
  89. this.createHelpCat();
  90. }
  91. }
  92. removeCurCat() {
  93. (this.curHelprCatData = null), delete this.saveData.cur, (this._curCat = null);
  94. }
  95. onCatRemove() {
  96. if (this.curHelprCatData) {
  97. const t = d.default.ins.getModel().attr;
  98. t.removeAttrDict("HELP_CAT"),
  99. t.claFinishAttr(),
  100. h.default.NotificationCenter.dispatch(
  101. l.GameNotificationConst.UPDATE_EQUIP_COSTUME_ATTR,
  102. this.curHelprCatData.recalMap
  103. ),
  104. this.removeCurCat();
  105. }
  106. }
  107. createHelpCat() {
  108. const t = this.curHelprCatData.attr,
  109. e = (this._curCat = g.default.ins.createManCat(t, "")),
  110. i = e.addComponent(p.default),
  111. s = 1e3 * this.define.invite_appear_timer;
  112. i.setLeftTime(this.saveData.hireTime + s, s),
  113. i.setCallBack(this.onCatRemove, this),
  114. e.updateSlot(this.curHelprCatData.equipItems),
  115. (e.getCookMoneyRate = () =>
  116. u.default.ins.cookMoneyRate + t.getAttrValue(c.CostumeAbilityType.base, 0) / 100);
  117. }
  118. setCurHelperCatData(t) {
  119. this.curHelprCatData = t;
  120. const e = d.default.ins.getModel().attr;
  121. e.addAttrDict("HELP_CAT", t.getGlobalAttr()),
  122. e.claFinishAttr(),
  123. h.default.NotificationCenter.dispatch(l.GameNotificationConst.UPDATE_EQUIP_COSTUME_ATTR, t.recalMap);
  124. }
  125. hireCat(t) {
  126. return (
  127. this.setCurHelperCatData(this.helperCatDatas[t]),
  128. (this.helperCatDatas.length = 0),
  129. (this.saveData.cur = this.saveData.items[t]),
  130. delete this.saveData.items,
  131. (this.saveData.hireTime = h.default.DateUtils.Now()),
  132. this.createHelpCat(),
  133. this.curHelprCatData
  134. );
  135. }
  136. getCfgById(e) {
  137. var i = this.cfgs.length;
  138. for (let t = 0; t < i; t++) if (this.cfgs[t].idx === e) return this.cfgs[t];
  139. }
  140. getHelpCatDatas() {
  141. if (this.helperCatDatas.length) return this.helperCatDatas;
  142. var e = this.getCostumeCacheData();
  143. let i = e.length;
  144. for (let t = 0; t < i; t++) {
  145. const i = e[t],
  146. s = new r.default();
  147. s.init(i, this.getCfgById(i.id)), s.initAttr(), (this.helperCatDatas[t] = s);
  148. }
  149. return this.helperCatDatas;
  150. }
  151. getCostumeCacheData() {
  152. if (this.saveData.items) return this.saveData.items;
  153. const e = this.randomData(),
  154. i = (this.saveData.items = []),
  155. s = d.default.ins.getModel().equipItems;
  156. let o = e.length;
  157. for (let t = 0; t < o; t++) {
  158. const o = e[t],
  159. a = {};
  160. for (let t = c.CostumeParts.head; t <= c.CostumeParts.hand; t++) {
  161. const i = s[t],
  162. n = i ? i.data.grade : c.RarityType.common,
  163. d = i ? i.data.lv : 0,
  164. r = h.default.RandomUtils.limitInteger(
  165. Math.max(n + o.costume_grade_min, c.RarityType.common),
  166. Math.max(n + o.costume_grade_max, c.RarityType.common)
  167. ),
  168. l = h.default.RandomUtils.limitInteger(
  169. Math.max(o.costume_lv_min + d, 1),
  170. Math.max(o.costume_lv_max + d, 1)
  171. );
  172. a[t] = {lv: l, grade: r};
  173. }
  174. i.push({id: o.idx, costume: a});
  175. }
  176. return this.saveData.items;
  177. }
  178. randomData() {
  179. var t = h.default.ConfigManager.getConfig("Define"),
  180. e = h.default.RandomUtils.limitInteger(t.tier1_min_count, t.tier1_max_count),
  181. i = h.default.RandomUtils.limitInteger(t.tier2_min_count, t.tier2_max_count),
  182. t = h.default.RandomUtils.limitInteger(t.tier3_min_count, t.tier3_max_count);
  183. return [
  184. ...h.default.RandomUtils.shuffle(this.getCfgsByTier(3)).splice(0, t),
  185. ...h.default.RandomUtils.shuffle(this.getCfgsByTier(2)).splice(0, i),
  186. ...h.default.RandomUtils.shuffle(this.getCfgsByTier(1)).splice(0, e)
  187. ];
  188. }
  189. desotrySelf() {
  190. this._curCat = null;
  191. }
  192. });
  193. (e.ins = null), (e = s = a([t], e)), (i.default = e = s);