| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- import { DataEventId, ExpAddType, FactroyState, GameProp, ProductType } from "../../game/data/GameData";
- import { MoveToCenter } from "../map/MoveToCenter";
- import ProductShow from "../view/ProductShow";
- import { FarmCountDown } from "./FarmCountDown";
- import { IDHelper } from "./IDHelper";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export class FactoryIcon extends cc.Component {
- @property({ type: FarmCountDown, tooltip: "倒计时组件" }) countDown: FarmCountDown = null;
- @property({ type: cc.Node, tooltip: "完成品展示节点" }) showGroup: cc.Node = null;
- @property({ type: cc.Node, tooltip: '闲置动画' }) idleAni: cc.Node = null;
- public configID: number = 0;
- public sortID: number = 0;
- public tab: ProductType = ProductType.bmhc;
- private _state: FactroyState = -1;
- public get state(): FactroyState { return this._state; }
- data = null;
- onLoad() {
- let helper = this.getComponent(IDHelper);
- this.configID = helper.buildID;
- this.sortID = helper.sortID;
- this.tab = gData.gameData.getTabByConfigID(this.configID);
- this.countDown.node.active = false;
- this.freshState();
- gData.factorySystem.addFactory(this);
- }
- update() {
- let index = gData.gameData.needFreshArr.indexOf(this.configID);
- if (index != -1) {
- this.freshState();
- gData.gameData.needFreshArr.splice(index, 1);
- }
- }
- freshState() {
- this.data = gData.gameData.getFactoryDataMap(this.configID);
- this.setState(this.data.state);
- }
- private setState(value: FactroyState): void {
- if (this.state != value) {
- this._state = value;
- this.countDown.node.active = false;
- switch (this.state) {
- case FactroyState.Lock:
- break;
- case FactroyState.Empty:
- if (this.idleAni && this.idleAni.active == false) {
- this.idleAni.active = true;
- }
- break;
- case FactroyState.Producting:
- this.countDown.node.active = true;
- this.countDown.setData(this.data);
- if (this.idleAni && this.idleAni.active == true) {
- this.idleAni.active = false;
- }
- break;
- case FactroyState.Ripe:
- this.countDown.node.active = true;
- this.countDown.setState(1);
- this.onProductComplete();
- break;
- case FactroyState.Sick:
- this.countDown.node.active = true;
- this.countDown.setState(0);
- break;
- }
- }
- }
- /**生产完成 */
- private async onProductComplete() {
- if (this.showGroup) {
- let prefab = await mk.loader.load("game/prefab/ProductShow", cc.Prefab);
- let item = cc.instantiate(prefab);
- let id = this.data.productID;
- item.getComponent(ProductShow).id = id;
- item.parent = this.showGroup;
- }
- }
- private clean(): void {
- this.showGroup.removeAllChildren();
- }
- public async onTouch() {
- switch (this.data.state) {
- case FactroyState.Lock:
- let arr = gData.gameData.getProductArrByType(this.tab);
- let lv = arr[0].value - gData.gameData.playerProp.completeFarmTaskTimes;
- mk.tip.pop(`完成${lv}次任务红包后解锁`);
- break;
- case FactroyState.Empty:
- gData.factorySystem.currSelectFactory = this;
- gData.plantData.openPanel(this.tab, this.configID);
- break;
- case FactroyState.Producting:
- mk.ui.openPanel('module/speedUpUI/speedUp');
- break;
- case FactroyState.Ripe:
- gData.factorySystem.currSelectFactory = this;
- gData.harvestData.openPanel(this.configID, this.data.productID, this.onHarvest.bind(this), this.node);
- break;
- case FactroyState.Sick:
- // mk.tip.pop(`生虫了!`);
- mk.data.sendDataEvent(DataEventId.button_click, "停电icon");
- gData.adClearSickData.openPanel(this.tab, this.configID);
- mk.console.logSingle('VVVV ', '停电icon');
- break;
- }
- }
- public async make(id) {
- if (this.data.state == FactroyState.Empty) {
- gData.gameData.isProducting = true;
- let config = gData.gameData.getProductMap(id);
- let growSpan = Date.now() + config.time * 1000;
- this.data.state = FactroyState.Producting;
- this.data.productID = config.picture;
- this.data.growSpan = growSpan;
- gData.gameData.setFactoryDataMap(this.configID, this.data);
- this.getComponent(MoveToCenter).move();
- gData.gameData.changeLeftTimes(-1);
- gData.adData.checkPopRed();
- gData.gameData.addProductMakeTimesById(this.data.productID);
- gData.gameData.isProducting = false;
- gData.gameData.updateOrderTaskCopyData(this.data.productID);
- gData.gameData.nextMake = null;
- gData.gameData.setNextProduct(false);
- let flyRed = await gData.gameData.updateNewTaskProgress();
- return flyRed;
- // if (flyRed) {
- // //mk.audio.playEffect('redmoney');
- // gData.gameData.gameStyle.dpFlyRedAni();
- // }
- }
- else {
- mk.tip.pop('商品已满!')
- return false;
- }
- }
- clickSpeedUp() {
- mk.ui.openPanel('module/speedUpUI/speedUp');
- }
- onRipe(sendToServer) {
- this.data.state = FactroyState.Ripe;
- gData.gameData.setFactoryDataMap(this.configID, this.data, sendToServer);
- //gData.gameData.addProductMakeTimesById(this.data.productID);
- }
- onSick(sendToServer) {
- this.data.state = FactroyState.Sick;
- gData.gameData.setFactoryDataMap(this.configID, this.data, sendToServer);
- }
- public async onHarvest(){
- this.countDown.cleanRiped();
- this.clean();
- gData.factorySystem.currSelectFactory = null;
- let productID = this.data.productID;
- this.data.state = FactroyState.Empty;
- this.data.productID = 0;
- this.data.growSpan = 0;
- gData.gameData.setFactoryDataMap(this.configID, this.data);
- await gData.gameData.gameStyle.doCropFlyLogic(productID, this.node);
- gData.gameData.nextMake = null;
- gData.gameData.setNextProduct(false);
- if (gData.harvestData.getType == 0) {
- gData.farmGradeData.addGradeExp(ExpAddType.EAT_harvest, this.node);
- }
- else {
- gData.farmGradeData.addGradeExp(ExpAddType.EAT_others, this.node);
- }
- }
- public canHarvest() {
- this.getComponent(MoveToCenter).move();
- gData.factorySystem.currSelectFactory = this;
- gData.harvestData.openPanel(this.configID, this.data.productID, this.onHarvest.bind(this), this.node, true);
- }
- public canClearSick() {
- this.getComponent(MoveToCenter).move();
- mk.data.sendDataEvent(DataEventId.button_click, "停电icon");
- gData.adClearSickData.openPanel(this.tab, this.configID);
- }
- }
|