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. if (this._skillId <= 3) {
  45. } else {
  46. /// 如果升级永久技能
  47. let skillLevelInfo = Global.BuildingManager.getSkillLevelInfo(this._skillId, this._starItem.skillData.skillLevel);
  48. GameEvent.fire(GameNotificationKey.UpdateFixationSkill, skillLevelInfo);
  49. if (this._skillId == 5) {
  50. GameEvent.fire("skill_five_use");
  51. /// 使用最后一个减cd的
  52. } else if (this._skillId == 6) {
  53. Global.rcdSkillLevel += 1;
  54. GameEvent.fire("skill_six_use");
  55. }
  56. }
  57. this.node.destroy();
  58. console.log("升级技能成功");
  59. }).catch(({code, msg}) => {
  60. console.log(code, msg);
  61. Global.commonAlert.showCommonErrorAlert(msg);
  62. this.buyButton.interactable = true;
  63. });
  64. },
  65. closeAction() {
  66. GameModule.audioMng.playClickButton();
  67. this.node.destroy();
  68. },
  69. upSkill(skillId) {
  70. return new Promise((resolve, reject) => {
  71. // 获取目标用户的建筑
  72. SkillApi.upSkill(skillId, (respondData) => {
  73. resolve(respondData);
  74. }, (code, msg) => {
  75. reject({code, msg});
  76. });
  77. });
  78. },
  79. // update (dt) {},
  80. });