CarAI.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var o,
  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 s = t("DeskService"),
  19. a = t("OrderService"),
  20. n = t("RoleService"),
  21. r = t("BaseMan"),
  22. l = t("Car"),
  23. h = t("OrderDisplay"),
  24. c = t("MoveComponent");
  25. ((t = o = o || {})[(t.NONE = 0)] = "NONE"),
  26. (t[(t.MOVE_TO_ORDER = 1)] = "MOVE_TO_ORDER"),
  27. (t[(t.WAIT_ORDER = 2)] = "WAIT_ORDER"),
  28. (t[(t.WAIT_FOOD = 3)] = "WAIT_FOOD"),
  29. (t[(t.MOVE_TO_FRONT = 4)] = "MOVE_TO_FRONT"),
  30. (t[(t.MOVE_TO_EXIT = 5)] = "MOVE_TO_EXIT");
  31. var {ccclass: t} = cc._decorator,
  32. t = e(
  33. [t],
  34. (t = class extends cc.Component {
  35. constructor() {
  36. super(...arguments), (this.man = null), (this.move = null), (this.state = o.NONE), (this.curIndex = -1);
  37. }
  38. onLoad() {
  39. (n.default.ins.canCreateCar = !1),
  40. (this.man = this.getComponent(l.default)),
  41. (this.move = this.getComponent(c.default));
  42. }
  43. log(...t) {
  44. cc.log("CarAI", ...t);
  45. }
  46. update(t) {
  47. if (this.man.state === r.CharactorState.stand)
  48. switch (this.state) {
  49. case o.WAIT_ORDER:
  50. case o.WAIT_FOOD:
  51. this.man.isEixt &&
  52. ((this.state = o.MOVE_TO_EXIT),
  53. n.default.ins.cars.remove(this.man),
  54. this.move.moveTo(n.default.ins.exit),
  55. (this.man.posData = null));
  56. break;
  57. case o.MOVE_TO_FRONT:
  58. 0 === this.curIndex
  59. ? ((this.man.isReadyReceive = !0),
  60. (this.state = o.WAIT_FOOD),
  61. s.default.ins.carCookDataFinish(this.man))
  62. : n.default.ins.cars.indexOf(this.man) !== this.curIndex &&
  63. ((this.curIndex = n.default.ins.cars.indexOf(this.man)),
  64. this.move.moveTo(this.man.carPosData.receiveTrans[this.curIndex]));
  65. break;
  66. case o.NONE:
  67. (this.state = o.MOVE_TO_ORDER), this.move.moveTo(this.man.carPosData.order);
  68. break;
  69. case o.MOVE_TO_ORDER:
  70. a.default.ins.waitOrderList.push({
  71. target: this,
  72. cb: this.orderFinish,
  73. pos: this.man.carPosData.staffTrans.pos,
  74. direction: this.man.carPosData.staffTrans.direction
  75. }),
  76. (this.state = o.WAIT_ORDER);
  77. break;
  78. case o.MOVE_TO_EXIT:
  79. this.man.destroySelf();
  80. }
  81. }
  82. orderFinish() {
  83. n.default.ins.canCreateCar = !0;
  84. const e = a.default.ins.createOrders(4),
  85. i = e.length;
  86. for (let t = 0; t < i; t++) {
  87. const i = e[t];
  88. this.man.orders.push(i);
  89. const s = a.default.ins.orderPool.pop();
  90. (s.x = s.y = 0),
  91. this.man.orderNode.children[t].addChild(s),
  92. (i.display = s.getComponent(h.default)),
  93. i.display || (i.display = s.addComponent(h.default)),
  94. (i.customer = this.man),
  95. i.display.setData(i);
  96. }
  97. (this.curIndex = n.default.ins.cars.indexOf(this.man)),
  98. this.move.moveTo(this.man.carPosData.receiveTrans[this.curIndex]),
  99. (this.state = o.MOVE_TO_FRONT);
  100. }
  101. })
  102. );
  103. i.default = t;