SkillBuyAlert.js 3.2 KB

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