123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602 |
- const SkillApi = require('../net/SkillApi');
- const DWTool = require("../utils/DWTool");
- const GameModule = require("../utils/GameModule");
- const buildingLevel = require('../data/buildingLevel');
- const {GameNotificationKey, WechatShareType} = require('../utils/GameEnum');
- const WeChat = require('../net/WeChat');
- const TapTapTool = require("../utils/TapTapTool");
- const AlertManager = require('../utils/AlertManager');
- const ADVideo = require('../utils/ADVideo');
- const HomeApi = require('../net/HomeApi');
- // const GameRedDot = require('../utils/GameEnum').GameRedDot;
- // WeChat
- 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,
- /// 0说明是用金币 1 说明是用分享 2 看广告
- _adState: 0,
- //// 当前使用的广告状态
- _useAdState: 0,
- _isInitAd: 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);
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- // GameEvent.off(GameNotificationKey.AdBuildingStateUpdate, this);
- },
- update (dt) {
- /// 如果说是建筑 并且没有处于响应
- if (this.fillBuldingNode.active && this._isAction === false) {
- let isCanUse = this.judgeIsCanUse();
- let isAd = DWTool.checkIsOldUser() && Global._upBuildingInfo.maxCount > Global._upBuildingInfo.count && Global._upBuildingInfo.cdTime <= 0;
- /// 如果有广告或者分享
- if (!this._isInitAd && isAd) {
- this._isInitAd = true;
- this.initBuildingAd();
- }
- if (isAd && !isCanUse) {
- if (this._useAdState != this.adState) {
- this._useAdState = this._adState;
- this.updateBuildingUsingUI();
- this.setupGrayBg(true);
- }
- } else {
- if (this._useAdState != 0) {
- this._useAdState = 0;
- this.updateBuildingUsingUI();
- }
- let inter = this.userSkillButton.interactable;
- if (isCanUse != inter) {
- 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();
- });
- // /// cd时间到了
- // GameEvent.on(GameNotificationKey.AdBuildingStateUpdate, this, () => {
- // this.initBuildingAd();
- // });
- GameEvent.on(GameNotificationKey.AdUpdateStateNotification, this, (adState, callBack) => {
- /// 说明是技能的关闭状态
- if (adState === 3 && callBack === 'skill') {
- this.finishAction();
- }
- if (adState === 0 || adState === 1) {
- this.initBuildingAd();
- }
- });
- GameModule.homeGuide.on('Fire_state16', this.awardBtnAction, this);
-
- // let buildingLevelInfo = buildingLevel[buildingInfo.buildingLevel - 1];
- },
- initBuildingAd() {
- if (!CC_WECHATGAME) {
- return;
- }
- //// 说明有广告
- if (Global._adVideoState == 0) {
- this._adState = 2;
- } else if (Global._adVideoState === 1) {
- this._adState = 1;
- }
- },
- finishAction() {
- HomeApi.reportInformation(1, () => {
- Global._upBuildingInfo.count += 1;
- /// 时间重置为5分钟
- Global._upBuildingInfo.cdTime = 5 * 60 * 1000;
- /// 恢复到正常的状态
- /// 如果已经达到当天最大的次数
- // if (Global._upBuildingInfo.maxCount <= Global._upBuildingInfo.count) {
- // if (this._video != undefined) {
- // /// 销毁这个对象
- // this._video = null;
- // }
- // return;
- // }
- /// 请求升级建筑
- this._adState = 0;
- this._useAdState = 0;
- this.requestUpBuildingLevel();
- }, (code, msg) => {
- console.log(msg);
- })
- },
- //// 初始化技能数据
- 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.updateBuildingUsingUI();
- // 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>`;
- },
- /// 根据视频 分享 升级更新使用的UI
- updateBuildingUsingUI() {
- /// 如果是直接使用金币
- if (this._useAdState === 0) {
- this.skillUseTitleRichText.string = '<color=#ffffff>+' + TapTapTool.parseToString(this._upGet) + '收益</c>' + `<br/><img src='coin_small'/><color=#ffffff>${TapTapTool.parseToString(this._upGold)}</c>`;
- /// 如果是分享
- } else if (this._useAdState === 1) {
- this.skillUseTitleRichText.string = '<color=#ffffff> 分享\n免费升级' + '</c>';
- } else {
- this.skillUseTitleRichText.string = '<color=#ffffff> 看视频\n免费升级' + '</c>';
- }
- },
- /// 更新技能相关数据
- updateData() {
- let levelInfo = Global.BuildingManager.getSkillLevelInfo(this.skillData.skillId, this.skillData.skillLevel);
- let skillInfo = Global.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.upBuildingLevelAction();
- } else {
- this.skillAction();
- }
- },
- upBuildingLevelAction() {
-
- if (CC_WECHATGAME) {
- if (this._useAdState == 0) {
- this.requestUpBuildingLevel();
- /// 说明是分享
- } else if (this._useAdState == 1) {
- GameEvent.on(GameNotificationKey.ShowShareAction, this, (type, isOk) => {
- if (type == WechatShareType.UpBuilding) {
- if (isOk) {
- this.finishAction();
- } else {
- this.userSkillButton.interactable = true;
- this._isAction = false;
- }
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- }
- });
- WeChat.shareAction(WechatShareType.UpBuilding, () => {
- }, () => {
- this.userSkillButton.interactable = true;
- this._isAction = false;
- console.log('分享失败或取消');
- });
- /// 如果是看视频
- } else {
- this.userSkillButton.interactable = true;
- this._isAction = false;
- Global._adVideo.showVideo('skill');
- }
- } else {
- this.requestUpBuildingLevel();
- }
- },
- requestUpBuildingLevel() {
- this.upBuildingLevel(1).then((respondData) => {
- this.userSkillButton.interactable = true;
- this._isAction = false;
- // Global.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);
- Global._gold10 = respondData.gold10;
- this.updateBuildingData();
-
- if (GameModule.userInfo.buildingLevel > 5 && this._useAdState === 0) {
- this.showSkillBuidingAlert(respondData.gold10, respondData.gold100);
- }
- }).catch(({code, msg}) => {
- Global.commonAlert.showCommonErrorAlert(msg);
- console.log(code, msg);
- this._isAction = false;
- this.userSkillButton.interactable = true;
- });
- },
- ///点击按钮之后 技能相关的响应
- 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);
- Global.commonAlert.showCommonErrorAlert(msg);
- this.userSkillButton.interactable = true;
- });
- /// 升级技能
- } else {
- let levelInfo = Global.BuildingManager.getSkillLevelInfo(this.skillData.skillId, this.skillData.skillLevel);
- levelInfo.name = this._skillInfo.name;
- let nextInfo = Global.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 = Global.BuildingManager.getSkillLevelInfo(skillId, this.skillData.skillLevel);
- GameEvent.fire(GameNotificationKey.UpdateFixationSkill, skillLevelInfo);
- if (skillId == 5) {
- GameEvent.fire("skill_five_use");
- } else if (skillId == 6) {
- Global.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 = Global.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 = TapTapTool.multiple(GameModule.userInfo.perpetualClickMt, {'e': 0, 'n': 2});
- GameEvent.fire(GameNotificationKey.UpBuildingLevel);
- GameEvent.fire(GameNotificationKey.GameShowAdditionTips,"总部大楼",0);
- this.updateBuildingData();
- let objct = {'cdTime': -6 * 1000, 'infoDesc': '点击提升2倍的金币产出', 'icon': 900001};
- Global._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;
- }
- },
- });
|