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. let x = this.sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  39. let y = this.sprite.mAtkSite.worldY
  40. let pos = cc.v2(x, y);
  41. let sfNode = cc.instantiate(sf)
  42. sfNode.angle = this.sprite.wAngle
  43. sfNode.setPosition(pos);
  44. sfNode.parent = this.sprite.node
  45. let startSpine: sp.Skeleton = sfNode.getComponent(sp.Skeleton)
  46. startSpine.setCompleteListener(() => {
  47. startSpine.setCompleteListener(null);
  48. sfNode.destroy()
  49. callback()
  50. });
  51. if(startSpine.findAnimation('skill')){
  52. startSpine.setAnimation(0, 'skill', false);
  53. }else{
  54. startSpine.setAnimation(0, 'atk', false);
  55. }
  56. //----开始动画播放结束
  57. this.sprite.playAction(SpriteActionType.atk, false, () => {
  58. // this.AI.walk(this.range);
  59. this.sprite.playAction(SpriteActionType.stand,true)
  60. });
  61. let tp = target.node.getPosition();
  62. for (let i = 0; i < this.count; i++) {
  63. this.fire(i, tp);
  64. }
  65. }
  66. public fire(index, tp: cc.Vec2) {
  67. this.fireBullet(index, tp);
  68. }
  69. private fireBullet(index, p2) {
  70. for (let i = 0; i < this.count; i++) {
  71. cc.tween(this).sequence(
  72. cc.delayTime(i * this.btime),
  73. cc.callFunc(() => {
  74. this.fireBulletByTime(index, p2);
  75. })
  76. ).start();
  77. }
  78. }
  79. private fireBulletByTime(index, p2) {
  80. let node = cc.instantiate(this.mBullet);
  81. node.group = 'bullet'
  82. let sprite = this.sprite
  83. let x = sprite.node.x + sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  84. let y = sprite.node.y + sprite.mAtkSite.worldY
  85. let pos = cc.v2(x, y);
  86. node.setPosition(pos);
  87. let bObject = node.getComponent(BObject);
  88. bObject.setSprite(this.sprite);
  89. bObject.distance = this.range
  90. bObject.speed = this.speed;
  91. node.parent = this.sprite.map.mSprites;
  92. let p1 = node.getPosition();
  93. let angle = CMath.getAngle(p1, p2);
  94. // let cur = index - Math.floor(this.count / 2);
  95. // angle += cur * this.rotate;
  96. bObject._skillData = this._skillData
  97. bObject.fireAngle(angle);
  98. }
  99. }