123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- const GameModule = require('../utils/GameModule');
- const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
- const TapTapTool = require("../utils/TapTapTool");
- cc.Class({
- extends: cc.Component,
- properties: {
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- GameModule.skill = this;
- this.multiple = {'n': 1, 'e': 0};
- this.skills = Global.skills;
- //判断是否正在使用技能3
- this.isUsingSkill3 = false;
- this.skill3Floor = Math.random() < 0.5 ? -1 : 1; //初始化在楼层单双数显示对联,正数为单,负数为双
- this.getAllSkillInfo();
- //先获取技能3的加成倍数
- this.getSkill3Ability();
- this.updateAutoGetGold();
- this.updateClickGold();
- this.setupEventListener();
- this.schedule(this.updateSkilltime, 1);
- },
- //添加相关接收通知
- setupEventListener() {
- GameEvent.on(GameNotificationKey.UpBuildingLevel, this, this.updateClickGold);
- GameEvent.on(GameNotificationKey.UpdateFixationSkill, this, (skillInfo) => {
- this.updateSkill(skillInfo);
- });
- //使用实时技能通知
- GameEvent.on(GameNotificationKey.UseTimeSkill, this, (skillInfo) => {
- this.useTimeSkill(skillInfo);
- });
- //重置技能CD时间通知
- GameEvent.on(GameNotificationKey.ResetSkill, this, () => {
- this.resetSkill();
- });
- GameEvent.on(GameNotificationKey.GameSkillOnHide, this, () => {
- this.refreshSkillStatus();
- });
- },
- //技能列表解锁或升级技能
- updateSkill(skillInfo) {
- switch (skillInfo.skillId) {
- case 4:
- this.skill4Info.skillLevel = skillInfo.level;
- this.updateAutoGetGold();
- break;
- case 5:
- this.skill5Info.skillLevel = skillInfo.level;
- this.updateClickGold();
- break;
- default:
- break;
- }
- },
- //技能实时技能
- useTimeSkill(skillInfo) {
- switch (skillInfo.skillId) {
- case 1:
- this.skill1Info.skillLevel = skillInfo.level;
- this.skill1Info.tdStarTime = skillInfo.td * 1000;
- this.skill1Info.skillStatus = 1;
- this.updateAutoGetGold();
- break;
- case 2:
- this.skill2Info = skillInfo;
- let add = TapTapTool.multiple(GameModule.userInfo.coinTap, {'n': this.skill2Info.mt, 'e': 0});
- GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, add);
- break;
- case 3:
- this.skill3Info.skillLevel = skillInfo.level;
- this.skill3Info.tdStarTime = skillInfo.td * 1000;
- this.skill3Info.skillStatus = 1;
- this.getSkill3Ability();
- break;
- default:
- break;
- }
- },
- //重置技能CD时间
- resetSkill() {
- this.skill1Info.tdStarTime = 0;
- this.skill1Info.skillStatus = 0;
- this.updateAutoGetGold();
- this.skill3Info.tdStarTime = 0;
- this.skill3Info.skillStatus = 0;
- this.multiple = {'n': 1, 'e': 0};
- this.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
- },
- //获取所有技能的信息
- getAllSkillInfo() {
- this.skill1Info = this.skills.find(n => {
- return n.skillId == 1;
- });
- this.skill2Info = this.skills.find(n => {
- return n.skillId == 2;
- });
- this.skill3Info = this.skills.find(n => {
- return n.skillId == 3;
- });
- this.skill4Info = this.skills.find(n => {
- return n.skillId == 4;
- });
- this.skill5Info = this.skills.find(n => {
- return n.skillId == 5;
- });
- },
- // start () {
- //
- // },
- /// 刷新技能从后台到前台的状态
- refreshSkillStatus() {
- let onHideTime = cc.sys.localStorage.getItem('onHideTimestamp');
- let curTime = new Date().getTime();
- let difference = curTime - onHideTime;
- if (this.skill1Info && this.skill1Info.skillStatus == 1) {
- //处理游戏使用技能后进入过后台的情况
- if (onHideTime) {
- if (difference > 0) {
- let isPast = difference > this.skill1Info.tdStarTime * 1000; //大于的话就是已超过使用技能的时间戳
- if (isPast) {
- this.skill1Info.tdStarTime = 0;
- this.skill1Info.skillStatus = 2;
- this.updateAutoGetGold();
- } else {
- this.skill1Info.tdStarTime = this.skill1Info.tdStarTime * 1000 - difference;
- }
- } else {
- this.skill1Info.tdStarTime = 0;
- this.skill1Info.skillStatus = 2;
- this.updateAutoGetGold();
- }
- }
- // console.log('skill 1 ' + this.skill1Info.tdStarTime);
- }
- if (this.skill3Info && this.skill3Info.skillStatus == 1) {
- if (onHideTime) {
- if (difference > 0) {
- let isPast = difference > this.skill3Info.tdStarTime * 1000; //大于的话就是已超过使用技能的时间戳
- if (isPast) {
- this.skill3Info.tdStarTime = 0;
- this.skill3Info.skillStatus = 2;
- this.multiple = {'n': 1, 'e': 0};
- this.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
- this.isUsingSkill3 = false;
- } else {
- this.skill3Info.tdStarTime = this.skill3Info.tdStarTime * 1000 - difference;
- }
- } else {
- this.skill3Info.tdStarTime = 0;
- this.skill3Info.skillStatus = 2;
- this.multiple = {'n': 1, 'e': 0};
- this.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
- this.isUsingSkill3 = false;
- }
- }
- // console.log('skill 3 ' + this.skill3Info.tdStarTime);
- }
- },
- /// 每秒更新实时技能的使用时间
- updateSkilltime() {
- if (this.skill1Info && this.skill1Info.skillStatus == 1) {
- //tdStarTime大于0为正在使用中
- if (this.skill1Info.tdStarTime > 0) {
- this.skill1Info.tdStarTime -= (1 * 1000 );
-
- if (this.skill1Info.tdStarTime <= 0) {
- this.skill1Info.tdStarTime = 0;
- this.skill1Info.skillStatus = 2;
- this.updateAutoGetGold();
- }
- } else {
- this.skill1Info.tdStarTime = 0;
- this.skill1Info.skillStatus = 2;
- this.updateAutoGetGold();
- }
- /// 重新进入前台需要刷新数据
- } else if (this.skill1Info && this.skill1Info.isShow != undefined) {
-
- this.skill1Info.isShow = undefined;
- this.skill1Info.tdStarTime = 0;
- this.updateAutoGetGold();
- }
- if (this.skill3Info && this.skill3Info.skillStatus == 1) {
- if (this.skill3Info.tdStarTime > 0) {
- this.skill3Info.tdStarTime -= 1 * 1000;
- this.isUsingSkill3 = true;
- if (this.skill3Info.tdStarTime <= 0) {
- this.skill3Info.tdStarTime = 0;
- this.skill3Info.skillStatus = 2;
- this.multiple = {'n': 1, 'e': 0};
- this.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
- this.isUsingSkill3 = false;
- }
- } else {
- this.skill3Info.tdStarTime = 0;
- this.skill3Info.skillStatus = 2;
- this.multiple = {'n': 1, 'e': 0};
- this.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
- this.isUsingSkill3 = false;
- }
- } else if (this.skill3Info && this.skill3Info.isShow != undefined) {
- this.skill3Info.isShow = undefined;
- this.skill3Info.tdStarTime = 0;
- this.multiple = {'n': 1, 'e': 0};
- this.updateClickGold();
- GameModule.userInfo.refreshSecondText();
- GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
- this.isUsingSkill3 = false;
- } else {
- this.isUsingSkill3 = false;
- }
- },
- // update (dt) {
- // },
- //更新每秒自动点击生成金币的速率
- updateAutoGetGold() {
- var second = 1;
- var click = 0;
- var skill1 = this.getSkill1Ability();
- if (skill1 != null) {
- click += skill1.cc / skill1.iv;
- }
- var skill4 = this.getSkill4Ability();
- if (skill4 != null) {
- click += skill4.cc / skill4.iv;
- }
- if (click > 0) {
- GameModule.userInfo.secondClick = second / click;
- } else {
- GameModule.userInfo.secondClick = 0;
- }
- },
- //更新每次点击生成金币的数量
- updateClickGold() {
- var clickGold = this.getBuildingGold();
- clickGold = clickGold * this.getSkill5Ability();
- let coinTap = TapTapTool.multiple({'n': clickGold, 'e': 0}, this.multiple);
- coinTap = TapTapTool.multiple(coinTap, GameModule.shop.multiple);
- GameModule.userInfo.coinTap = TapTapTool.multiple(coinTap, GameModule.userInfo.perpetualClickMt);
- GameModule.userInfo.refreshSecondText();
- },
- //总部大楼等级技能
- getBuildingGold() {
- this.userBuildingLevel = GameModule.userInfo.buildingLevel;
- let clickGold = 9 + this.userBuildingLevel;
- return clickGold;
- },
- //主动释放技能1,多少分钟内每秒自动点击多少次
- getSkill1Ability() {
- if (this.skill1Info == undefined || this.skill1Info.skillLevel <= 0 ) {
- return null;
- }
-
- if (this.skill1Info.skillStatus != 1 || this.skill1Info.tdStarTime == 0) {
- return null;
- }
- let skillInfo = Global.BuildingManager.getSkillLevelInfo(this.skill1Info.skillId, this.skill1Info.skillLevel);
- return skillInfo;
- },
- //主动释放技能3,增加加成倍数
- getSkill3Ability() {
- if (this.skill3Info == undefined || this.skill3Info.skillLevel <= 0 ) {
- return null;
- }
- if (this.skill3Info.skillStatus != 1 || this.skill3Info.tdStarTime == 0) {
- return null;
- }
-
- let skillInfo = Global.BuildingManager.getSkillLevelInfo(this.skill3Info.skillId, this.skill3Info.skillLevel);
- this.multiple = {'n': skillInfo.mt, 'e': 0};
- GameModule.userInfo.multiple = this.multiple;
- this.updateClickGold();
-
- },
- //永久技能1,指定时间内自动点击次数
- getSkill4Ability() {
- if (this.skill4Info == undefined || this.skill4Info.skillLevel <= 0 ) {
- return null;
- }
- let skillInfo = Global.BuildingManager.getSkillLevelInfo(this.skill4Info.skillId, this.skill4Info.skillLevel);
- return skillInfo;
- },
- //永久技能2,每次点击产出的金币提升
- getSkill5Ability() {
- if (this.skill5Info == undefined || this.skill5Info.skillLevel <= 0 ) {
- return 1;
- }
- let skillInfo = Global.BuildingManager.getSkillLevelInfo(this.skill5Info.skillId, this.skill5Info.skillLevel);
- let mt = skillInfo.mt;
- return mt;
- },
- //永久技能3,减少CD时间
- getSkill6Ability() {
- let skillInfo = this.skills.find(n => {
- return n.skillId == 6;
- });
- skillInfo = Global.BuildingManager.getSkillLevelInfo(skillInfo.skillId, skillInfo.skillLevel);
- let rcd = (1 - skillInfo.rcd);
- return rcd;
- },
- });
|