SkillFixed.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import CMath from "../../../../util/CMath";
  2. import BObject from "../../bullet/BObject";
  3. import FSprite, { SpriteActionType, SpriteType } from "../FSprite";
  4. import SkillBase from "./SkillBase";
  5. /**
  6. * 点射
  7. */
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class SkillFixed extends SkillBase {
  11. /**
  12. * 每次攻击几颗子弹
  13. */
  14. @property({
  15. displayName: '每次攻击子弹数量'
  16. })
  17. public count = 1;
  18. @property({
  19. displayName: '每颗子弹间隔时间'
  20. })
  21. public btime = 1;
  22. @property({
  23. type: cc.Prefab,
  24. displayName: '子弹'
  25. })
  26. mBullet: cc.Prefab = null;
  27. /**
  28. * 释放技能
  29. */
  30. public exe(target: FSprite, callback: () => void) {
  31. this.time = new Date().getTime();
  32. // this.sprite.setDir({ x: 0, y: 0 });
  33. //-----播放开始动画
  34. let bNode = cc.instantiate(this.mBullet)
  35. let bobject = bNode.getComponent(BObject)
  36. bobject.distance = this.range
  37. let sf = bobject.mStartEffect
  38. if (this.sprite) return
  39. let x = this.sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  40. let y = this.sprite.mAtkSite.worldY
  41. let pos = cc.v2(x, y);
  42. let sfNode = cc.instantiate(sf)
  43. sfNode.angle = this.sprite.wAngle
  44. sfNode.setPosition(pos);
  45. sfNode.parent = this.sprite.node
  46. let startSpine: sp.Skeleton = sfNode.getComponent(sp.Skeleton)
  47. startSpine.setCompleteListener(() => {
  48. startSpine.setCompleteListener(null);
  49. sfNode.destroy()
  50. callback()
  51. });
  52. if (startSpine.findAnimation('skill')) {
  53. startSpine.setAnimation(0, 'skill', false);
  54. } else {
  55. startSpine.setAnimation(0, 'atk', false);
  56. }
  57. //----开始动画播放结束
  58. this.sprite.playAction(SpriteActionType.atk, false, () => {
  59. // this.AI.walk(this.range);
  60. this.sprite.playAction(SpriteActionType.stand, true)
  61. });
  62. let tp = target.node.getPosition();
  63. for (let i = 0; i < this.count; i++) {
  64. this.fire(i, tp);
  65. }
  66. }
  67. public fire(index, tp: cc.Vec2) {
  68. this.fireBullet(index, tp);
  69. }
  70. private fireBullet(index, p2) {
  71. for (let i = 0; i < this.count; i++) {
  72. cc.tween(this).sequence(
  73. cc.delayTime(i * this.btime),
  74. cc.callFunc(() => {
  75. this.fireBulletByTime(index, p2);
  76. })
  77. ).start();
  78. }
  79. }
  80. private fireBulletByTime(index, p2) {
  81. let node = cc.instantiate(this.mBullet);
  82. node.group = 'bullet'
  83. let sprite = this.sprite
  84. let x = sprite.node.x + sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  85. let y = sprite.node.y + sprite.mAtkSite.worldY
  86. let pos = cc.v2(x, y);
  87. node.setPosition(pos);
  88. let bObject = node.getComponent(BObject);
  89. bObject.setSprite(this.sprite);
  90. bObject.distance = this.range
  91. bObject.speed = this.speed;
  92. node.parent = this.sprite.map.mSprites;
  93. let p1 = node.getPosition();
  94. let angle = CMath.getAngle(p1, p2);
  95. // let cur = index - Math.floor(this.count / 2);
  96. // angle += cur * this.rotate;
  97. bObject._skillData = this._skillData
  98. bObject.fireAngle(angle);
  99. }
  100. }