/** 商店Item */ import GameM, { AUDIO_TYPE } from "../manager/GameM"; import UiM, { PANEL_NAME } from "../manager/UiM"; import Main from "../Main"; import Sciencen_M from "../utils/Sciencen_M"; import Shop from "../ui/Shop"; import EffectNode from "../ui/EffectNode"; import LocalManagerData from "../datas/LocalManagerData"; import ShopData from "../datas/ShopData"; const { ccclass, property } = cc._decorator; @ccclass export default class ShopItem extends cc.Component { @property(cc.Button) btnShopBuy: cc.Button = null; @property(cc.Node) lock: cc.Node = null; @property(cc.Node) free: cc.Node = null; @property(cc.Node) price: cc.Node = null; @property(cc.Node) iconCarEmpty: cc.Node = null; @property(cc.Node) car: cc.Node = null; @property(cc.Label) labLevel: cc.Label = null; @property(cc.Label) labPrice: cc.Label = null; @property(cc.Node) iconGold: cc.Node = null; @property(cc.Node) iconMoney: cc.Node = null; @property(cc.Label) label_lockTip: cc.Label = null; @property(cc.Node) desNode: cc.Node = null; @property(cc.Label) labCircle: cc.Label = null; @property(cc.Label) labLeftTimes: cc.Label = null; //类型 type = 0 //当前车价格 curPrice = '0' normalPrice = '0' percent = 0 resetTimes = 0 start() { } init(type) { this.type = type cc.loader.loadRes('carPic/head/head_' + this.type.toString(), cc.SpriteFrame, (err, assets) => { if (err) { cc.error(err); return; } this.car.getComponent(cc.Sprite).spriteFrame = assets }) this.labLevel.string = this.type.toString() this.refreshPrice(true) } updateLeftTimes() { let times = LocalManagerData.Instance.getBuyCarData(this.type) let maxbuycarnum = GameM.commonData.globalCfg.maxbuycarnum if (maxbuycarnum == null || maxbuycarnum == undefined) { maxbuycarnum = 0 } if (maxbuycarnum == 0) { this.labLeftTimes.string = "" return } let leftTimes = maxbuycarnum - times if (leftTimes < 0) { leftTimes = 0 } this.labLeftTimes.string = "购买次数:" + leftTimes } refreshPrice(init = false) { let max = Math.max(GameM.commonData.maxCarLevel - 6, 4); this.labLeftTimes.string = "" if (this.type <= max) { this.iconCarEmpty.active = false this.desNode.active = true this.btnShopBuy.interactable = true this.desNode.active = true this.curPrice = GameM.commonData.getPriceByType(this.type) this.labCircle.node.active = true this.labCircle.string = Sciencen_M.instance.format(GameM.commonData.getFristPriceByType(this.type), false) this.iconMoney.active = false this.iconGold.active = true this.labPrice.string = Sciencen_M.instance.format(this.curPrice) if (!this.car.active) { cc.loader.loadRes('carPic/head/head_' + this.type.toString(), cc.SpriteFrame, (err, assets) => { if (err) { cc.error(err); return; } this.car.getComponent(cc.Sprite).spriteFrame = assets this.car.active = true }) } this.price.active = true this.free.active = false this.updateLeftTimes() } else if (this.type <= max + 2) { if (!GameM.commonData.redSwitch) { this.iconCarEmpty.active = false this.desNode.active = true this.btnShopBuy.interactable = true this.labCircle.node.active = true this.labCircle.string = Sciencen_M.instance.format(GameM.commonData.getFristPriceByType(this.type), false) this.lock.active = false this.free.active = false this.curPrice = GameM.commonData.getMoneyPriceBuyType(this.type) this.iconMoney.active = true this.iconGold.active = false this.labPrice.string = Sciencen_M.instance.format(this.curPrice) if (!this.car.active) { cc.loader.loadRes('carPic/head/head_' + this.type.toString(), cc.SpriteFrame, (err, assets) => { if (err) { cc.error(err); return; } this.car.getComponent(cc.Sprite).spriteFrame = assets this.car.active = true }) } this.price.active = true this.updateLeftTimes() } else { this.labCircle.node.active = false this.iconCarEmpty.active = true this.desNode.active = false this.car.active = false this.btnShopBuy.interactable = false this.price.active = false this.free.active = false this.lock.active = true this.label_lockTip.string = `${this.type + 6}级武将解锁`; cc.loader.loadRes('carPic/head/head_' + this.type.toString(), cc.SpriteFrame, (err, assets) => { if (err) { cc.error(err); return; } this.iconCarEmpty.getComponent(cc.Sprite).spriteFrame = assets }) } } else { this.labCircle.node.active = false this.iconCarEmpty.active = true this.desNode.active = false this.car.active = false this.btnShopBuy.interactable = false this.price.active = false this.free.active = false this.lock.active = true } } /** 点击购买 */ clickBuyCar() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (GameM.commonData.roleData.shop == 0) { ShopData.Instance.shopGuideTimes++ if (ShopData.Instance.shopGuideTimes >= 2) { ShopData.Instance.updateShop() UiM.Instance.shopNode.getComponent(Shop).hideGuide() let main = UiM.Instance.hallNode.getComponent(Main) main.hideAllHand() main.CheckNormalGuide() } } let times = LocalManagerData.Instance.getBuyCarData(this.type) let maxbuycarnum = GameM.commonData.globalCfg.maxbuycarnum if (maxbuycarnum == null || maxbuycarnum == undefined) { maxbuycarnum = 0 } if (maxbuycarnum != 0) { if (times >= maxbuycarnum) { EffectNode.instance.PlayTip('今日次数用尽,可降伏其他武将') return } } UiM.Instance.hallNode.getComponent(Main).onBuyTypeCar(this.type, 0) } }