RoleService.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. e =
  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});
  18. const a = t("App"),
  19. o = t("NodePool"),
  20. n = t("CostumeController"),
  21. r = t("GameConst"),
  22. l = t("Car"),
  23. h = t("Chef"),
  24. c = t("CarAI"),
  25. d = t("ChefAI"),
  26. u = t("CustomerAI"),
  27. p = t("RoleSpeakComponent"),
  28. f = t("WaiterAI"),
  29. g = t("Customer"),
  30. m = t("MainCat"),
  31. _ = t("Waiter"),
  32. y = t("BaseService"),
  33. v = t("DeskService"),
  34. U = t("MapService"),
  35. {ccclass: Z, property: C} = cc._decorator;
  36. t = s = class extends y.default {
  37. constructor() {
  38. super(...arguments),
  39. (this.layer = null),
  40. (this.deskService = null),
  41. (this.nextTime = 0),
  42. (this.customerPool = null),
  43. (this.carPool = null),
  44. (this.chefPool = null),
  45. (this.waiterPool = null),
  46. (this.mainCatPool = null),
  47. (this.chefs = []),
  48. (this.waiters = []),
  49. (this.customers = []),
  50. (this.cars = []),
  51. (this.testMan = null),
  52. (this.enter = null),
  53. (this.exit = null),
  54. (this.canCreateCar = !0),
  55. (this.chefspeed = 100),
  56. (this.waiterspeed = 100),
  57. (this.chefCnt = 0),
  58. (this.customerCnt = 1),
  59. (this.waiterCnt = 0),
  60. (this.carCnt = 1),
  61. (this.waiterPosIdx = 0),
  62. (this.chefPosIdx = 0),
  63. (this.rapidCats = null),
  64. (this.isTalking = !1),
  65. (this._mainCat = null);
  66. }
  67. onLoad() {
  68. (s.ins = this).roleLang = a.default.ConfigManager.getConfig("RoleLang");
  69. }
  70. getNextWaiterPos() {
  71. return this.waiterPosIdx == this.waiterPosList.length
  72. ? this.waiterPosList[this.waiterPosIdx - 1]
  73. : this.waiterPosList[this.waiterPosIdx++];
  74. }
  75. getNextChefPos() {
  76. return this.chefPosIdx == this.chefPosList.length
  77. ? this.chefPosList[this.chefPosIdx - 1]
  78. : this.chefPosList[this.chefPosIdx++];
  79. }
  80. updateChefSpeed() {
  81. for (const t of this.chefs) t.calSpeed();
  82. }
  83. updateWaiterSpeed() {
  84. for (const t of this.waiters) t.calSpeed();
  85. }
  86. removeEmployee(t) {
  87. this.chefs.remove(t), this.waiters.remove(t), t.node.destroy();
  88. }
  89. tempUpdate(t) {
  90. if (this.nextTime < 0) {
  91. if (this.deskService.empPosList.length) {
  92. const t = this.deskService.empPosList.pop(),
  93. e = this.createCustomer();
  94. e.addComponent(u.default),
  95. (e.posData = t),
  96. (e.node.position = this.enter),
  97. this.layer.addChild(e.node),
  98. e.ranSkin(),
  99. this.customers.push(e);
  100. }
  101. this.nextTime = 1;
  102. } else this.nextTime -= t;
  103. }
  104. tempCarUpdate(t) {
  105. if (this.nextTime < 0) {
  106. if (this.canCreateCar && this.cars.length < this.carCnt) {
  107. const t = this.createCar();
  108. t.addComponent(c.default),
  109. (t.posData = v.default.ins.carPosData.posData),
  110. (t.carPosData = v.default.ins.carPosData),
  111. (t.node.position = this.enter),
  112. this.layer.addChild(t.node),
  113. this.cars.push(t);
  114. }
  115. this.nextTime = 1;
  116. } else this.nextTime -= t;
  117. }
  118. createManCat(t, e) {
  119. const i = this.mainCatPool.pop(),
  120. s = i.getComponent(m.default);
  121. return (
  122. void 0 !== e && (s.skinName = e),
  123. (s.selfAttr = t),
  124. 1 === U.default.ins.curCfg.type
  125. ? ((s.isWaiter = !0),
  126. i.addComponent(f.default),
  127. this.waiters.push(s),
  128. (s.basePos = i.position = this.getNextWaiterPos()))
  129. : ((s.basePos = i.position = this.getNextChefPos()), i.addComponent(d.default), this.chefs.push(s)),
  130. this.layer.addChild(i),
  131. s.calSpeed(),
  132. s
  133. );
  134. }
  135. createRapidCat() {
  136. const t = this.mainCatPool.pop(),
  137. e = (this._mainCat = t.getComponent(m.default));
  138. (e.selfAttr = n.default.ins.getModel().attr),
  139. 1 === U.default.ins.curCfg.type
  140. ? ((e.isWaiter = !0),
  141. t.addComponent(f.default),
  142. this.waiters.push(e),
  143. (e.basePos = t.position = this.getNextWaiterPos()))
  144. : ((e.basePos = t.position = this.getNextChefPos()), t.addComponent(d.default), this.chefs.push(e)),
  145. this.layer.addChild(t),
  146. e.calSpeed();
  147. }
  148. createTestMan() {
  149. var t = this.mainCatPool.pop().getComponent(m.default);
  150. (this.testMan = t),
  151. (this.testMan.node.position = this.enter),
  152. this.layer.addChild(this.testMan.node),
  153. this.testMan.updateSlot(n.default.ins.getModel().equipItems);
  154. }
  155. createCustomer() {
  156. return this.customerPool.pop().getComponent(g.default);
  157. }
  158. createCar() {
  159. return this.carPool.pop().getComponent(l.default);
  160. }
  161. createWaiter(t) {
  162. const e = this.waiterPool.pop(),
  163. i = e.getComponent(_.default);
  164. return (
  165. i.calSpeed(),
  166. e.addComponent(f.default),
  167. (i.basePos = e.position = t || this.getNextWaiterPos()),
  168. this.layer.addChild(e),
  169. this.waiters.push(i),
  170. i
  171. );
  172. }
  173. createChef(t) {
  174. const e = this.chefPool.pop(),
  175. i = e.getComponent(h.default);
  176. return (
  177. (i.basePos = e.position = t || this.getNextChefPos()),
  178. i.calSpeed(),
  179. this.layer.addChild(e),
  180. i.addComponent(d.default),
  181. this.chefs.push(i),
  182. i
  183. );
  184. }
  185. update(t) {}
  186. parse(t) {
  187. const e = t.getChildByName("CustomerTrans");
  188. (this.enter = e.getChildByName("EnterTrans").position),
  189. (this.exit = e.getChildByName("ExitTrans").position),
  190. e.destroy();
  191. const i = t.getChildByName("CashierSpawnTrans");
  192. (this.waiterPosList = i.children.map(t => t.position)), i.destroy();
  193. const s = t.getChildByName("SpawnTrans");
  194. (this.chefPosList = s.children.map(t => t.position)), s.destroy();
  195. }
  196. destroySelf() {
  197. (this.chefs = []),
  198. (this.waiters = []),
  199. (this.customers = []),
  200. (this.testMan = null),
  201. (this._mainCat = null),
  202. (this.canCreateCar = !0),
  203. (this.waiterPosIdx = 0),
  204. (this.chefPosIdx = 0),
  205. (this.update = () => {});
  206. }
  207. init() {
  208. U.default.ins.curCfg.type === r.StageType.CAR
  209. ? (this.update = this.tempCarUpdate)
  210. : (this.update = this.tempUpdate),
  211. (this.deskService = v.default.ins),
  212. (this.layer = U.default.ins.layer);
  213. var t = U.default.ins.curCfg.type;
  214. if (
  215. ((this._mainCat = this.createManCat(n.default.ins.getModel().attr)),
  216. this.onEquipOrUnEquipCostume(),
  217. 1 === t)
  218. ) {
  219. var e = this.waiterCnt;
  220. for (let t = 0; t < e; t++) this.createWaiter();
  221. } else if (2 === t || 3 === t) {
  222. this.waiterCnt++;
  223. let e = this.waiterCnt;
  224. for (let t = 0; t < e; t++) this.createWaiter();
  225. e = this.chefCnt;
  226. for (let t = 0; t < e; t++) this.createChef();
  227. }
  228. a.default.NotificationCenter.addListener(
  229. r.GameNotificationConst.EQUIP_COSTUME,
  230. this.onEquipOrUnEquipCostume,
  231. this
  232. ),
  233. a.default.NotificationCenter.addListener(
  234. r.GameNotificationConst.UNEQUIP_COSTUME,
  235. this.onEquipOrUnEquipCostume,
  236. this
  237. );
  238. }
  239. onEquipOrUnEquipCostume() {
  240. this._mainCat.updateSlot(n.default.ins.getModel().equipItems),
  241. this.testMan && this.testMan.updateSlot(n.default.ins.getModel().equipItems);
  242. }
  243. getNewMainCat() {
  244. return this.mainCatPool.pop();
  245. }
  246. removeNewMainCat(t) {
  247. this.mainCatPool.push(t);
  248. }
  249. talkingFinish() {
  250. this.isTalking = !1;
  251. }
  252. showLang(t, e) {
  253. if (this.isTalking) return !1;
  254. var i = this.roleLang[e];
  255. if (a.default.RandomUtils.limit(0, 100) > i.rate) return !1;
  256. this.isTalking = !0;
  257. const s = a.default.RandomUtils.randomArray(this.roleLang[e].lang),
  258. o = a.default.NodePoolMsr.roleLangPool.pop();
  259. return U.default.ins.langLayer.addChild(o), o.getComponent(p.RoleSpeakComponent).init(t, s.lang), !0;
  260. }
  261. };
  262. e([C(o.default)], t.prototype, "customerPool", void 0),
  263. e([C(o.default)], t.prototype, "carPool", void 0),
  264. e([C(o.default)], t.prototype, "chefPool", void 0),
  265. e([C(o.default)], t.prototype, "waiterPool", void 0),
  266. e([C(o.default)], t.prototype, "mainCatPool", void 0),
  267. (t = s = e([Z], t)),
  268. (i.default = t = s);