123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- const DWTool = require("../utils/DWTool");
- const SkillApi = require('../net/SkillApi');
- const GameModule = require("../utils/GameModule");
- const {GameNotificationKey, WechatShareType } = require('../utils/GameEnum');
- const WeChat = require('../net/WeChat');
- const TapTapTool = require("../utils/TapTapTool");
- const AlertManager = require('../utils/AlertManager');
- const GameRedDot = require('../utils/GameEnum').GameRedDot;
- const ADVideo = require('../utils/ADVideo');
- const SkillState = cc.Enum({
- /// 使用中
- usingState: 1,
- /// 技能cd状态
- cdState: 2,
- /// 技能可以使用的状态
- canUseState: 3,
- /// 技能锁住的状态
- lockedState: 4
- });
- cc.Class({
- extends: cc.Component,
- properties: {
- titleRichText: {
- tooltip: '技能时间time ,锁住状态的text',
- default: null,
- type: cc.RichText
- },
- skillBg: {
- tooltip: '技能的黑色遮罩',
- default: null,
- type: cc.Sprite
- },
- skillBgOutSide: {
- tooltip: '技能的黑色外遮罩,这里只有是三个哦,最后一个刷新技能的是没有的',
- default: null,
- type: cc.Sprite
- },
- skillBgBottom: {
- tooltip: '技能的底部黑色遮罩',
- default: null,
- type: cc.Sprite
- },
- button: cc.Button,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- ///技能解锁啦
- GameEvent.on("TopSkill_unLocked", this, (skillId) => {
- if (this.skillInfo != undefined && skillId === this.skillInfo.skillId) {
- this.setUpSkillState(SkillState.canUseState);
- /// 技能等级 1
- this.skillInfo.skillLevel = 1;
- /// 设置为可以使用
- this.skillInfo.skillStatus = SkillState.canUseState;
- this.updataData();
- let iconPath = './textures/skill/4000' + skillId;
- AlertManager.showCommonAlert(iconPath, this._skillData.desc, this._skillData.name);
- let iconId = 900005 + skillId
- let objct = {'cdTime': 0, 'infoDesc': `${this._skillData.name}可使用`, 'name': this._skillData.name, 'icon': iconId, 'sId': skillId, 'type': 2, 'skillStatus': 0};
- Global._timeInformations.push(objct);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
- /// 设置重置技能可用
- } else if (this.skillInfo == undefined && this._isAlllLocked) {
- this._isAlllLocked = false;
- this.setUpSkillState(SkillState.canUseState);
- }
- });
- },
- start () {
- },
- onDestroy() {
- GameEvent.off("TopSkill_unLocked", this);
- GameEvent.off(GameNotificationKey.ResetSkill, this);
- GameEvent.off(GameNotificationKey.UpBuildingLevel, this);
- GameEvent.off("skill_six_use", this);
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- this.unschedule(this.updateTime, this);
- },
- init(skillInfo) {
- if (this.skillInfo == undefined) {
- this.setupTopSkillNotification();
- }
- this.skillInfo = skillInfo;
- let skillData = Global.BuildingManager.getSkillInfo(skillInfo.skillId);
- this._skillData = skillData;
- if (skillInfo.isHave == 0) {
- this.setUpSkillState(SkillState.lockedState);
- this.titleRichText.string = "<img src='skill_lock'/><br/><color=#ffffff>等级" + skillData.buildingLevel + '</c>';
- return;
- }
- /// 如果不是第二个技能那么去更新信息流时间
- if (skillInfo.skillId != 2) {
- for (let i = 0; i < Global._timeInformations.length; ++ i) {
- let information = Global._timeInformations[i]
- /// 如果是第一个技能或者第三个技能则更新它的时间
- if (information.type == 2 && information.sId == skillInfo.skillId) {
- /// 技能使用cd中
- if (this.skillInfo.skillStatus == 1) {
- information.cdTime = skillInfo.cdStarTime;
- } else {
- information.cdTime = 0;
- }
- }
- }
- }
-
- this.updataData();
- },
- setupTopSkillNotification() {
- GameEvent.on(GameNotificationKey.ResetSkill, this, () => {
- // console.log(this.skillInfo);
- if (this.skillState !== SkillState.lockedState) {
- this.setUpSkillState(SkillState.canUseState);
- }
- let isNew = true;
- for (let i = 0; i < Global._timeInformations.length; ++ i) {
- let information = Global._timeInformations[i]
- /// 如果是第一个技能或者第三个技能则更新它的时间
- if (information.type == 2 && information.sId == this.skillInfo.skillId) {
- information.cdTime = 0;
- /// 可以使用
- information.skillStatus = 0;
- information.infoDesc = `${this.skillInfo.name}可使用`;
- isNew = false;
- ///那么就是没有用过嘛 直接固定在那里
- }
- }
- if (isNew) {
- let iconId = 900005 + this.skillInfo.skillId
- let objct = {'cdTime': 0, 'infoDesc': `${this.skillInfo.name}可使用`, 'name': this.skillInfo.name, 'icon': iconId, 'sId': this.skillInfo.skillId, 'type': 2, 'skillStatus': 0};
- Global._timeInformations.push(objct);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
- }
- });
- /// 第六个技能使用 需要更新cd时间
- GameEvent.on("skill_six_use", this, () => {
-
- let lastLevelInfo = Global.BuildingManager.getSkillLevelInfo(6, Global.rcdSkillLevel);
- this.cd = this._levelInfo.cd * (1 - lastLevelInfo.rcd / 100);
- });
- GameEvent.on(GameNotificationKey.UpdateTimeSkill, this, (skillLevelInfo) => {
- if (this.skillState === SkillState.canUseState && this.skillInfo.skillId == skillLevelInfo.skillId) {
- this.updataData();
- }
- });
- },
- updataData() {
- let levelInfo = Global.BuildingManager.getSkillLevelInfo(this.skillInfo.skillId, this.skillInfo.skillLevel);
- this._levelInfo = levelInfo;
- if (Global.rcdSkillLevel == 0) {
- this.cd = levelInfo.cd;
- } else {
- let lastLevelInfo = Global.BuildingManager.getSkillLevelInfo(6, Global.rcdSkillLevel);
- this.cd = levelInfo.cd * (1 - lastLevelInfo.rcd / 100);
- }
- /// 技能cd
- /// 持续时间
- let td = levelInfo.td;
- let hasCd = this.skillInfo.cdStarTime / 1000;
- this.td = td;
- /// 技能使用cd中
- if (this.skillInfo.skillStatus == 2) {
- this.setUpSkillState(SkillState.cdState);
- this.timeLabelCount = hasCd;
- this.titleRichText.string = DWTool.calculateTime(hasCd);
- this.skillBg.fillRange = - hasCd / this.cd;
- /// 技能使用中
- } else if (this.skillInfo.skillStatus == 1) {
- this.setUpSkillState(SkillState.usingState);
- this.timeLabelCount = hasCd;
- this.titleRichText.string = DWTool.calculateTime(hasCd);
- this.skillBgOutSide.fillRange = - hasCd / td;
- } else {
- this.setUpSkillState(SkillState.canUseState);
- }
- },
- /// 初始化刷新技能的item
- initUpdateSkill(isAllLocked) {
- ///是否所有的技能锁住
- this._isAlllLocked = isAllLocked;
- // 20分钟
- this.cd = 15 * 60;
- if (isAllLocked) {
- this.setUpSkillState(SkillState.lockedState);
- return;
- }
- let resetSkillTime = Global.userData.resetSkillTime;
- let timestamp = new Date().getTime();
- let totalCd = (timestamp - resetSkillTime) / 1000;
- if (this.cd <= totalCd) {
- this.setUpSkillState(SkillState.canUseState);
- } else {
- this.setUpSkillState(SkillState.cdState);
- this.skillBg.fillRange = totalCd / this.cd - 1;
- this.timeLabelCount = this.cd - totalCd;
- this.titleRichText.string = DWTool.calculateTime(this.timeLabelCount);
- }
- },
- updateTime() {
- if (this.skillState === SkillState.canUseState || this.skillState === SkillState.lockedState) {
- return;
- }
- /// 使用中的状态
- if (this.skillState === SkillState.usingState) {
- this.timeLabelCount -= 1;
- this.skillBgOutSide.fillRange += 1 / this.td;
- if(this.skillBgOutSide.fillRange >= 0 || this.timeLabelCount <= 0) {
- this.setUpSkillState(SkillState.cdState);
- this.timeLabelCount = this.cd;
- this.skillBg.fillRange = - 1;
- this.titleRichText.string = DWTool.calculateTime(this.timeLabelCount);
- } else {
- this.titleRichText.string = DWTool.calculateTime(this.timeLabelCount);
- }
- /// 技能cd 的状态
- } else {
- this.skillBg.fillRange += 1 / this.cd;
- this.timeLabelCount -= 1;
- if (this.skillBg.fillRange >= 0 || this.timeLabelCount <= 0) {
- this.setUpSkillState(SkillState.canUseState);
- }else {
- this.titleRichText.string = DWTool.calculateTime(this.timeLabelCount);
- }
- }
- },
- setUpSkillState(skillState) {
- this.skillState = skillState;
- this.skillBg.node.active = skillState !== SkillState.canUseState;
- if (this.skillBgOutSide != null) {
- this.skillBgOutSide.node.active = skillState === SkillState.usingState;
- }
- this.skillBgBottom.node.active = skillState !== SkillState.canUseState;
- this.titleRichText.node.active = skillState !== SkillState.canUseState;
- this.button.interactable = skillState === SkillState.canUseState;
- },
- sendNotification() {
- let skillId = this.skillInfo.skillId;
- let skillLevelInfo = Global.BuildingManager.getSkillLevelInfo(skillId, this.skillInfo.skillLevel);
- GameEvent.fire(GameNotificationKey.UseTimeSkill, skillLevelInfo);
- // cdTime 剩余时间 是 [long] 查看
- // 5 desc 描述 是 [string] 查看
- // 6 name 名称 是 [string] 查看
- if (skillId == 2) {
- //显示使用技能效果
- let gold = TapTapTool.multiple(GameModule.userInfo.coinTap, {'n': skillLevelInfo.mt, 'e': 0});
- let text = TapTapTool.parseToString(gold);
- AlertManager.showSkill2Efc(text);
- let isNew = true;
- for (let i = 0; i < Global._timeInformations.length; ++ i) {
- let information = Global._timeInformations[i];
- if (information.type == 2 && information.sId == 2) {
- /// 如果是已经使用过的直接刷新时间就可以啦
- information.cdTime = -6 * 1000;
- information.skillStatus = 1;
- information.infoDesc = `获得金币${text}`;
- isNew = false;
- break;
- }
- }
- if (isNew) {
- let objct = {'cdTime': -6 * 1000, 'infoDesc': `获得金币${text}`, 'name': this.skillInfo.name, 'icon': 900007, 'sId': 2, 'type': 2, 'skillStatus': 1};
- Global._fixInformations.push(objct);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, false);
- }
- } else {
- this.handelSkillTimeInformation(skillLevelInfo, skillId);
- }
- },
- //// 处理第一个和第三个实时技能的信息流数据
- handelSkillTimeInformation(skillLevelInfo, skillId) {
- let isNew = true;
- let infoDesc = this._skillData.infoDesc;
- let skillLevel = this.skillInfo.skillLevel;
- /// 第一个技能
- if (skillId === 1) {
- let num = skillLevel > 11 ? (10 + skillLevel - 11) : 10;
- infoDesc = infoDesc.replace('{num}', num);
- /// 第三个技能
- } else {
- infoDesc = infoDesc.replace('${num}', skillLevelInfo.mt * 100);
- }
- for (let i = 0; i < Global._timeInformations.length; ++ i) {
- let information = Global._timeInformations[i];
- if (information.type == 2 && information.sId == skillId) {
- /// 如果是已经使用过的直接刷新时间就可以啦
- information.cdTime = skillLevelInfo.td * 1000;
- information.skillStatus = 1;
- information.infoDesc = infoDesc;
- isNew = false;
- break;
- }
- }
- if (isNew){
- let objct = {'cdTime': skillLevelInfo.td * 1000, 'infoDesc': infoDesc, 'name': this.skillInfo.name, 'icon': 900005 + skillId, 'sId': skillId, 'type': 2, 'skillStatus': 1};
- Global._timeInformations.push(objct);
- GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
- }
- },
- skillAction1() {
- GameModule.audioMng.playClickButton();
- this.button.interactable = false;
- this.useSkill(this.skillInfo.skillId).then(() => {
- this.button.interactable = true;
- this.setUpSkillState(SkillState.usingState);
- this.timeLabelCount = this.td;
- this.titleRichText.string = DWTool.calculateTime(this.td);
- this.skillBgOutSide.fillRange = -1;
- this.skillBg.fillRange = -1;
- this.sendNotification();
- }).catch(({code, msg}) => {
- console.log(code, msg);
- this.button.interactable = true;
- });
- },
- skillAction2() {
- GameModule.audioMng.playClickButton();
- this.button.interactable = false;
- this.useSkill(this.skillInfo.skillId).then(() => {
- this.button.interactable = true;
- this.setUpSkillState(SkillState.cdState);
- this.timeLabelCount = this.cd;
- this.titleRichText.string = DWTool.calculateTime(this.cd);
- this.skillBg.fillRange = -1;
- this.sendNotification();
- }).catch(({code, msg}) => {
- console.log(code, msg);
- this.button.interactable = true;
- });
- },
- skillAction3() {
- GameModule.audioMng.playClickButton();
- this.button.interactable = false;
- this.useSkill(this.skillInfo.skillId).then(() => {
- this.button.interactable = true;
- this.setUpSkillState(SkillState.usingState);
- this.timeLabelCount = this.td;
- this.titleRichText.string = DWTool.calculateTime(this.td);
- this.skillBgOutSide.fillRange = -1;
- this.skillBg.fillRange = -1;
- this.sendNotification();
- GameEvent.fire("skill3_use_begain");
- }).catch(({code, msg}) => {
- console.log(code, msg);
- this.button.interactable = true;
- });
- },
- skillAgainAction() {
- GameModule.audioMng.playClickButton();
- if (CC_WECHATGAME) {
- this.button.interactable = false;
- ADVideo.wxPlayADVideo('adunit-72f6285169164939', () => {
- this.button.interactable = true;
- }, (isFinished) => {
- if (isFinished) {
- this.shareActionCallback();
- } else {
- this.button.interactable = true;
- }
- });
- }
- },
- shareActionCallback() {
- this.resetSkill().then((respondData) => {
- Global.userData.resetSkillTime = respondData.curSystemTime;
- this.setUpSkillState(SkillState.cdState);
- this.timeLabelCount = this.cd;
- this.titleRichText.string = DWTool.calculateTime(this.cd);
- this.skillBg.fillRange = -1;
- GameEvent.fire(GameNotificationKey.ResetSkill);
- }).catch(({code, msg}) => {
- console.log(code, msg);
- this.button.interactable = true;
- });
- GameEvent.off(GameNotificationKey.ShowShareAction, this);
- },
- /// 网络请求
- useSkill(skillId) {
- return new Promise((resolve, reject) => {
- // 获取目标用户的建筑
- SkillApi.useSkill(skillId, (respondData) => {
- /// 如果取消了红点显示
- // if (respondData.isCancel) {
- // /// 去掉因为技能 可以用的红点条件
- // TapTapTool.removeRedDot(GameRedDot.skill);
- // }
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- });
- },
- resetSkill() {
- return new Promise((resolve, reject) => {
- // 获取目标用户的建筑
- SkillApi.resetSkill((respondData) => {
- resolve(respondData);
- }, (code, msg) => {
- reject({code, msg});
- });
- });
- },
- });
|