3c877c8f-8ef6-4543-9246-a2f90fe634cf.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. "use strict";
  2. cc._RF.push(module, '3c877yPjvZFQ5JGovkP5jTP', 'Table');
  3. // Script/Table.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var Beef_1 = require("./Beef");
  26. var gameScene_1 = require("./gameScene");
  27. var guidePanel_1 = require("./guide/guidePanel");
  28. var App_1 = require("./Manager/App");
  29. var Person_1 = require("./Person");
  30. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  31. var Table = /** @class */ (function (_super) {
  32. __extends(Table, _super);
  33. function Table() {
  34. var _this = _super !== null && _super.apply(this, arguments) || this;
  35. // @property([cc.SpriteFrame])
  36. // private tableSpriteFrame: cc.SpriteFrame[] = [];
  37. _this.btnShengNiuPai = null;
  38. _this.rawSteakList = [null, null, null, null];
  39. _this.cookedSteakList = [null, null, null, null];
  40. _this.prefabBeef = null;
  41. _this.btnYellowSouce = null;
  42. _this.btnCocumber = null;
  43. _this.btnTomato = null;
  44. _this.btnRedSouce = null;
  45. _this.liuShui = null;
  46. _this.drinkCup = null;
  47. _this.kaoPanGaiZi = [];
  48. _this.plateGaiZi = [];
  49. _this.cupGaiZi = [];
  50. _this.pDrinkBar = null;
  51. _this.m_shuiLiuTime = 3;
  52. _this.fullCup = null;
  53. _this.drinkCupList = [];
  54. _this.kaoPanNum = 2;
  55. _this.plateNum = 2;
  56. _this.cupNum = 3;
  57. _this.beefBornPos = [cc.v3(-290, -185, 0), cc.v3(-197, -195, 0), cc.v3(-243, -131, 0), cc.v3(-160, -133, 0)];
  58. _this.platePos = [cc.v3(-58, -200, 0), cc.v3(80, -201, 0), cc.v3(-52, -126, 0), cc.v3(68, -131, 0)];
  59. _this.burntPos = cc.v3(-360, -640, 0);
  60. _this.cupPos = [cc.v3(258, -209, 0), cc.v3(232, -161, 0), cc.v3(205, -115, 0)];
  61. // ------------------------person---------------------------
  62. _this.renwuPerfabList = [];
  63. _this.personList = [];
  64. // 点餐位置
  65. _this.personPos = [cc.v3(30, 38, 0), cc.v3(260, 38, 0), cc.v3(-200, 38, 0)];
  66. // 人物出生位置
  67. _this.bornPos = [cc.v3(-500, 38, 0), cc.v3(550, 38, 0)];
  68. _this.fixTime = 1;
  69. _this.passTime = 0;
  70. _this.personWalkTime = 2;
  71. _this.createpPersonNum = 0; //已经来了到少人
  72. _this.fullPersonNum = 0; //多少吃饱了
  73. _this.maxSitPersonNum = 3; //总共只能坐下人数
  74. return _this;
  75. }
  76. Table_1 = Table;
  77. // LIFE-CYCLE CALLBACKS:
  78. Table.getInstance = function () {
  79. if (this._instance == null) {
  80. this._instance = new Table_1();
  81. }
  82. return this._instance;
  83. };
  84. Table.prototype.onLoad = function () {
  85. Table_1._instance = this;
  86. this.btnShengNiuPai.node.on(cc.Node.EventType.TOUCH_END, this.onClickShengNiuPai.bind(this), this);
  87. this.btnYellowSouce.node.on(cc.Node.EventType.TOUCH_END, this.onClickYellowSouce.bind(this), this);
  88. this.btnCocumber.node.on(cc.Node.EventType.TOUCH_END, this.onClickCocumber.bind(this), this);
  89. this.btnTomato.node.on(cc.Node.EventType.TOUCH_END, this.onClickTomato.bind(this), this);
  90. this.btnRedSouce.node.on(cc.Node.EventType.TOUCH_END, this.onClickRedSouce.bind(this), this);
  91. // this.drinksMachine.node.on(cc.Node.EventType.TOUCH_END, this.onClickDrinksMachine.bind(this), this);
  92. for (var i = 0; i < this.maxSitPersonNum; i++) {
  93. this.personList[i] = null;
  94. }
  95. this.plateNum = App_1.App.DataManager.kitchenNum[0][App_1.App.DataManager.kinchenLevel[0]];
  96. this.kaoPanNum = App_1.App.DataManager.kitchenNum[1][App_1.App.DataManager.kinchenLevel[1]];
  97. this.cupNum = App_1.App.DataManager.kitchenNum[2][App_1.App.DataManager.kinchenLevel[2]];
  98. };
  99. Table.prototype.start = function () {
  100. for (var i = 0; i < this.kaoPanNum - 2; i++) {
  101. this.kaoPanGaiZi[i].active = false;
  102. }
  103. for (var i = 0; i < this.plateNum - 2; i++) {
  104. this.plateGaiZi[i].active = true;
  105. }
  106. for (var i = 0; i < this.cupNum - 1; i++) {
  107. this.cupGaiZi[i].active = true;
  108. }
  109. if (App_1.App.DataManager.CurrentIntoLevel >= 3) {
  110. this.btnTomato.node.active = true;
  111. }
  112. if (App_1.App.DataManager.CurrentIntoLevel >= 5) {
  113. this.btnYellowSouce.node.active = true;
  114. }
  115. if (App_1.App.DataManager.CurrentIntoLevel >= 7) {
  116. this.btnRedSouce.node.active = true;
  117. }
  118. this.onClickDrinksMachine();
  119. if (App_1.App.DataManager.guideStep == 0) {
  120. guidePanel_1.default.getInstance().showCurGuide();
  121. }
  122. };
  123. Table.prototype.onClickShengNiuPai = function () {
  124. if (App_1.App.DataManager.guideStep == 0) {
  125. App_1.App.DataManager.guideStep++;
  126. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep);
  127. guidePanel_1.default.getInstance().hideGuideStep();
  128. }
  129. for (var i = 0; i < this.kaoPanNum; i++) {
  130. if (this.rawSteakList[i] == null) {
  131. var beef = cc.instantiate(this.prefabBeef);
  132. beef.on(cc.Node.EventType.TOUCH_END, this.onClickRawBeef.bind(this, i), beef);
  133. beef.setPosition(this.beefBornPos[i]);
  134. this.node.addChild(beef);
  135. this.rawSteakList[i] = beef;
  136. break;
  137. }
  138. }
  139. };
  140. Table.prototype.onClickRawBeef = function (index) {
  141. if (this.rawSteakList[index].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Burnt) {
  142. cc.tween(this.rawSteakList[index]).to(0.5, { position: this.burntPos }).removeSelf().start();
  143. this.rawSteakList[index] = null;
  144. return;
  145. }
  146. else if (this.rawSteakList[index].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Cooked) {
  147. for (var i = 0; i < this.plateNum; i++) {
  148. if (!this.cookedSteakList[i]) {
  149. this.rawSteakList[index].targetOff(this.rawSteakList[index]);
  150. // this.rawSteakList[index].off(cc.Node.EventType.TOUCH_END, this.onClickRawBeef.bind(this, index), this);
  151. this.cookedSteakList[i] = this.rawSteakList[index];
  152. this.rawSteakList[index] = null;
  153. // 从烤架移动到盘子里面
  154. this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.Plate);
  155. this.cookedSteakList[i].on(cc.Node.EventType.TOUCH_END, this.onClickCookedBeef.bind(this, i), this);
  156. cc.tween(this.cookedSteakList[i]).to(0.5, { position: this.platePos[i] }).start();
  157. break;
  158. }
  159. }
  160. if (App_1.App.DataManager.guideStep == 1) {
  161. App_1.App.DataManager.guideStep++;
  162. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep);
  163. guidePanel_1.default.getInstance().showCurGuide();
  164. }
  165. }
  166. };
  167. // 点击熟牛排
  168. Table.prototype.onClickCookedBeef = function (index) {
  169. if (App_1.App.DataManager.guideStep == 3) {
  170. App_1.App.DataManager.guideStep++;
  171. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep);
  172. guidePanel_1.default.getInstance().showCurGuide();
  173. }
  174. // todo 移动到人
  175. // 移动到人之后,从数组里面删除
  176. var toPos = this.findFoodPos(this.cookedSteakList[index].getComponent(Beef_1.default).m_foodType);
  177. if (toPos) {
  178. var pos = this.node.convertToNodeSpaceAR(toPos);
  179. cc.tween(this.cookedSteakList[index]).to(0.5, { position: pos, scale: 0.5 }).removeSelf().start();
  180. this.cookedSteakList[index] = null;
  181. }
  182. };
  183. Table.prototype.onClickYellowSouce = function () {
  184. for (var i = 0; i < this.cookedSteakList.length; i++) {
  185. if (this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Cocumber) {
  186. this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.YellowSouce);
  187. break;
  188. }
  189. }
  190. };
  191. Table.prototype.onClickCocumber = function () {
  192. if (App_1.App.DataManager.guideStep == 2) {
  193. App_1.App.DataManager.guideStep++;
  194. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep);
  195. guidePanel_1.default.getInstance().showCurGuide();
  196. }
  197. for (var i = 0; i < this.cookedSteakList.length; i++) {
  198. if (this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Plate) {
  199. this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.Cocumber);
  200. break;
  201. }
  202. }
  203. };
  204. Table.prototype.onClickTomato = function () {
  205. for (var i = 0; i < this.cookedSteakList.length; i++) {
  206. if (this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Plate) {
  207. this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.Tomato);
  208. break;
  209. }
  210. }
  211. };
  212. Table.prototype.onClickRedSouce = function () {
  213. for (var i = 0; i < this.cookedSteakList.length; i++) {
  214. if (this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Tomato) {
  215. this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.RedSouce);
  216. break;
  217. }
  218. }
  219. };
  220. Table.prototype.onClickDrinksMachine = function () {
  221. var _this = this;
  222. this.pDrinkBar.node.active = true;
  223. this.liuShui.active = true;
  224. App_1.App.SpinManager.PlaySpinAnimation(this.liuShui, "newAnimation", true, null);
  225. App_1.App.SpinManager.PlaySpinAnimation(this.drinkCup, "newAnimation", false, null);
  226. this.pDrinkBar.progress = 0;
  227. cc.tween(this.pDrinkBar).to(this.m_shuiLiuTime, { progress: 1 }).call(function () {
  228. _this.pDrinkBar.node.active = false;
  229. _this.liuShui.active = false;
  230. _this.drinkCup.getComponent(sp.Skeleton).animation = null;
  231. for (var i = 0; i < _this.cupNum; i++) {
  232. if (!_this.drinkCupList[i]) {
  233. var cup = cc.instantiate(_this.fullCup);
  234. cup.setPosition(_this.drinkCup.getPosition());
  235. _this.node.addChild(cup);
  236. cup.zIndex = _this.cupNum - i;
  237. _this.drinkCupList[i] = cup;
  238. cup.on(cc.Node.EventType.TOUCH_END, _this.onClickFullCup.bind(_this, i), _this);
  239. if (i == 0) {
  240. cc.tween(cup).to(0.5, { position: _this.cupPos[0] }).start();
  241. }
  242. else {
  243. cc.tween(cup).to(0.5, { position: _this.cupPos[0] }).to(0.2, { position: _this.cupPos[i] }).start();
  244. }
  245. }
  246. }
  247. }).start();
  248. };
  249. // 点击饮料
  250. Table.prototype.onClickFullCup = function (index) {
  251. // todo 移动到人
  252. if (App_1.App.DataManager.guideStep == 4) {
  253. App_1.App.DataManager.guideStep++;
  254. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep);
  255. guidePanel_1.default.getInstance().hideGuideStep();
  256. }
  257. // 移动到人之后,从数组里面删除
  258. var toPos = this.findFoodPos(Beef_1.FoodType.Drink);
  259. if (toPos) {
  260. var pos = this.node.convertToNodeSpaceAR(toPos);
  261. cc.tween(this.drinkCupList[index]).to(0.3, { position: pos, scale: 0.5 }).removeSelf().start();
  262. this.drinkCupList[index] = null;
  263. // this.m_machineState = DrinksMachineState.None;
  264. this.onClickDrinksMachine();
  265. }
  266. };
  267. Table.prototype.onDisable = function () {
  268. this.btnShengNiuPai.node.off(cc.Node.EventType.TOUCH_END, this.onClickShengNiuPai.bind(this), this);
  269. this.btnYellowSouce.node.off(cc.Node.EventType.TOUCH_END, this.onClickYellowSouce.bind(this), this);
  270. this.btnCocumber.node.off(cc.Node.EventType.TOUCH_END, this.onClickCocumber.bind(this), this);
  271. this.btnTomato.node.off(cc.Node.EventType.TOUCH_END, this.onClickTomato.bind(this), this);
  272. this.btnRedSouce.node.off(cc.Node.EventType.TOUCH_END, this.onClickRedSouce.bind(this), this);
  273. };
  274. // 找到点这个食物剩余时间最少的人
  275. Table.prototype.findFoodPos = function (foodt) {
  276. var curPerson = null;
  277. var personIndex = -1;
  278. var lessLeftTime = 100;
  279. for (var i = 0; i < this.maxSitPersonNum; i++) {
  280. if (this.personList[i] && this.personList[i].getComponent(Person_1.default).m_state == Person_1.PersonState.Waite) {
  281. // 点餐种类
  282. var fTypelist = this.personList[i].getComponent(Person_1.default).foodTypeList;
  283. var time = this.personList[i].getComponent(Person_1.default).leftTime;
  284. for (var j = 0; j < fTypelist.length; j++) {
  285. if (foodt == fTypelist[j] && lessLeftTime > time) {
  286. lessLeftTime = time;
  287. personIndex = i;
  288. curPerson = this.personList[i];
  289. }
  290. }
  291. }
  292. }
  293. if (curPerson) {
  294. var worldPos = curPerson.getComponent(Person_1.default).getFoodWorldPos(foodt);
  295. if (curPerson.getComponent(Person_1.default).judgeFoodFull()) {
  296. this.fullPersonNum++;
  297. var smallLevel = App_1.App.DataManager.PassProgress[App_1.App.DataManager.CurrentIntoLevel];
  298. if (this.fullPersonNum == App_1.App.DataManager.personCount[App_1.App.DataManager.CurrentIntoLevel - 1][smallLevel - 1]) {
  299. // GameSuccess
  300. this.personList[personIndex] = null;
  301. var rand_1 = Math.round(Math.random());
  302. cc.tween(curPerson).delay(0.6).call(function () {
  303. curPerson.getComponent(Person_1.default).setState(Person_1.PersonState.FullOut);
  304. if (rand_1 == 1) {
  305. curPerson.getChildByName("renwu").scaleX = -0.5;
  306. }
  307. }).to(this.personWalkTime, { position: this.bornPos[rand_1] }).call(function () {
  308. curPerson.removeFromParent();
  309. }).start();
  310. gameScene_1.default.instance.GameSuccess();
  311. }
  312. else {
  313. var rand_2 = Math.round(Math.random());
  314. this.personList[personIndex] = null;
  315. cc.tween(curPerson).delay(0.6).call(function () {
  316. curPerson.getComponent(Person_1.default).setState(Person_1.PersonState.FullOut);
  317. if (rand_2 == 1) {
  318. curPerson.getChildByName("renwu").scaleX = -0.5;
  319. }
  320. }).to(this.personWalkTime, { position: this.bornPos[rand_2] }).call(function () {
  321. curPerson.removeFromParent();
  322. }).start();
  323. }
  324. }
  325. return worldPos;
  326. }
  327. return null;
  328. };
  329. Table.prototype.update = function (dt) {
  330. if (!gameScene_1.default.instance.GameStutas)
  331. return;
  332. this.passTime += dt;
  333. var smallLevel = App_1.App.DataManager.PassProgress[App_1.App.DataManager.CurrentIntoLevel];
  334. if (this.passTime >= this.fixTime && this.createpPersonNum < App_1.App.DataManager.personCount[App_1.App.DataManager.CurrentIntoLevel - 1][smallLevel - 1]) {
  335. this.passTime = 0;
  336. this.fixTime = 1;
  337. console.log("aaa-------randomIndex---------", smallLevel);
  338. var _loop_1 = function (i) {
  339. if (!this_1.personList[i]) {
  340. var randomIndex = Math.floor(Math.random() * this_1.renwuPerfabList.length);
  341. var person_1 = cc.instantiate(this_1.renwuPerfabList[randomIndex]);
  342. person_1.getComponent(Person_1.default).setState(Person_1.PersonState.Comming);
  343. person_1.zIndex = -1;
  344. this_1.node.addChild(person_1);
  345. this_1.personList[i] = person_1;
  346. var rand = Math.round(Math.random());
  347. person_1.setPosition(this_1.bornPos[rand]);
  348. if (rand == 0) {
  349. person_1.getChildByName("renwu").scaleX = -0.5;
  350. }
  351. App_1.App.SpinManager.PlaySpinAnimation(person_1.getChildByName("renwu"), "newAnimation", true);
  352. cc.tween(person_1).to(this_1.personWalkTime, { position: this_1.personPos[i] }).call(function () {
  353. person_1.getChildByName("renwu").scaleX = 0.5;
  354. person_1.getComponent(Person_1.default).setState(Person_1.PersonState.Waite);
  355. }).start();
  356. this_1.createpPersonNum++;
  357. var smallLevel_1 = App_1.App.DataManager.PassProgress[App_1.App.DataManager.CurrentIntoLevel];
  358. gameScene_1.default.instance.updateLeftPeople(App_1.App.DataManager.personCount[App_1.App.DataManager.CurrentIntoLevel - 1][smallLevel_1 - 1] - this_1.createpPersonNum);
  359. return "break";
  360. }
  361. };
  362. var this_1 = this;
  363. for (var i = 0; i < this.maxSitPersonNum; i++) {
  364. var state_1 = _loop_1(i);
  365. if (state_1 === "break")
  366. break;
  367. }
  368. }
  369. };
  370. var Table_1;
  371. Table._instance = null;
  372. __decorate([
  373. property(cc.Button)
  374. ], Table.prototype, "btnShengNiuPai", void 0);
  375. __decorate([
  376. property(cc.Prefab)
  377. ], Table.prototype, "prefabBeef", void 0);
  378. __decorate([
  379. property(cc.Button)
  380. ], Table.prototype, "btnYellowSouce", void 0);
  381. __decorate([
  382. property(cc.Button)
  383. ], Table.prototype, "btnCocumber", void 0);
  384. __decorate([
  385. property(cc.Button)
  386. ], Table.prototype, "btnTomato", void 0);
  387. __decorate([
  388. property(cc.Button)
  389. ], Table.prototype, "btnRedSouce", void 0);
  390. __decorate([
  391. property(cc.Node)
  392. ], Table.prototype, "liuShui", void 0);
  393. __decorate([
  394. property(cc.Node)
  395. ], Table.prototype, "drinkCup", void 0);
  396. __decorate([
  397. property([cc.Node])
  398. ], Table.prototype, "kaoPanGaiZi", void 0);
  399. __decorate([
  400. property([cc.Node])
  401. ], Table.prototype, "plateGaiZi", void 0);
  402. __decorate([
  403. property([cc.Node])
  404. ], Table.prototype, "cupGaiZi", void 0);
  405. __decorate([
  406. property(cc.ProgressBar)
  407. ], Table.prototype, "pDrinkBar", void 0);
  408. __decorate([
  409. property(cc.Prefab)
  410. ], Table.prototype, "fullCup", void 0);
  411. __decorate([
  412. property([cc.Prefab])
  413. ], Table.prototype, "renwuPerfabList", void 0);
  414. Table = Table_1 = __decorate([
  415. ccclass
  416. ], Table);
  417. return Table;
  418. }(cc.Component));
  419. exports.default = Table;
  420. cc._RF.pop();