MBomb.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import CMath from "../../../../../util/CMath";
  2. import BBObject from "../../../bullet/BBObject";
  3. import BObject from "../../../bullet/BObject";
  4. import FSprite, { SpriteActionType } from "../../FSprite";
  5. import SkillBase from "../SkillBase";
  6. /**
  7. * 射出一个炸弹,击中后爆炸产生范围伤害
  8. */
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class MBomb extends SkillBase {
  12. /**
  13. * 法术效果
  14. */
  15. public mBullet: cc.Prefab
  16. onLoad() {
  17. this.sprite = this.node.getComponent(FSprite);
  18. }
  19. /**
  20. * 释放技能
  21. */
  22. public exe(target: FSprite,callback:()=>void) {
  23. this.time = new Date().getTime();
  24. // this.sprite.setDir({ x: 0, y: 0 });
  25. //-----播放开始动画
  26. let bNode = cc.instantiate(this.mBullet)
  27. let bobject = bNode.getComponent(BObject)
  28. let sf = bobject.mStartEffect
  29. let x = this.sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  30. let y = this.sprite.mAtkSite.worldY
  31. let pos = cc.v2(x, y);
  32. let sfNode = cc.instantiate(sf)
  33. sfNode.angle = this.sprite.wAngle
  34. sfNode.setPosition(pos);
  35. sfNode.parent = this.sprite.node
  36. let startSpine: sp.Skeleton = sfNode.getComponent(sp.Skeleton)
  37. startSpine.setCompleteListener(() => {
  38. startSpine.setCompleteListener(null);
  39. sfNode.destroy()
  40. if(callback){
  41. callback()
  42. }
  43. });
  44. startSpine.setAnimation(0, 'atk', false);
  45. //----开始动画播放结束
  46. this.sprite.playAction(SpriteActionType.atk, false, () => {
  47. if(this.sprite.isWalk){
  48. this.sprite.playAction(SpriteActionType.run,true)
  49. }else{
  50. this.sprite.playAction(SpriteActionType.stand,true)
  51. }
  52. });
  53. let tp = undefined
  54. if (target) {
  55. tp = target.node.getPosition();
  56. } else {
  57. let y = this.sprite.moveV2.y * 300 + this.node.y
  58. let x = this.sprite.moveV2.x * 300 + this.node.x;
  59. tp = cc.v2(x, y)
  60. }
  61. //向目标吹龙卷风
  62. if (target) {
  63. tp = target.node.getPosition();
  64. } else {
  65. let y = this.sprite.moveV2.y + this.node.y
  66. y += this.sprite.mAtkSite.worldY
  67. let x = this.sprite.moveV2.x + this.node.x;
  68. tp = cc.v2(x, y)
  69. }
  70. this.fireBulletByTime(tp)
  71. }
  72. /**
  73. *
  74. * @param p2 向目标发射
  75. */
  76. private fireBulletByTime(p2) {
  77. let node = cc.instantiate(this.mBullet);
  78. node.group = 'bullet'
  79. let sprite = this.sprite
  80. let x = sprite.node.x + sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  81. let y = sprite.node.y + sprite.mAtkSite.worldY
  82. let pos = cc.v2(x, y);
  83. node.setPosition(pos);
  84. let bObject = node.getComponent(BBObject);
  85. bObject.setSprite(this.sprite);
  86. bObject.speed = this.speed;
  87. node.parent = this.sprite.map.mSprites;
  88. let p1 = node.getPosition();
  89. let angle = CMath.getAngle(p1, p2);
  90. bObject._skillData = this._skillData
  91. bObject.fireAngle(angle);
  92. }
  93. }