/** 可生产物品item */ import { BitmapFontC } from "../../../game/component/BitmapFontC"; import { GameProp, ProductType } from "../../../game/data/GameData"; const { ccclass, property } = cc._decorator; @ccclass export default class PlantItem extends cc.Component { @property({ type: cc.Node, tooltip: "布局" }) mainNode: cc.Node = null; @property({ type: cc.Node, tooltip: "未解锁" }) lockNode: cc.Node = null; @property({ type: cc.Sprite, tooltip: "作物图标" }) plantIcon: cc.Sprite = null; @property({ type: cc.Sprite, tooltip: "名字图标" }) nameIcon: cc.Sprite = null; @property({ type: BitmapFontC, tooltip: "获得数量文本" }) awardLabel: BitmapFontC = null; @property({ type: BitmapFontC, tooltip: "成熟时间文本" }) timeLabel: BitmapFontC = null; @property({ type: cc.Label, tooltip: "未开条件" }) labUnlock: cc.Label = null; @property({ type: cc.Label, tooltip: '进度文本' }) lbl_progress: cc.Label = null; @property({ type: cc.Node, tooltip: '订单' }) node_dingdan: cc.Node = null; @property({ type: cc.Node }) node_plant: cc.Node = null; @property({ type: cc.Node }) node_product: cc.Node = null; private data = null; /** * list_data * @param list_data 数据列表 */ public async setItemData(list_data) { await this.initItem(list_data); } update() { if (gData.plantData.init_itemIndex == this.data.picture) { this.initItem(this.data); gData.plantData.init_itemIndex = -1; } if (gData.plantData.init_lock == this.data.picture) { this.initItem(this.data); gData.plantData.init_lock = -1; } } /** * 数据分发 * @param list_data 数据列表 */ private async initItem(list_data) { this.data = list_data; let plantPath = ''; let namePath = ''; if (this.data.tab == ProductType.nzw) { plantPath = 'game/coregame/texture/plant_icons/plantIcon_'; namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_'; this.node_plant.active = true; this.node_product.active = false; } else { plantPath = 'game/coregame/texture/factory_icons/factory_'; namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_'; this.node_plant.active = false; this.node_product.active = true; } this.plantIcon.spriteFrame = await mk.loader.load(plantPath + list_data.picture, cc.SpriteFrame); this.nameIcon.spriteFrame = await mk.loader.load(namePath + list_data.picture, cc.SpriteFrame); this.awardLabel.string = (list_data.menuRedBagCoin / 100).toString(); this.timeLabel.string = list_data.time; let unlock = false; let times = 0; //根据上个商品种植次数 if (list_data.unlock == 1) { unlock = gData.gameData.getProductUnlockById(this.data.tab, this.data.picture); if (!unlock) { times = gData.gameData.getProductMakeTimesById(list_data.picture - 1); if (times >= list_data.value) { unlock = true; } } } //根据农场等级 else if (list_data.unlock == 2) { if (gData.gameData.playerProp.orderData && gData.gameData.playerProp.orderData.overTimes >= list_data.value) { unlock = true; } } if (unlock) { this.checkOrder(); } else { this.node_dingdan.active = false; } this.mainNode.active = unlock; this.lockNode.active = !unlock; if (!unlock) { let des = this.getDesByType(); let plantName = gData.gameData.getProductMap(this.data.picture - 1).name; if (list_data.picture - 1 == gData.gameData.getMaxProductExtra(this.data.tab)) { this.labUnlock.string = `${des}${this.data.value}次\n${plantName}`; this.lbl_progress.string = `${times}/${this.data.value}`; this.labUnlock.node.active = true; } else { this.labUnlock.node.active = false; } } } checkOrder() { let data = gData.gameData.playerProp.orderData; let isDingdan = false; if (data) { let len = data.orderTaskList.length; let orderPlantTimes = gData.gameData.getProp(GameProp.orderPlantTimes); if (!orderPlantTimes) { orderPlantTimes = {}; } gData.gameData.setProp(GameProp.orderPlantTimes, orderPlantTimes); if (orderPlantTimes[this.data.id] == undefined) { orderPlantTimes[this.data.id] = 0; } for (var i = 0; i < len; i++) { // if (data.orderTaskList[i].Id == this.data.id && orderPlantTimes[data.orderTaskList[i].Id] < data.orderTaskList[i].taskCount) { // isDingdan = true; // break; // } if (data.orderTaskList[i].Id == this.data.id) { console.log("===[订单id",data.orderTaskList[i].Id,this.data.id) console.log("===[订单id 种植次数",orderPlantTimes[data.orderTaskList[i].Id],data.orderTaskList[i].taskCount) if (orderPlantTimes[data.orderTaskList[i].Id] < data.orderTaskList[i].taskCount) { isDingdan = true; break; } } } } this.node_dingdan.active = isDingdan; } showTips() { mk.tip.pop("生产次数+5"); } async clickMake() { mk.audio.playEffect('button'); mk.guide.next(); // if (gData.gameData.leftTimes <= 0) { // gData.gameData.popTipCallBack = this.showTips; // mk.ui.openPanel('module/speedUpUI/productReward'); // return; // } if (gData.gameData.isProducting) { //mk.tip.pop('点击太快了'); return; } let flyRed; if (this.data.tab == ProductType.nzw) { flyRed = await gData.farmSystem.plant(this.data.picture, this.nameIcon.node); // gData.gameData.nextMake = null; // gData.gameData.setNextProduct(false); // if (gData.gameData.playerProp.gradeLevel < 2) { // mk.tip.pop('生产次数+1'); // } } else { flyRed = await gData.factorySystem.make(this.data.picture, this.nameIcon.node); } console.log("===[种植订单 flyRed",flyRed); if (flyRed) { let orderPlantTimes = gData.gameData.getProp(GameProp.orderPlantTimes); if (orderPlantTimes[this.data.id] == undefined) { orderPlantTimes[this.data.id] = 1; } else { orderPlantTimes[this.data.id]++; } gData.gameData.setProp(GameProp.orderPlantTimes, orderPlantTimes); this.checkOrder(); mk.data.sendDataEvent('Plant', this.data.name); let plantTimes = gData.gameData.getProp(GameProp.plantTimes); if (plantTimes == undefined) { plantTimes = 0; } plantTimes++; gData.gameData.setProp(GameProp.plantTimes, plantTimes); if (gData.gameData.showRichBankIconLimit == plantTimes && gData.gameData.funOpenData[13] == "1") { mk.event.emit("showRichBankIcon"); } //飞红包开关 if (gData.gameData.funOpenData[4] == "0") { return; } gData.plantData.init_ani = true; let pos = this.nameIcon.node.parent.convertToWorldSpaceAR(this.nameIcon.node.getPosition()); gData.gameData.gameStyle.dpFlyRedAni(pos); } } getDesByType() { let des = '' switch (this.data.tab) { case '农作物': des = '种植'; break; case '动物': des = '养殖'; break; case '爆米花厂': case '糕点铺': case '制糖厂': case '炼乳厂': case '功夫面馆': case '快餐店': des = '制作'; break; } return des; } }