const SkillApi = require('../net/SkillApi'); const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const GameModule = require("../utils/GameModule"); cc.Class({ extends: cc.Component, properties: { skillNameRichText: cc.RichText, // 262424 desc1RichText: cc.RichText, // #FD4700 desc2RichText: cc.RichText, buyButton: cc.Button, buySprite: cc.Sprite, buyRichText: cc.RichText, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, /// 上一级和下一级的技能信息 init(skillInfo, nextSkillInfo, starItem) { this._skillId = skillInfo.skillId; this._starItem = starItem; let diamondCount = skillInfo.bonus[10002]; /// 用的砖石 if (diamondCount != undefined) { this.diamondCount = diamondCount; this.coinCount = {'n': 0, 'e': 0}; this.building = 0; this.buyRichText.string = `升级
${diamondCount}钻石`; } this.desc1RichText.string = `立即获得\n${skillInfo.desc}`; this.desc2RichText.string = `立即获得\n${nextSkillInfo.desc}`; this.skillNameRichText.string = `${skillInfo.name}`; }, start () { }, buyAction() { this.buyButton.interactable = false; GameModule.audioMng.playClickButton(); this.upSkill(this._skillId).then(() => { this.buyButton.interactable = true; this._starItem.skillData.skillLevel += 1; this._starItem.updateGloabData(); GameEvent.fire('skill_update'); if (this._skillId <= 3) { } else { /// 如果升级永久技能 let skillLevelInfo = Global.BuildingManager.getSkillLevelInfo(this._skillId, this._starItem.skillData.skillLevel); GameEvent.fire(GameNotificationKey.UpdateFixationSkill, skillLevelInfo); if (this._skillId == 5) { GameEvent.fire("skill_five_use"); /// 使用最后一个减cd的 } else if (this._skillId == 6) { Global.rcdSkillLevel += 1; GameEvent.fire("skill_six_use"); } } this.node.destroy(); console.log("升级技能成功"); }).catch(({code, msg}) => { console.log(code, msg); Global.commonAlert.showCommonErrorAlert(msg); this.buyButton.interactable = true; }); }, closeAction() { GameModule.audioMng.playClickButton(); this.node.destroy(); }, upSkill(skillId) { return new Promise((resolve, reject) => { // 获取目标用户的建筑 SkillApi.upSkill(skillId, (respondData) => { resolve(respondData); }, (code, msg) => { reject({code, msg}); }); }); }, // update (dt) {}, });