DefaultSkill.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { _decorator, Component, Node, Sprite, Label, RichText, SpriteFrame } from 'cc';
  2. import { DataSystem } from '../../core/data/DataSystem';
  3. import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
  4. import { CountDown } from '../../core/ui/CountDown';
  5. import { StringUtils } from '../../core/utils/StringUtils';
  6. import { Utils } from '../../core/utils/Utils';
  7. import { ConfigData } from '../../data/ConfigData';
  8. import { Hero_Client } from '../../hero/UserHeroData';
  9. import { MarshalData } from '../MarshalData';
  10. import { MarshalSkillSystem } from '../MarshalSkillSystem';
  11. import { GrayEffectNode } from './GrayEffectNode';
  12. const { ccclass, property } = _decorator;
  13. /**
  14. * 统帅页默认技能
  15. * @author 郑聂华
  16. */
  17. @ccclass('DefaultSkill')
  18. export class DefaultSkill extends Component {
  19. @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
  20. @property({ type: GrayEffectNode, displayName: "置灰脚本", tooltip: "置灰脚本" }) grayScr: GrayEffectNode = null;
  21. @property({ type: Sprite, displayName: "图_技能", tooltip: "图_技能" }) imgSkill: Sprite = null;
  22. @property({ type: Sprite, displayName: "图_冷却进度", tooltip: "图_冷却进度" }) imgFillCool: Sprite = null;
  23. @property({ type: Node, displayName: "图_冷却进度指针", tooltip: "图_冷却进度指针" }) imgNeedle: Node = null;
  24. @property({ type: Label, displayName: "文本_冷却计时器", tooltip: "文本_冷却计时器" }) txtTimeCool: Label = null;
  25. @property({ type: RichText, displayName: "文本_技能名称", tooltip: "文本_技能名称" }) txtRichName: RichText = null;
  26. @property({ type: RichText, displayName: "文本_技能描述", tooltip: "文本_技能描述" }) txtRichDes: RichText = null;
  27. @property({ type: CountDown, displayName: "倒计时组件", tooltip: "倒计时组件" }) countDown: CountDown = null;
  28. @property({ type: Node, displayName: "锁", tooltip: "锁" }) nodeLock: Node = null;
  29. private cfg: any;
  30. private remaindTime = 0;
  31. private isExistMarshal: boolean;
  32. onLoad() {
  33. this.cfg = DataSystem.getData(ConfigData).get("serverConfig");
  34. }
  35. /**更新信息
  36. * @param hero 武将
  37. * @param skillId 技能id
  38. * @param lv 技能等级
  39. * @param isExistMarshal 是否存在统帅
  40. */
  41. public async updateInfo(hero: Hero_Client, skillId: number, lv: number, isExistMarshal: boolean) {
  42. this.isExistMarshal = isExistMarshal;
  43. let tempLv = lv < 0 ? 1 : lv;
  44. let marshalData = DataSystem.getData(MarshalData);
  45. let skillData = marshalData.skillData[skillId];
  46. this.updateCheckSkillCd();
  47. if (!this.countDown.running && this.remaindTime) { this.countDown.value = this.remaindTime; this.countDown.play(); }
  48. this.txtRichName.string = `<color=#4E301B>${skillData.name}</c><color=#E6181A>Lv.${tempLv}${tempLv == 3 ? "Max" : ""}</color>`;
  49. let addStr = MarshalSkillSystem.getSkillAddValueStr(skillData, tempLv, hero);
  50. let skillValueStr = MarshalSkillSystem.getSkillValueStr(skillData, tempLv);
  51. let totalSkillStr = `${skillValueStr + (isExistMarshal ? "(+" + addStr + ")" : "")}`;
  52. let desStr = StringUtils.format(skillData.des, totalSkillStr);
  53. desStr = StringUtils.getRichText(desStr);
  54. //desStr = desStr.replace("$0", totalSkillStr);
  55. this.txtRichDes.string = desStr;
  56. (lv < 0 || !isExistMarshal) && this.lockSkill();
  57. this.imgSkill.spriteFrame = await this.res.load<SpriteFrame>("images/skill/" + skillData.icon + "/spriteFrame", SpriteFrame);
  58. }
  59. update() {
  60. this.watchDefaultSkillCd();
  61. }
  62. watchDefaultSkillCd() {
  63. if (DataSystem.watch(MarshalData, "skillCoolingTime")) {
  64. this.updateCheckSkillCd();
  65. this.remaindTime == 0 && this.countDown.stop();
  66. }
  67. }
  68. /**更新技能cd*/
  69. updateCheckSkillCd() {
  70. let marshalData = DataSystem.getData(MarshalData);
  71. let date = new Date();
  72. let detlaTime = date.getTime() - marshalData.skillCoolingTime;
  73. if (detlaTime >= this.cfg.skillCD * 1000) {
  74. this.remaindTime = 0;
  75. } else {
  76. this.remaindTime = this.cfg.skillCD - detlaTime * 0.001;
  77. }
  78. this.updateCdInfo();
  79. }
  80. /**倒计时更新方法*/
  81. public updateTxt(progress) {
  82. this.txtTimeCool.string = Utils.formatCountDown(progress * 1000);
  83. this.imgNeedle.angle = 360 / this.cfg.skillCD * progress;
  84. }
  85. /**倒计时结束方法*/
  86. public async finishCooling() {
  87. this.remaindTime = 0;
  88. this.updateCdInfo();
  89. }
  90. updateCdInfo() {
  91. this.imgNeedle.active = this.isExistMarshal && this.remaindTime > 0;
  92. this.imgFillCool.node.active = this.imgNeedle.active = this.isExistMarshal && this.remaindTime > 0;
  93. this.txtTimeCool.string = (this.isExistMarshal && this.remaindTime > 0) ? Utils.formatCountDown(this.remaindTime * 1000) : "";
  94. this.imgNeedle.angle = 360 / DataSystem.getData(ConfigData).get("serverConfig").skillCD * this.remaindTime;
  95. }
  96. lockSkill() {
  97. this.nodeLock.active = true;
  98. this.grayScr.setGray();
  99. }
  100. unlockSkill() {
  101. this.grayScr.revert();
  102. this.nodeLock.active = false;
  103. }
  104. }