SkillBuyAlert.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const SkillApi = require('../net/SkillApi');
  2. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  3. const GameModule = require("../utils/GameModule");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. skillNameRichText: cc.RichText,
  8. // 262424
  9. desc1RichText: cc.RichText,
  10. // #FD4700
  11. desc2RichText: cc.RichText,
  12. buyButton: cc.Button,
  13. buySprite: cc.Sprite,
  14. buyRichText: cc.RichText,
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. // onLoad () {},
  18. /// 上一级和下一级的技能信息
  19. init(skillInfo, nextSkillInfo, starItem) {
  20. this._skillId = skillInfo.skillId;
  21. this._starItem = starItem;
  22. let diamondCount = skillInfo.bonus[10002];
  23. /// 用的砖石
  24. if (diamondCount != undefined) {
  25. this.diamondCount = diamondCount;
  26. this.coinCount = {'n': 0, 'e': 0};
  27. this.building = 0;
  28. this.buyRichText.string = `<color=#ffffff>升级</c><br/><img src='skill_diamond'/><color=#ffffff>${diamondCount}钻石</c>`;
  29. }
  30. this.desc1RichText.string = `<color=#262424>立即获得\n${skillInfo.desc}</c>`;
  31. this.desc2RichText.string = `<color=#FD4700>立即获得\n${nextSkillInfo.desc}</c>`;
  32. this.skillNameRichText.string = `<b><color=#540904>${skillInfo.name}</c></b>`;
  33. },
  34. start () {
  35. },
  36. buyAction() {
  37. this.buyButton.interactable = false;
  38. GameModule.audioMng.playClickButton();
  39. this.upSkill(this._skillId).then(() => {
  40. this.buyButton.interactable = true;
  41. this._starItem.skillData.skillLevel += 1;
  42. this._starItem.updateGloabData();
  43. GameEvent.fire('skill_update');
  44. let skillLevelInfo = Global.BuildingManager.getSkillLevelInfo(this._skillId, this._starItem.skillData.skillLevel);
  45. if (this._skillId <= 3) {
  46. GameEvent.fire(GameNotificationKey.UpdateTimeSkill, skillLevelInfo);
  47. } else {
  48. /// 如果升级永久技能
  49. GameEvent.fire(GameNotificationKey.UpdateFixationSkill, skillLevelInfo);
  50. if (this._skillId == 5) {
  51. GameEvent.fire("skill_five_use");
  52. /// 使用最后一个减cd的
  53. } else if (this._skillId == 6) {
  54. Global.rcdSkillLevel += 1;
  55. GameEvent.fire("skill_six_use");
  56. }
  57. }
  58. this.node.destroy();
  59. console.log("升级技能成功");
  60. }).catch(({code, msg}) => {
  61. console.log(code, msg);
  62. Global.commonAlert.showCommonErrorAlert(msg);
  63. this.buyButton.interactable = true;
  64. });
  65. },
  66. closeAction() {
  67. GameModule.audioMng.playClickButton();
  68. this.node.destroy();
  69. },
  70. upSkill(skillId) {
  71. return new Promise((resolve, reject) => {
  72. // 获取目标用户的建筑
  73. SkillApi.upSkill(skillId, (respondData) => {
  74. resolve(respondData);
  75. }, (code, msg) => {
  76. reject({code, msg});
  77. });
  78. });
  79. },
  80. // update (dt) {},
  81. });