SkillOptCell.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /** @format */
  2. import FightCore from '../zuma/FightCore'
  3. import {CardSkillConfig, ICardSkillConfig} from '../config/CardSkillConfig'
  4. import {Data} from '../GameControl'
  5. import {ICard} from '../interface/GlobalInterface'
  6. const {ccclass, property} = cc._decorator
  7. @ccclass
  8. export class SkillOptCell extends cc.Component {
  9. mask: cc.Sprite = null //技能精灵
  10. timeLb: cc.Label = null //显示技能冷却剩余时间的文字
  11. time: number = 1 //技能冷却时间
  12. countDown: number = 0
  13. showTime: boolean = false //是否显示文字
  14. isStop: boolean = true //是否停止
  15. iCard: ICard
  16. fightCore: FightCore
  17. onLoad() {
  18. this.mask = cc.find('mask', this.node).getComponent(cc.Sprite)
  19. this.timeLb = cc.find('timeLb', this.node).getComponent(cc.Label)
  20. this.timeLb.node.active = this.showTime
  21. this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchStart, this)
  22. }
  23. update(dt: number) {
  24. dt *= Data.game.gameSpeed
  25. if (!this.isStop && !this.fightCore.isStop) {
  26. this.countDown -= dt
  27. if (this.countDown <= 0) {
  28. this.countDown = 0
  29. this.isStop = true
  30. if (this.iCard) {
  31. }
  32. }
  33. this.mask.fillRange = this.time > 0 ? this.countDown / this.time : 0 //恢复技能
  34. this.timeLb.string = this.countDown > 0 ? (this.mask.fillRange * this.time).toFixed(1) : '' //更新技能冷却时间
  35. }
  36. }
  37. init(iCard: ICard, fightCore: FightCore) {
  38. this.fightCore = fightCore
  39. this.iCard = iCard
  40. this.time = this.iCard.cfg.startCD
  41. this.countDown = this.time
  42. this.mask.fillRange = 0
  43. this.isStop = true
  44. this.resetNode()
  45. }
  46. startCD() {
  47. this.time = this.iCard.cfg.skillCDs[0]
  48. this.countDown = this.time
  49. this.isStop = false
  50. this.resetNode()
  51. }
  52. onTouchStart(e: cc.Event.EventTouch): void {
  53. if (!this.iCard) return
  54. this.fightCore.skillOptShow(this)
  55. cc.find('popChoose', this.node).active = true
  56. }
  57. resetNode() {
  58. this.node.stopAllActions()
  59. cc.find('light', this.node).active = false
  60. cc.find('popChoose', this.node).active = false
  61. }
  62. showCreateAni() {
  63. cc.find('light', this.node).active = true
  64. }
  65. }