"use strict"; cc._RF.push(module, '3c877yPjvZFQ5JGovkP5jTP', 'Table'); // Script/Table.ts "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var Beef_1 = require("./Beef"); var gameScene_1 = require("./gameScene"); var guidePanel_1 = require("./guide/guidePanel"); var App_1 = require("./Manager/App"); var Person_1 = require("./Person"); var TipPanel_1 = require("./view/tipPanel/TipPanel"); var TipPanelMediator_1 = require("./view/tipPanel/TipPanelMediator"); var ATRewardedVideoJSSDK_1 = require("./AnyThinkAds/ATRewardedVideoJSSDK"); var ATAndroidJS2_1 = require("./ATAndroidJS2"); var GlobalManager_1 = require("./GlobalManager"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var Table = /** @class */ (function (_super) { __extends(Table, _super); function Table() { var _this = _super !== null && _super.apply(this, arguments) || this; // @property([cc.SpriteFrame]) // private tableSpriteFrame: cc.SpriteFrame[] = []; _this.btnShengNiuPai = null; _this.rawSteakList = [null, null, null, null]; _this.cookedSteakList = [null, null, null, null]; _this.prefabBeef = null; _this.btnYellowSouce = null; _this.btnCocumber = null; _this.btnTomato = null; _this.btnRedSouce = null; _this.liuShui = null; _this.drinkCup = null; _this.kaoPanGaiZi = []; _this.plateGaiZi = []; _this.cupGaiZi = []; _this.pDrinkBar = null; _this.m_shuiLiuTime = 3; _this.fullCup = null; _this.drinkCupList = []; _this.kaoPanNum = 2; _this.plateNum = 2; _this.cupNum = 3; _this.beefBornPos = [cc.v3(-290, -185, 0), cc.v3(-197, -195, 0), cc.v3(-243, -131, 0), cc.v3(-160, -133, 0)]; _this.platePos = [cc.v3(-58, -200, 0), cc.v3(80, -201, 0), cc.v3(-52, -126, 0), cc.v3(68, -131, 0)]; _this.burntPos = cc.v3(-360, -640, 0); _this.cupPos = [cc.v3(258, -209, 0), cc.v3(232, -161, 0), cc.v3(205, -115, 0)]; // ------------------------person--------------------------- _this.renwuPerfabList = []; _this.personList = []; // 点餐位置 _this.personPos = [cc.v3(30, 38, 0), cc.v3(260, 38, 0), cc.v3(-200, 38, 0)]; // 人物出生位置 _this.bornPos = [cc.v3(-500, 38, 0), cc.v3(550, 38, 0)]; _this.fixTime = 1; _this.passTime = 0; _this.personWalkTime = 2; _this.createpPersonNum = 0; //已经来了到少人 _this.fullPersonNum = 0; //多少吃饱了 _this.maxSitPersonNum = 3; //总共只能坐下人数 _this.kaoJiaoCount = 0; //合计烤焦了多少个? return _this; } Table_1 = Table; // LIFE-CYCLE CALLBACKS: Table.getInstance = function () { if (this._instance == null) { this._instance = new Table_1(); } return this._instance; }; Table.prototype.onLoad = function () { Table_1._instance = this; this.btnShengNiuPai.node.on(cc.Node.EventType.TOUCH_END, this.onClickShengNiuPai.bind(this), this); this.btnYellowSouce.node.on(cc.Node.EventType.TOUCH_END, this.onClickYellowSouce.bind(this), this); this.btnCocumber.node.on(cc.Node.EventType.TOUCH_END, this.onClickCocumber.bind(this), this); this.btnTomato.node.on(cc.Node.EventType.TOUCH_END, this.onClickTomato.bind(this), this); this.btnRedSouce.node.on(cc.Node.EventType.TOUCH_END, this.onClickRedSouce.bind(this), this); // this.drinksMachine.node.on(cc.Node.EventType.TOUCH_END, this.onClickDrinksMachine.bind(this), this); for (var i = 0; i < this.maxSitPersonNum; i++) { this.personList[i] = null; } this.plateNum = App_1.App.DataManager.kitchenNum[0][App_1.App.DataManager.kinchenLevel[0]]; this.kaoPanNum = App_1.App.DataManager.kitchenNum[1][App_1.App.DataManager.kinchenLevel[1]]; this.cupNum = App_1.App.DataManager.kitchenNum[2][App_1.App.DataManager.kinchenLevel[2]]; this.initAdForPage(); }; Table.prototype.initAdForPage = function () { if (cc.sys.os === cc.sys.OS_ANDROID) { var deviceId = ATAndroidJS2_1.default.getDeviceUserId(); console.log("zh:checkstatus:", ATRewardedVideoJSSDK_1.default.checkAdStatus(ATAndroidJS2_1.default.getPlacementId())); var setting = {}; setting[ATRewardedVideoJSSDK_1.default.userIdKey] = deviceId; ATRewardedVideoJSSDK_1.default.loadRewardedVideo(ATAndroidJS2_1.default.getPlacementId(), setting); } }; Table.prototype.start = function () { for (var i = 0; i < this.kaoPanNum - 2; i++) { this.kaoPanGaiZi[i].active = false; } for (var i = 0; i < this.plateNum - 2; i++) { this.plateGaiZi[i].active = true; } for (var i = 0; i < this.cupNum - 1; i++) { this.cupGaiZi[i].active = true; } if (App_1.App.DataManager.CurrentIntoLevel >= 3) { this.btnTomato.node.active = true; } if (App_1.App.DataManager.CurrentIntoLevel >= 5) { this.btnYellowSouce.node.active = true; } if (App_1.App.DataManager.CurrentIntoLevel >= 7) { this.btnRedSouce.node.active = true; } this.onClickDrinksMachine(); if (App_1.App.DataManager.guideStep == 0) { guidePanel_1.default.getInstance().showCurGuide(); } }; Table.prototype.onClickShengNiuPai = function () { if (App_1.App.DataManager.guideStep == 0) { App_1.App.DataManager.guideStep++; App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep); guidePanel_1.default.getInstance().hideGuideStep(); } for (var i = 0; i < this.kaoPanNum; i++) { if (this.rawSteakList[i] == null) { var beef = cc.instantiate(this.prefabBeef); beef.on(cc.Node.EventType.TOUCH_END, this.onClickRawBeef.bind(this, i), beef); beef.setPosition(this.beefBornPos[i]); this.node.addChild(beef); this.rawSteakList[i] = beef; break; } } }; Table.prototype.onClickRawBeef = function (index) { console.log('zh: 已经烤焦=' + this.kaoJiaoCount); if (this.rawSteakList[index].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Burnt) { console.log('zh: 已经烤焦了'); var c1 = this.kaoJiaoCount + 1; this.kaoJiaoCount = c1; // 每烤焦2次执行惩罚 if (c1 % 2 === 0) { // 当烤焦次数为2的倍数时执行惩罚 this.kaoJiaoCount = 0; // 重置计数器 console.log('zh: 需要惩罚'); if (cc.sys.os == cc.sys.OS_ANDROID) { if (ATRewardedVideoJSSDK_1.default.hasAdReady(ATAndroidJS2_1.default.getPlacementId())) { console.log('zh:AD ok!'); cc.director.pause(); console.log('zh: 游戏已暂停'); cc.sys.localStorage.setItem('yxAdMark', 'callBackFor_kaoJiao'); //看广告用于 xx 标记 cc.sys.localStorage.setItem('yxAdMark_index', index); //参数 GlobalManager_1.default.instance.registerMethod('callBackFor_kaoJiao', this.callBackFor_kaoJiao.bind(this)); ATRewardedVideoJSSDK_1.default.showAd(ATAndroidJS2_1.default.getPlacementId()); } else { console.log('zh:AD NO OK'); this.callBackFor_kaoJiao(index); this.initAdForPage(); return; } } else { console.log('zh: H5 直接奖励'); this.callBackFor_kaoJiao(index); return; } } else { this.callBackFor_kaoJiao(index); return; } // App.Facade.popView(TipPanelMediator, TipPanel, "The steak is burnt!", false); // cc.tween(this.rawSteakList[index]).to(0.5, {position: this.burntPos}).removeSelf().start() // this.rawSteakList[index] = null; return; } else if (this.rawSteakList[index].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Cooked) { for (var i = 0; i < this.plateNum; i++) { if (!this.cookedSteakList[i]) { this.rawSteakList[index].targetOff(this.rawSteakList[index]); // this.rawSteakList[index].off(cc.Node.EventType.TOUCH_END, this.onClickRawBeef.bind(this, index), this); this.cookedSteakList[i] = this.rawSteakList[index]; this.rawSteakList[index] = null; // 从烤架移动到盘子里面 this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.Plate); this.cookedSteakList[i].on(cc.Node.EventType.TOUCH_END, this.onClickCookedBeef.bind(this, i), this); cc.tween(this.cookedSteakList[i]).to(0.5, { position: this.platePos[i] }).start(); break; } } if (App_1.App.DataManager.guideStep == 1) { App_1.App.DataManager.guideStep++; App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep); guidePanel_1.default.getInstance().showCurGuide(); } } }; //烤焦了惩罚 Table.prototype.callBackFor_kaoJiao = function (index) { cc.director.resume(); console.log('zh: 游戏已恢复'); console.log('zh:callBackFor_kaoJiao 被触发 index = ' + index); App_1.App.Facade.popView(TipPanelMediator_1.default, TipPanel_1.default, "The steak is burnt!", false); cc.tween(this.rawSteakList[index]).to(0.5, { position: this.burntPos }).removeSelf().start(); this.rawSteakList[index] = null; return; }; // 点击熟牛排 Table.prototype.onClickCookedBeef = function (index) { if (App_1.App.DataManager.guideStep == 3) { App_1.App.DataManager.guideStep++; App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep); guidePanel_1.default.getInstance().showCurGuide(); } // todo 移动到人 // 移动到人之后,从数组里面删除 var toPos = this.findFoodPos(this.cookedSteakList[index].getComponent(Beef_1.default).m_foodType); if (toPos) { var pos = this.node.convertToNodeSpaceAR(toPos); cc.tween(this.cookedSteakList[index]).to(0.5, { position: pos, scale: 0.5 }).removeSelf().start(); this.cookedSteakList[index] = null; } }; Table.prototype.onClickYellowSouce = function () { for (var i = 0; i < this.cookedSteakList.length; i++) { if (this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Cocumber) { this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.YellowSouce); break; } } }; Table.prototype.onClickCocumber = function () { if (App_1.App.DataManager.guideStep == 2) { App_1.App.DataManager.guideStep++; App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep); guidePanel_1.default.getInstance().showCurGuide(); } for (var i = 0; i < this.cookedSteakList.length; i++) { if (this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Plate) { this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.Cocumber); break; } } }; Table.prototype.onClickTomato = function () { for (var i = 0; i < this.cookedSteakList.length; i++) { if (this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Plate) { this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.Tomato); break; } } }; Table.prototype.onClickRedSouce = function () { for (var i = 0; i < this.cookedSteakList.length; i++) { if (this.cookedSteakList[i] && this.cookedSteakList[i].getComponent(Beef_1.default).m_state == Beef_1.BeefState.Tomato) { this.cookedSteakList[i].getComponent(Beef_1.default).setState(Beef_1.BeefState.RedSouce); break; } } }; Table.prototype.onClickDrinksMachine = function () { var _this = this; this.pDrinkBar.node.active = true; this.liuShui.active = true; App_1.App.SpinManager.PlaySpinAnimation(this.liuShui, "newAnimation", true, null); App_1.App.SpinManager.PlaySpinAnimation(this.drinkCup, "newAnimation", false, null); this.pDrinkBar.progress = 0; cc.tween(this.pDrinkBar).to(this.m_shuiLiuTime, { progress: 1 }).call(function () { _this.pDrinkBar.node.active = false; _this.liuShui.active = false; _this.drinkCup.getComponent(sp.Skeleton).animation = null; for (var i = 0; i < _this.cupNum; i++) { if (!_this.drinkCupList[i]) { var cup = cc.instantiate(_this.fullCup); cup.setPosition(_this.drinkCup.getPosition()); _this.node.addChild(cup); cup.zIndex = _this.cupNum - i; _this.drinkCupList[i] = cup; cup.on(cc.Node.EventType.TOUCH_END, _this.onClickFullCup.bind(_this, i), _this); if (i == 0) { cc.tween(cup).to(0.5, { position: _this.cupPos[0] }).start(); } else { cc.tween(cup).to(0.5, { position: _this.cupPos[0] }).to(0.2, { position: _this.cupPos[i] }).start(); } } } }).start(); }; // 点击饮料 Table.prototype.onClickFullCup = function (index) { // todo 移动到人 if (App_1.App.DataManager.guideStep == 4) { App_1.App.DataManager.guideStep++; App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.str_guideStep, App_1.App.DataManager.guideStep); guidePanel_1.default.getInstance().hideGuideStep(); } // 移动到人之后,从数组里面删除 var toPos = this.findFoodPos(Beef_1.FoodType.Drink); if (toPos) { var pos = this.node.convertToNodeSpaceAR(toPos); cc.tween(this.drinkCupList[index]).to(0.3, { position: pos, scale: 0.5 }).removeSelf().start(); this.drinkCupList[index] = null; // this.m_machineState = DrinksMachineState.None; this.onClickDrinksMachine(); } }; Table.prototype.onDisable = function () { this.btnShengNiuPai.node.off(cc.Node.EventType.TOUCH_END, this.onClickShengNiuPai.bind(this), this); this.btnYellowSouce.node.off(cc.Node.EventType.TOUCH_END, this.onClickYellowSouce.bind(this), this); this.btnCocumber.node.off(cc.Node.EventType.TOUCH_END, this.onClickCocumber.bind(this), this); this.btnTomato.node.off(cc.Node.EventType.TOUCH_END, this.onClickTomato.bind(this), this); this.btnRedSouce.node.off(cc.Node.EventType.TOUCH_END, this.onClickRedSouce.bind(this), this); }; // 找到点这个食物剩余时间最少的人 Table.prototype.findFoodPos = function (foodt) { var curPerson = null; var personIndex = -1; var lessLeftTime = 100; for (var i = 0; i < this.maxSitPersonNum; i++) { if (this.personList[i] && this.personList[i].getComponent(Person_1.default).m_state == Person_1.PersonState.Waite) { // 点餐种类 var fTypelist = this.personList[i].getComponent(Person_1.default).foodTypeList; var time = this.personList[i].getComponent(Person_1.default).leftTime; for (var j = 0; j < fTypelist.length; j++) { if (foodt == fTypelist[j] && lessLeftTime > time) { lessLeftTime = time; personIndex = i; curPerson = this.personList[i]; } } } } if (curPerson) { var worldPos = curPerson.getComponent(Person_1.default).getFoodWorldPos(foodt); if (curPerson.getComponent(Person_1.default).judgeFoodFull()) { this.fullPersonNum++; var smallLevel = App_1.App.DataManager.PassProgress[App_1.App.DataManager.CurrentIntoLevel]; if (this.fullPersonNum == App_1.App.DataManager.personCount[App_1.App.DataManager.CurrentIntoLevel - 1][smallLevel - 1]) { // GameSuccess this.personList[personIndex] = null; var rand_1 = Math.round(Math.random()); cc.tween(curPerson).delay(0.6).call(function () { curPerson.getComponent(Person_1.default).setState(Person_1.PersonState.FullOut); if (rand_1 == 1) { curPerson.getChildByName("renwu").scaleX = -0.5; } }).to(this.personWalkTime, { position: this.bornPos[rand_1] }).call(function () { curPerson.removeFromParent(); }).start(); gameScene_1.default.instance.GameSuccess(); } else { var rand_2 = Math.round(Math.random()); this.personList[personIndex] = null; cc.tween(curPerson).delay(0.6).call(function () { curPerson.getComponent(Person_1.default).setState(Person_1.PersonState.FullOut); if (rand_2 == 1) { curPerson.getChildByName("renwu").scaleX = -0.5; } }).to(this.personWalkTime, { position: this.bornPos[rand_2] }).call(function () { curPerson.removeFromParent(); }).start(); } } return worldPos; } return null; }; Table.prototype.update = function (dt) { if (!gameScene_1.default.instance.GameStutas) return; this.passTime += dt; var smallLevel = App_1.App.DataManager.PassProgress[App_1.App.DataManager.CurrentIntoLevel]; if (this.passTime >= this.fixTime && this.createpPersonNum < App_1.App.DataManager.personCount[App_1.App.DataManager.CurrentIntoLevel - 1][smallLevel - 1]) { this.passTime = 0; this.fixTime = 1; console.log("aaa-------randomIndex---------", smallLevel); var _loop_1 = function (i) { if (!this_1.personList[i]) { var randomIndex = Math.floor(Math.random() * this_1.renwuPerfabList.length); var person_1 = cc.instantiate(this_1.renwuPerfabList[randomIndex]); person_1.getComponent(Person_1.default).setState(Person_1.PersonState.Comming); person_1.zIndex = -1; this_1.node.addChild(person_1); this_1.personList[i] = person_1; var rand = Math.round(Math.random()); person_1.setPosition(this_1.bornPos[rand]); if (rand == 0) { person_1.getChildByName("renwu").scaleX = -0.5; } App_1.App.SpinManager.PlaySpinAnimation(person_1.getChildByName("renwu"), "newAnimation", true); cc.tween(person_1).to(this_1.personWalkTime, { position: this_1.personPos[i] }).call(function () { person_1.getChildByName("renwu").scaleX = 0.5; person_1.getComponent(Person_1.default).setState(Person_1.PersonState.Waite); }).start(); this_1.createpPersonNum++; var smallLevel_1 = App_1.App.DataManager.PassProgress[App_1.App.DataManager.CurrentIntoLevel]; gameScene_1.default.instance.updateLeftPeople(App_1.App.DataManager.personCount[App_1.App.DataManager.CurrentIntoLevel - 1][smallLevel_1 - 1] - this_1.createpPersonNum); return "break"; } }; var this_1 = this; for (var i = 0; i < this.maxSitPersonNum; i++) { var state_1 = _loop_1(i); if (state_1 === "break") break; } } }; var Table_1; Table._instance = null; __decorate([ property(cc.Button) ], Table.prototype, "btnShengNiuPai", void 0); __decorate([ property(cc.Prefab) ], Table.prototype, "prefabBeef", void 0); __decorate([ property(cc.Button) ], Table.prototype, "btnYellowSouce", void 0); __decorate([ property(cc.Button) ], Table.prototype, "btnCocumber", void 0); __decorate([ property(cc.Button) ], Table.prototype, "btnTomato", void 0); __decorate([ property(cc.Button) ], Table.prototype, "btnRedSouce", void 0); __decorate([ property(cc.Node) ], Table.prototype, "liuShui", void 0); __decorate([ property(cc.Node) ], Table.prototype, "drinkCup", void 0); __decorate([ property([cc.Node]) ], Table.prototype, "kaoPanGaiZi", void 0); __decorate([ property([cc.Node]) ], Table.prototype, "plateGaiZi", void 0); __decorate([ property([cc.Node]) ], Table.prototype, "cupGaiZi", void 0); __decorate([ property(cc.ProgressBar) ], Table.prototype, "pDrinkBar", void 0); __decorate([ property(cc.Prefab) ], Table.prototype, "fullCup", void 0); __decorate([ property([cc.Prefab]) ], Table.prototype, "renwuPerfabList", void 0); Table = Table_1 = __decorate([ ccclass ], Table); return Table; }(cc.Component)); exports.default = Table; cc._RF.pop();