GameSkill.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. const GameModule = require('../utils/GameModule');
  2. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  3. const TapTapTool = require("../utils/TapTapTool");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. },
  8. // LIFE-CYCLE CALLBACKS:
  9. onLoad () {
  10. GameModule.skill = this;
  11. this.multiple = {'n': 1, 'e': 0};
  12. this.skills = Global.skills;
  13. //判断是否正在使用技能3
  14. this.isUsingSkill3 = false;
  15. this.skill3Floor = Math.random() < 0.5 ? -1 : 1; //初始化在楼层单双数显示对联,正数为单,负数为双
  16. this.getAllSkillInfo();
  17. //先获取技能3的加成倍数
  18. this.getSkill3Ability();
  19. this.updateAutoGetGold();
  20. this.updateClickGold();
  21. this.setupEventListener();
  22. this.schedule(this.updateSkilltime, 1);
  23. },
  24. //添加相关接收通知
  25. setupEventListener() {
  26. GameEvent.on(GameNotificationKey.UpBuildingLevel, this, this.updateClickGold);
  27. GameEvent.on(GameNotificationKey.UpdateFixationSkill, this, (skillInfo) => {
  28. this.updateSkill(skillInfo);
  29. });
  30. //使用实时技能通知
  31. GameEvent.on(GameNotificationKey.UseTimeSkill, this, (skillInfo) => {
  32. this.useTimeSkill(skillInfo);
  33. });
  34. //重置技能CD时间通知
  35. GameEvent.on(GameNotificationKey.ResetSkill, this, () => {
  36. this.resetSkill();
  37. });
  38. },
  39. //技能列表解锁或升级技能
  40. updateSkill(skillInfo) {
  41. switch (skillInfo.skillId) {
  42. case 4:
  43. this.skill4Info.skillLevel = skillInfo.level;
  44. this.updateAutoGetGold();
  45. break;
  46. case 5:
  47. this.skill5Info.skillLevel = skillInfo.level;
  48. this.updateClickGold();
  49. break;
  50. default:
  51. break;
  52. }
  53. },
  54. //技能实时技能
  55. useTimeSkill(skillInfo) {
  56. switch (skillInfo.skillId) {
  57. case 1:
  58. this.skill1Info.skillLevel = skillInfo.level;
  59. this.skill1Info.tdStarTime = skillInfo.td * 1000;
  60. this.skill1Info.skillStatus = 1;
  61. this.updateAutoGetGold();
  62. break;
  63. case 2:
  64. this.skill2Info = skillInfo;
  65. let add = TapTapTool.multiple(GameModule.userInfo.coinTap, {'n': this.skill2Info.mt, 'e': 0});
  66. GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, add);
  67. break;
  68. case 3:
  69. this.skill3Info.skillLevel = skillInfo.level;
  70. this.skill3Info.tdStarTime = skillInfo.td * 1000;
  71. this.skill3Info.skillStatus = 1;
  72. this.getSkill3Ability();
  73. break;
  74. default:
  75. break;
  76. }
  77. },
  78. //重置技能CD时间
  79. resetSkill() {
  80. this.skill1Info.tdStarTime = 0;
  81. this.skill1Info.skillStatus = 0;
  82. this.updateAutoGetGold();
  83. this.skill3Info.tdStarTime = 0;
  84. this.skill3Info.skillStatus = 0;
  85. this.multiple = {'n': 1, 'e': 0};
  86. this.updateClickGold();
  87. GameModule.userInfo.refreshSecondText();
  88. GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
  89. },
  90. //获取所有技能的信息
  91. getAllSkillInfo() {
  92. this.skill1Info = this.skills.find(n => {
  93. return n.skillId == 1;
  94. });
  95. this.skill2Info = this.skills.find(n => {
  96. return n.skillId == 2;
  97. });
  98. this.skill3Info = this.skills.find(n => {
  99. return n.skillId == 3;
  100. });
  101. this.skill4Info = this.skills.find(n => {
  102. return n.skillId == 4;
  103. });
  104. this.skill5Info = this.skills.find(n => {
  105. return n.skillId == 5;
  106. });
  107. },
  108. // start () {
  109. //
  110. // },
  111. /// 每秒更新实时技能的使用时间
  112. updateSkilltime() {
  113. if (this.skill1Info && this.skill1Info.skillStatus == 1) {
  114. if (this.skill1Info.tdStarTime > 0) {
  115. this.skill1Info.tdStarTime -= (1 * 1000);
  116. if (this.skill1Info.tdStarTime <= 0) {
  117. this.skill1Info.tdStarTime = 0;
  118. this.skill1Info.skillStatus = 2;
  119. this.updateAutoGetGold();
  120. }
  121. } else {
  122. this.skill1Info.tdStarTime = 0;
  123. this.skill1Info.skillStatus = 2;
  124. this.updateAutoGetGold();
  125. }
  126. }
  127. if (this.skill3Info && this.skill3Info.skillStatus == 1) {
  128. if (this.skill3Info.tdStarTime > 0) {
  129. this.skill3Info.tdStarTime -= 1 * 1000;
  130. this.isUsingSkill3 = true;
  131. if (this.skill3Info.tdStarTime <= 0) {
  132. this.skill3Info.tdStarTime = 0;
  133. this.skill3Info.skillStatus = 2;
  134. this.multiple = {'n': 1, 'e': 0};
  135. this.updateClickGold();
  136. GameModule.userInfo.refreshSecondText();
  137. GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
  138. this.isUsingSkill3 = false;
  139. }
  140. } else {
  141. this.skill3Info.tdStarTime = 0;
  142. this.skill3Info.skillStatus = 2;
  143. this.multiple = {'n': 1, 'e': 0};
  144. this.updateClickGold();
  145. GameModule.userInfo.refreshSecondText();
  146. GameEvent.fire(GameNotificationKey.SkillThreeHasDone);
  147. this.isUsingSkill3 = false;
  148. }
  149. } else {
  150. this.isUsingSkill3 = false;
  151. }
  152. },
  153. // update (dt) {
  154. // },
  155. //更新每秒自动点击生成金币的速率
  156. updateAutoGetGold() {
  157. var second = 1;
  158. var click = 0;
  159. var skill1 = this.getSkill1Ability();
  160. if (skill1 != null) {
  161. click += skill1.cc / skill1.iv;
  162. }
  163. var skill4 = this.getSkill4Ability();
  164. if (skill4 != null) {
  165. click += skill4.cc / skill4.iv;
  166. }
  167. if (click > 0) {
  168. GameModule.userInfo.secondClick = second / click;
  169. } else {
  170. GameModule.userInfo.secondClick = 0;
  171. }
  172. },
  173. //更新每次点击生成金币的数量
  174. updateClickGold() {
  175. var clickGold = this.getBuildingGold();
  176. clickGold = clickGold * this.getSkill5Ability();
  177. let coinTap = TapTapTool.multiple({'n': clickGold, 'e': 0}, this.multiple);
  178. GameModule.userInfo.coinTap = TapTapTool.multiple(coinTap, GameModule.userInfo.perpetualClickMt);
  179. GameModule.userInfo.refreshSecondText();
  180. },
  181. //总部大楼等级技能
  182. getBuildingGold() {
  183. this.userBuildingLevel = GameModule.userInfo.buildingLevel;
  184. let clickGold = 9 + this.userBuildingLevel;
  185. return clickGold;
  186. },
  187. //主动释放技能1,多少分钟内每秒自动点击多少次
  188. getSkill1Ability() {
  189. if (this.skill1Info == undefined || this.skill1Info.skillLevel <= 0 ) {
  190. return null;
  191. }
  192. if (this.skill1Info.skillStatus != 1 || this.skill1Info.tdStarTime == 0) {
  193. return null;
  194. }
  195. let skillInfo = Global.BuildingManager.getSkillLevelInfo(this.skill1Info.skillId, this.skill1Info.skillLevel);
  196. return skillInfo;
  197. },
  198. //主动释放技能3,增加加成倍数
  199. getSkill3Ability() {
  200. if (this.skill3Info == undefined || this.skill3Info.skillLevel <= 0 ) {
  201. return null;
  202. }
  203. if (this.skill3Info.skillStatus != 1 || this.skill3Info.tdStarTime == 0) {
  204. return null;
  205. }
  206. let skillInfo = Global.BuildingManager.getSkillLevelInfo(this.skill3Info.skillId, this.skill3Info.skillLevel);
  207. this.multiple = {'n': skillInfo.mt, 'e': 0};
  208. GameModule.userInfo.multiple = this.multiple;
  209. this.updateClickGold();
  210. },
  211. //永久技能1,指定时间内自动点击次数
  212. getSkill4Ability() {
  213. if (this.skill4Info == undefined || this.skill4Info.skillLevel <= 0 ) {
  214. return null;
  215. }
  216. let skillInfo = Global.BuildingManager.getSkillLevelInfo(this.skill4Info.skillId, this.skill4Info.skillLevel);
  217. return skillInfo;
  218. },
  219. //永久技能2,每次点击产出的金币提升
  220. getSkill5Ability() {
  221. if (this.skill5Info == undefined || this.skill5Info.skillLevel <= 0 ) {
  222. return 1;
  223. }
  224. let skillInfo = Global.BuildingManager.getSkillLevelInfo(this.skill5Info.skillId, this.skill5Info.skillLevel);
  225. let mt = skillInfo.mt;
  226. return mt;
  227. },
  228. //永久技能3,减少CD时间
  229. getSkill6Ability() {
  230. let skillInfo = this.skills.find(n => {
  231. return n.skillId == 6;
  232. });
  233. skillInfo = Global.BuildingManager.getSkillLevelInfo(skillInfo.skillId, skillInfo.skillLevel);
  234. let rcd = (1 - skillInfo.rcd);
  235. return rcd;
  236. },
  237. });