123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- const SkillApi = require('../net/SkillApi');
- const DWTool = require("../utils/DWTool");
- const GameModule = require("../utils/GameModule");
- const buildingLevel = require('../data/buildingLevel');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const TapTapTool = require("../utils/TapTapTool");
- const AlertManager = require('../utils/AlertManager');
- const GameRedDot = require('../utils/GameEnum').GameRedDot;
- var Promise = require('../lib/es6-promise').Promise;
- cc.Class({
- extends: cc.Component,
- properties: {
- userSkillButton: {
- tooltip: '使用技能button',
- default: null,
- type: cc.Button
- },
-
- titleRichText: {
- tooltip: 'title啦',
- default: null,
- type: cc.RichText
- },
- skillIconBg: {
- tooltip: '技能icon的背景',
- default: null,
- type: cc.Sprite
- },
- ///使用技能的按钮背景图片
- useSkillButtonBgSprite: cc.Sprite,
- /// 使用技能的text
- skillUseTitleRichText: cc.RichText,
- /// 描述text
- subTitleRichText: cc.RichText,
- ///技能icon
- skillIcon: cc.Sprite,
- ///总部大楼特有,等级 / 25
- fillBuldingNode: cc.Node,
- fillBuldingSprite: cc.Sprite,
- lightSpriteFrame: cc.SpriteFrame,
- graySpriteFrame: cc.SpriteFrame,
- /// 里程碑奖励显示的button
- awardButton: cc.Button,
- /// 升级技能的弹窗
- alertNode: cc.Node,
- ///砖石数
- diamondCount: 0,
- /// 金币数
- coinCount: 0,
- building: 0,
- _awardCount: 0,
- _isAlert: false,
- },
- // onLoad () {
- // },
- start () {
- this._isAction = false;
- },
- onDestroy() {
- GameEvent.off("skill3_use_begain", this);
- GameEvent.off(GameNotificationKey.SkillThreeHasDone, this);
- GameEvent.off("skill_five_use", this);
- GameEvent.off(GameNotificationKey.UpBuildingLevel, this);
- },
- update (dt) {
- /// 如果说是建筑 并且没有钱升级的状态
- if (this.fillBuldingNode.active) {
- ///如果能够使用了,那么继续能用
- let isCanUse = this.judgeIsCanUse();
- let inter = this.userSkillButton.interactable;
- if (isCanUse != inter && this._isAction == false) {
- this.setupGrayBg(!inter);
- }
- }
- },
- /// 初始化第一个建筑相关的数据
- initBuilding(awardCount) {
- this.initAward(awardCount)
- this.userSkillButton.interactable = false;
- this.updateBuildingData();
- /// 第三个技能开始使用
- GameEvent.on("skill3_use_begain", this, () => {
- this.updateBuildingData();
- });
- /// 第三个技能结束
- GameEvent.on(GameNotificationKey.SkillThreeHasDone, this, () => {
- this.updateBuildingData();
- });
- ////第五个技能开始使用
- GameEvent.on("skill_five_use", this, () => {
- this.updateBuildingData();
- });
- GameModule.homeGuide.on('Fire_state16', this.awardBtnAction, this);
-
- // let buildingLevelInfo = buildingLevel[buildingInfo.buildingLevel - 1];
- },
- //// 初始化技能数据
- init(skillData) {
- this.fillBuldingNode.active = false;
- this.awardButton.node.active = false;
- this.loadSpriteFrame(skillData);
- this.skillData = skillData;
- this.updateData();
- this.setupMaxLevel();
- /// 更新技能相关
- GameEvent.on('skill_update', this, () => {
- this.updateData();
- this.setupMaxLevel();
- });
- },
- /// 初始化领取里程碑奖励数据
- initAward(awardCount) {
- this._awardCount = awardCount;
- let needAwardCount = parseInt(GameModule.userInfo.buildingLevel / 25);
- if (needAwardCount > this._awardCount) {
- this.awardButton.node.active = true;
- } else {
- this.awardButton.node.active = false;
- }
- },
- /// 更新建筑相关数据
- updateBuildingData() {
- let currentLevel = GameModule.userInfo.buildingLevel;
- let upGet = GameModule.userInfo.perpetualClickMt;
- this._upGet = upGet;
- if (currentLevel <= 25) {
- let buildingObj = buildingLevel.find(n => {
- return n.level == currentLevel;
- });
- this._upGold = {'n': buildingObj.upGold, 'e': 0};
- } else {
- let mul = TapTapTool.toPower(currentLevel - 26);
- this._upGold = TapTapTool.multiple({'n': 1056, 'e': 0}, mul);
- }
- this.skillUseTitleRichText.string = '<color=#ffffff>+' + TapTapTool.parseToString(upGet) + '收益</c>' + `<br/><img src='coin_small'/><color=#ffffff>${TapTapTool.parseToString(this._upGold)}</c>`;
- this.fillBuldingNode.active = true;
- this.fillBuldingSprite.fillRange = (currentLevel % 25) / 25;
- this.diamondCount = 0;
- this.coinCount = this._upGold;
- this.building = 0;
- this.titleRichText.string = '<color=#df5400>等级' + currentLevel + '</c>' + '<color=#1c1c1c>' + ' 总部大楼' + '</c>';
- this.subTitleRichText.string = `<img src='skill_click_coin'/><color=#df5400> ${TapTapTool.parseToString(GameModule.userInfo.coinTap)}收益</c><color=#1c1c1c>/点击</c>`;
- },
- /// 更新技能相关数据
- updateData() {
- let levelInfo = GameGlobal.BuildingManager.getSkillLevelInfo(this.skillData.skillId, this.skillData.skillLevel);
- let skillInfo = GameGlobal.BuildingManager.getSkillInfo(this.skillData.skillId);
- this._skillInfo = skillInfo;
- //// 如果是没有拥有的
- if (this.skillData.isHave == 0) {
- /// 说明是用其它的来解锁
- if (skillInfo.buildingLevel == 0) {
- /// 用的砖石 技能4是用砖石或者金币来解锁的
- this.showBuySkill();
- } else {
- /// 说明总部等级不够,还没有解锁
- if (GameModule.userInfo.buildingLevel < skillInfo.buildingLevel) {
- this.coinCount = {'n': 0, 'e': 0};
- this.diamondCount = 0;
- this.building = skillInfo.buildingLevel;
- this.skillUseTitleRichText.string = "<img src='skill_lock'/><br/><color=#ffffff>总部大楼等级" + skillInfo.buildingLevel + '</c>';
- //// 如果是因为建筑锁住的
- this._upNoticefacation = false;
- GameEvent.on(GameNotificationKey.UpBuildingLevel, this, () => {
- if (!this._upNoticefacation && GameModule.userInfo.buildingLevel >= this.building && this.skillData.isHave == 0) {
- /// 实时技能直接拥有
- this._upNoticefacation = true;
- if (this.skillData.skillId < 4) {
- /// 直接解锁它
- this.unlockedSkill();
- } else {
- this.showBuySkill();
- this.setupGrayBg(this.judgeIsCanUse());
- }
- }
- });
- /// 那就需要去购买了
- } else {
- this.showBuySkill();
- }
- }
- } else {
- this.userSkillButton.interactable = true;
- let diamondCount = levelInfo.bonus[10002];
- /// 用的砖石
- if (diamondCount != undefined) {
- this.diamondCount = diamondCount;
- this.coinCount = {'n': 0, 'e': 0};
- this.building = 0;
- this.skillUseTitleRichText.string = `<color=#ffffff>升级</c><br/><img src='skill_diamond'/><color=#ffffff>${diamondCount}钻石</c>`;
- }
- }
- this.setupGrayBg(this.judgeIsCanUse());
- if (this.skillData.skillLevel > 0) {
- this.titleRichText.string = '<color=#df5400>等级' + + this.skillData.skillLevel + ' </c>' + '<color=#1c1c1c>' + skillInfo.name + '</c>';
- } else {
- this.titleRichText.string = '<color=#df5400>技能' + ' </c>' + '<color=#1c1c1c>' + skillInfo.name + '</c>';
- }
- if (levelInfo == undefined) {
- this.subTitleRichText.string = '<color=#1c1c1c>' + skillInfo.desc + '</c>';
- } else {
- this.subTitleRichText.string = '<color=#1c1c1c>' + levelInfo.desc + '</c>';
- }
- },
- /// 设置使用技能的背景
- setupGrayBg(isActive) {
- this.userSkillButton.interactable = isActive;
- this.useSkillButtonBgSprite.spriteFrame = isActive ? this.lightSpriteFrame : this.graySpriteFrame;
- },
- //// 设置技能达到最大值的时候
- setupMaxLevel() {
- if (this.skillData.skillLevel >= this.skillData.maxLevel) {
- this.userSkillButton.interactable = false;
- this.skillUseTitleRichText.node.active = false;
- DWTool.loadResSpriteFrame('./textures/skill/skill_max')
- .then((spriteFrame) => {
- this.useSkillButtonBgSprite.spriteFrame = spriteFrame;
- });
- }
- },
- /// 加载技能icon图片
- loadSpriteFrame(skillData) {
- if (skillData.skillId <= 3) {
- let bgPath = './textures/skill/400' + skillData.skillId + skillData.skillId;
- DWTool.loadResSpriteFrame(bgPath)
- .then((spriteFrame) => {
- this.skillIconBg.spriteFrame = spriteFrame;
- });
- }
- let iconPath = './textures/skill/4000' + skillData.skillId;
- DWTool.loadResSpriteFrame(iconPath)
- .then((spriteFrame) => {
- this.skillIcon.spriteFrame = spriteFrame;
- });
- },
- ///////////// ******* 网络请求 ****** //////
- //// 购买技能
- buySkill(skillId) {
- return new Promise((resolve, reject) => {
- // 获取目标用户的建筑
- SkillApi.buySkill(skillId, (respondData) => {
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- });
- },
- /// 升级建筑
- upBuildingLevel(upLevel) {
- return new Promise((resolve, reject) => {
- // 获取目标用户的建筑
- SkillApi.upBuildingLevel(upLevel, (respondData) => {
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- });
- },
- /// 上报里程碑奖励
- report() {
- return new Promise((resolve, reject) => {
- // 获取目标用户的建筑
- SkillApi.report(3, (respondData) => {
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- });
- },
- ///////////******* 技能升级购买相关 *********/////////////////////////
-
- //// 购买或者升级技能
- useSkillButtonAction() {
- GameModule.audioMng.playClickButton();
- this.userSkillButton.interactable = false;
- this._isAction = true;
- /// 如果是升级建筑
- if (this.fillBuldingNode.active) {
- this.upBuildingLevel(1).then((respondData) => {
- this.userSkillButton.interactable = true;
- this._isAction = false;
- // GameGlobal.userData.buildingLevel = respondData.level;
- GameModule.userInfo.buildingLevel = respondData.level;
- GameModule.userInfo.gold = TapTapTool.sub(GameModule.userInfo.gold, this._upGold);
- this.initAward(this._awardCount);
- GameEvent.fire(GameNotificationKey.UpBuildingLevel);
- GameGlobal._gold10 = respondData.gold10;
- this.updateBuildingData();
- if (GameModule.userInfo.buildingLevel > 5) {
- this.showSkillBuidingAlert(respondData.gold10, respondData.gold100);
- }
- }).catch(({code, msg}) => {
- GameGlobal.commonAlert.showCommonErrorAlert(msg);
- console.log(code, msg);
- this._isAction = false;
- this.userSkillButton.interactable = true;
- });
- } else {
- this.skillAction();
- }
- },
- ///点击按钮之后 技能相关的响应
- skillAction() {
- /// 那就是解锁啦
- let skillId = this.skillData.skillId;
- /// 说明是购买技能
- if (this.skillData.isHave == 0 && skillId > 3) {
- /// 购买成功
- this.buySkill(skillId).then(() => {
- this.updateGloabData();
- this.buyFixSkill();
- GameEvent.fire('skill_update');
- this.userSkillButton.interactable = true;
- console.log("技能购买成功");
- }).catch(({code, msg}) => {
- console.log(code, msg);
- GameGlobal.commonAlert.showCommonErrorAlert(msg);
- this.userSkillButton.interactable = true;
- });
- /// 升级技能
- } else {
- let levelInfo = GameGlobal.BuildingManager.getSkillLevelInfo(this.skillData.skillId, this.skillData.skillLevel);
- levelInfo.name = this._skillInfo.name;
- let nextInfo = GameGlobal.BuildingManager.getSkillLevelInfo(this.skillData.skillId, this.skillData.skillLevel + 1);
- nextInfo.name = this._skillInfo.name;
- AlertManager.showSkillBuyAlert(levelInfo, nextInfo, this);
- this.userSkillButton.interactable = true;
- }
- },
- //// 购买永久技能
- buyFixSkill() {
- this.skillData.skillLevel = 1;
- this.skillData.isHave = 1;
- let skillId = this.skillData.skillId;
- /// 如果升级永久技能
- let skillLevelInfo = GameGlobal.BuildingManager.getSkillLevelInfo(skillId, this.skillData.skillLevel);
- GameEvent.fire(GameNotificationKey.UpdateFixationSkill, skillLevelInfo);
- if (skillId == 5) {
- GameEvent.fire("skill_five_use");
- } else if (skillId == 6) {
- GameGlobal.rcdSkillLevel = 1;
- GameEvent.fire("skill_six_use");
- }
- let iconPath = './textures/skill/4000' + skillId;
- AlertManager.showCommonAlert(iconPath, this._skillInfo.desc, this._skillInfo.name);
- },
- /// 显示购买技能
- showBuySkill() {
- // let levelInfo = GameGlobal.BuildingManager.getSkillLevelInfo(this.skillData.skillId, 1);
-
- /// 使用金币升级
- let diamondCount = this._skillInfo.bonus[10002];
- /// 用的砖石
- if (diamondCount != undefined) {
- this.diamondCount = diamondCount;
- this.coinCount = {'n': 0, 'e': 0};
- this.building = 0;
- this.skillUseTitleRichText.string = `<color=#ffffff>购买</c><br/><img src='skill_diamond'/><color=#ffffff>${diamondCount}钻石</c>`;
- }
- },
- /// 每次升级需要弹窗
- showSkillBuidingAlert (gold10, gold100) {
- this.unschedule(this.hideBuildingAlert, this);
- this.scheduleOnce(this.hideBuildingAlert, 2);
- this.alertNode.getComponent('SkillBuildingAlert').updateData(gold10, gold100, this);
- this.alertNode.active = true;
- },
- hideBuildingAlert () {
- this.alertNode.active = false;
- },
- hiddenSkillBuidingAlert(gold10, gold100) {
- this.initAward(this._awardCount);
- this.updateBuildingData();
- this.showSkillBuidingAlert(gold10, gold100);
- },
- /// 解锁某一个技能
- unlockedSkill() {
- let skillId = this.skillData.skillId;
- this.skillData.isHave = 1;
- this.skillData.skillLevel = 1;
- this.updateData()
- if (skillId <= 3) {
- GameEvent.fire("TopSkill_unLocked", skillId);
- }
- console.log("解锁技能成功");
- },
- //// 里程碑奖励action
- awardBtnAction() {
- this.awardButton.interactable = false;
- GameModule.audioMng.playClickButton();
- this.report().then((respondData) => {
- this.awardButton.interactable = true;
- this._awardCount = respondData.awardCount;
- let needAwardCount = parseInt(GameModule.userInfo.buildingLevel / 25);
- this.awardButton.node.active = needAwardCount > this._awardCount;
- GameModule.userInfo.perpetualClickMt = respondData.clickMt;
- GameEvent.fire(GameNotificationKey.UpBuildingLevel);
- GameEvent.fire(GameNotificationKey.GameShowAdditionTips,"总部大楼",0);
- this.updateBuildingData();
- let objct = {'cdTime': -6 * 1000, 'desc': '点击提升2倍的金币产出', 'icon': 900001};
- GameGlobal._fixInformations.push(objct);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, false);
- console.log("领取里程碑奖励成功");
- }).catch(({code, msg}) => {
- console.log(code, msg);
- this.awardButton.interactable = true;
- });
- },
- /// 判断本地是否是解锁状态
- judgeIsCanUse() {
- if (this.coinCount.n > 0 && TapTapTool.compare(GameModule.userInfo.gold, this.coinCount)) {
- return true;
- } else if (this.diamondCount > 0 && GameModule.userInfo.diamond >= this.diamondCount) {
- return true;
- } else if (this.building > 0 && GameModule.userInfo.buildingLevel >= this.building) {
- return true;
- } else {
- return false;
- }
- },
- ///更新全局数据
- updateGloabData() {
- if (this.coinCount.n > 0) {
- GameModule.userInfo.gold = TapTapTool.sub(GameModule.userInfo.gold, this.coinCount);
- } else if (this.diamondCount > 0) {
- GameModule.userInfo.diamond -= this.diamondCount;
- }
- },
- });
|