StageUpgradeService.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. o =
  6. (this && this.__decorate) ||
  7. function (t, e, i, s) {
  8. var o,
  9. a = arguments.length,
  10. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  11. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  12. else
  13. for (var r = t.length - 1; 0 <= r; r--)
  14. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  15. return 3 < a && n && Object.defineProperty(e, i, n), n;
  16. };
  17. Object.defineProperty(i, "__esModule", {value: !0}), (i.AbilityType = void 0);
  18. const a = t("App"),
  19. n = t("RedPointMgr"),
  20. r = t("Toast"),
  21. l = t("NotificationConst"),
  22. h = (t("ViewConst"), t("SystemOpenConst")),
  23. c = t("RoleUnlockAni"),
  24. d = t("StageUpgradeData"),
  25. u = t("GameConst"),
  26. p = t("GlobalAttr"),
  27. f = t("BaseService"),
  28. g = t("CurrencyService"),
  29. m = t("DeskService"),
  30. _ = t("MachineService"),
  31. y = t("MapService"),
  32. v = t("RoleService");
  33. n.RedPointMgr.types.StageUpgrade = "StageUpgrade";
  34. var U,
  35. {ccclass: e} = cc._decorator,
  36. t = (s = class extends f.default {
  37. constructor() {
  38. super(...arguments),
  39. (this.define = null),
  40. (this.datas = null),
  41. (this.menuprofitValue = null),
  42. (this.fastermenu = null),
  43. (this.saveData = null),
  44. (this.funMap = {}),
  45. (this.isSysOpen = !1);
  46. }
  47. onLoad() {
  48. ((s.ins = this).funMap[U.menuprofit] = this.onMenuprofit),
  49. (this.funMap[U.allmenuprofit] = this.onAllmenuprofit),
  50. (this.funMap[U.fastermenu] = this.onFastermenu),
  51. (this.funMap[U.chefspeed] = this.onChefspeed),
  52. (this.funMap[U.cashirespeed] = this.onCashirespeed),
  53. (this.funMap[U.addchef] = this.onAddchef),
  54. (this.funMap[U.addcashire] = this.onAddcashire),
  55. (this.funMap[U.addcustomer1] = this.onAddcustomer1),
  56. (this.funMap[U.addcustomer2] = this.onAddcustomer2),
  57. (this.funMap[U.addcar] = this.onAddcar),
  58. this.initEvent();
  59. }
  60. unlockAll() {
  61. for (const t of this.datas.concat()) this.buy(t.cfg.order, !0);
  62. }
  63. buy(t, e = !1, i) {
  64. for (const s of this.datas)
  65. if (s.cfg.order === t) {
  66. if (!e && !g.default.ins.moneyChange(-s.cost)) return r.default.launch("金币不足!"), !1;
  67. this.funMap[s.cfg.ability_type] && this.funMap[s.cfg.ability_type].call(this, s),
  68. this.saveData.push(s.cfg.order),
  69. this.datas.remove(s),
  70. a.default.NotificationCenter.dispatch(
  71. l.NotificationConst.STAGE_UPGRADE_UPDATE,
  72. this.datas.length,
  73. i
  74. );
  75. break;
  76. }
  77. return this.onUpdateMoney(), !0;
  78. }
  79. init() {
  80. const e = v.default.ins;
  81. (e.chefspeed = 100),
  82. (e.waiterspeed = 100),
  83. (e.chefCnt = 0),
  84. (e.waiterCnt = 0),
  85. (e.customerCnt = 1),
  86. (e.carCnt = 1),
  87. (this.menuprofitValue = {}),
  88. (this.fastermenu = {}),
  89. (this.datas = []);
  90. const i = this.getModel().getCurMapData();
  91. i.stageUpgrade || (i.stageUpgrade = []), (this.saveData = i.stageUpgrade);
  92. var s = y.default.ins.curCfg.StageUpgrade;
  93. let o = s.length;
  94. for (let t = 0; t < o; t++) {
  95. const e = new d.default(),
  96. o = s[t];
  97. e.init(o),
  98. i.stageUpgrade.includes(o.order)
  99. ? this.funMap[o.ability_type] && this.funMap[o.ability_type].call(this, e, !0)
  100. : this.datas.push(e);
  101. }
  102. this.onUpdateMoney();
  103. }
  104. initEvent() {
  105. a.default.NotificationCenter.addListener(l.NotificationConst.UPDATE_MONEY, this.onUpdateMoney, this),
  106. a.default.NotificationCenter.addListener(l.NotificationConst.SYS_OPEN, this.onSysOpen, this);
  107. }
  108. onSysOpen(t, e) {
  109. t == h.OpenTypeConst.STAGE_UPGRADE &&
  110. e &&
  111. ((this.isSysOpen = !0),
  112. a.default.NotificationCenter.removeListener(l.NotificationConst.SYS_OPEN, this.onSysOpen, this));
  113. }
  114. onMenuprofit(t, e) {
  115. this.menuprofitValue[t.cfg.ability_target]
  116. ? (this.menuprofitValue[t.cfg.ability_target] *= t.cfg.ability_value)
  117. : (this.menuprofitValue[t.cfg.ability_target] = t.cfg.ability_value),
  118. e || _.default.ins.reCalFoodValue(t.cfg.ability_target - 1);
  119. }
  120. onFastermenu(t, e) {
  121. this.fastermenu[t.cfg.ability_target]
  122. ? (this.fastermenu[t.cfg.ability_target] *= t.cfg.ability_value / 100)
  123. : (this.fastermenu[t.cfg.ability_target] = t.cfg.ability_value / 100),
  124. e || _.default.ins.machineDatas[t.cfg.ability_target - 1].attr.calFoodFinalTime();
  125. }
  126. onAllmenuprofit(t, e) {
  127. this.menuprofitValue[t.cfg.ability_target]
  128. ? (this.menuprofitValue[t.cfg.ability_target] *= t.cfg.ability_value)
  129. : (this.menuprofitValue[t.cfg.ability_target] = t.cfg.ability_value),
  130. e || _.default.ins.reCalAllFoodValue();
  131. }
  132. onCashirespeed(t, e) {
  133. (v.default.ins.waiterspeed = (v.default.ins.waiterspeed * t.cfg.ability_value) / 100),
  134. e || p.default.ins.calWaiterSpeed();
  135. }
  136. onChefspeed(t, e) {
  137. (v.default.ins.chefspeed = (v.default.ins.chefspeed * t.cfg.ability_value) / 100),
  138. e || p.default.ins.calChefSpeed();
  139. }
  140. onAddcashire(e, i) {
  141. if (((v.default.ins.waiterCnt += e.cfg.ability_value), !i)) {
  142. const i = y.default.ins.layer;
  143. for (let t = 0; t < e.cfg.ability_value; t++) {
  144. const e = a.default.NodePoolMsr.catUnlockAni.pop(),
  145. s = e.getComponent(c.default),
  146. o = v.default.ins.getNextWaiterPos();
  147. (e.position = o),
  148. i.addChild(e),
  149. s.init(() => {
  150. var t = v.default.ins.createWaiter(o);
  151. v.default.ins.showLang(t.node, u.RoleLangType.OPEN_BOX);
  152. }, this);
  153. }
  154. }
  155. }
  156. onAddchef(e, i) {
  157. if (((v.default.ins.chefCnt += e.cfg.ability_value), !i)) {
  158. const i = y.default.ins.layer;
  159. for (let t = 0; t < e.cfg.ability_value; t++) {
  160. const e = a.default.NodePoolMsr.catUnlockAni.pop(),
  161. s = e.getComponent(c.default),
  162. o = v.default.ins.getNextChefPos();
  163. (e.position = o),
  164. i.addChild(e),
  165. s.init(() => {
  166. var t = v.default.ins.createChef(o);
  167. v.default.ins.showLang(t.node, u.RoleLangType.OPEN_BOX);
  168. }, this);
  169. }
  170. }
  171. }
  172. onAddcustomer1(t, e) {
  173. m.default.ins.unlockDesk2();
  174. }
  175. onAddcustomer2(t, e) {
  176. if (e) m.default.ins.unlockDesk(t.cfg.ability_target);
  177. else {
  178. const e = m.default.ins.deskDatas[t.cfg.ability_target],
  179. i = a.default.NodePoolMsr.cookUnlockAni.pop(),
  180. s = i.getComponent(c.default),
  181. o = e.node.position;
  182. (i.position = o),
  183. y.default.ins.layer.addChild(i),
  184. s.init(() => {
  185. m.default.ins.unlockDesk(t.cfg.ability_target);
  186. }, this);
  187. }
  188. }
  189. onAddcar(t, e) {
  190. v.default.ins.carCnt += t.cfg.ability_value;
  191. }
  192. desotrySelf() {}
  193. updateUpgradeDiscount() {
  194. for (const t of this.datas) t.calCost();
  195. this.onUpdateMoney();
  196. }
  197. onUpdateMoney() {
  198. let t = !1;
  199. var e = y.default.ins.mapSaveData.money;
  200. for (const i of this.datas)
  201. if (i.cost <= e) {
  202. t = !0;
  203. break;
  204. }
  205. a.default.RedPointMgr.next(a.default.RedPointMgr.types.StageUpgrade, t), this.updateTipView();
  206. }
  207. isUnlock(t) {
  208. const e = this.getModel().getCurMapData();
  209. return !!e.stageUpgrade && e.stageUpgrade.includes(t);
  210. }
  211. updateTipView() {
  212. if (this.isSysOpen && !(y.default.ins.curId > a.default.ConfigManager.gameConf.game.stageUpgradeTip)) {
  213. const e = this.datas[0];
  214. var t = e && e.canBuy();
  215. a.default.ViewManager.isShow(21)
  216. ? t
  217. ? a.default.ViewManager.getView(21).updateUI(e)
  218. : a.default.ViewManager.close(21)
  219. : t && a.default.ViewManager.open(21, e);
  220. }
  221. }
  222. });
  223. (t.ins = null),
  224. (t = s = o([e], t)),
  225. (i.default = t = s),
  226. ((i = U = i.AbilityType || (i.AbilityType = {}))[(i.menuprofit = 101)] = "menuprofit"),
  227. (i[(i.allmenuprofit = 102)] = "allmenuprofit"),
  228. (i[(i.fastermenu = 201)] = "fastermenu"),
  229. (i[(i.addcustomer1 = 301)] = "addcustomer1"),
  230. (i[(i.addcustomer2 = 302)] = "addcustomer2"),
  231. (i[(i.addcar = 303)] = "addcar"),
  232. (i[(i.addcashire = 401)] = "addcashire"),
  233. (i[(i.addchef = 402)] = "addchef"),
  234. (i[(i.cashirespeed = 501)] = "cashirespeed"),
  235. (i[(i.chefspeed = 502)] = "chefspeed");