MMagic.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import BObject from "../../../bullet/BObject";
  2. import FSprite, { SpriteActionType } from "../../FSprite";
  3. import SkillBase from "../SkillBase";
  4. /**
  5. * 主角法术攻击
  6. */
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class MMagic extends SkillBase {
  10. /**
  11. * 法术效果
  12. */
  13. public mBullet: cc.Prefab
  14. onLoad() {
  15. this.sprite = this.node.getComponent(FSprite);
  16. }
  17. /**
  18. * 释放技能
  19. */
  20. public exe(target: FSprite,callback:()=>void) {
  21. this.time = new Date().getTime();
  22. // this.sprite.setDir({ x: 0, y: 0 });
  23. //-----播放开始动画
  24. let bNode = cc.instantiate(this.mBullet)
  25. let bobject = bNode.getComponent(BObject)
  26. let sf = bobject.mStartEffect
  27. let x = this.sprite.mAtkSite.worldX * this.sprite.spine.node.scaleX
  28. let y = this.sprite.mAtkSite.worldY
  29. let pos = cc.v2(x, y);
  30. let sfNode = cc.instantiate(sf)
  31. sfNode.angle = this.sprite.wAngle
  32. sfNode.setPosition(pos);
  33. sfNode.parent = this.sprite.node
  34. let startSpine: sp.Skeleton = sfNode.getComponent(sp.Skeleton)
  35. startSpine.setCompleteListener(() => {
  36. startSpine.setCompleteListener(null);
  37. sfNode.destroy()
  38. if(callback){
  39. callback()
  40. }
  41. });
  42. startSpine.setAnimation(0, 'atk', false);
  43. //----开始动画播放结束
  44. // this.sprite.playAction(SpriteActionType.atk, false, () => {
  45. // if(this.sprite.isWalk){
  46. // this.sprite.playAction(SpriteActionType.run,true)
  47. // }else{
  48. // this.sprite.playAction(SpriteActionType.stand,true)
  49. // }
  50. // });
  51. let tp = undefined
  52. if (target) {
  53. tp = target.node.getPosition();
  54. } else {
  55. let y = this.sprite.moveV2.y * 300 + this.node.y
  56. let x = this.sprite.moveV2.x * 300 + this.node.x;
  57. tp = cc.v2(x, y)
  58. }
  59. let map = this.sprite.ff.mMap;
  60. let hitNode = cc.instantiate(bobject.mHitEffect)
  61. hitNode.setPosition(tp)
  62. hitNode.parent = map.mSprites;
  63. let endSpine: sp.Skeleton = hitNode.children[0].getComponent(sp.Skeleton)
  64. endSpine.setCompleteListener(() => {
  65. endSpine.setCompleteListener(null);
  66. hitNode.destroy()
  67. });
  68. endSpine.setAnimation(0, 'animation', false);
  69. this.roundHit(hitNode)
  70. }
  71. /**
  72. * 炸开后周围受到伤害
  73. */
  74. public roundHit(hitNode:cc.Node) {
  75. let ff = this.sprite.ff
  76. let mGroup = this.sprite.getEnemyGroup();
  77. let nodes = ff.mMap.getSprites();
  78. // cc.log('this._skillData : ',this._skillData)
  79. for (let i = 0; i < nodes.length; i++) {
  80. const node = nodes[i];
  81. let target = node.getComponent(FSprite);
  82. if (target && node.active && target.isActive && target.hp > 0 && target.node.group == mGroup) {
  83. let dis = cc.Vec2.distance(hitNode.getPosition(), node.getPosition());
  84. if (dis < 300) {
  85. if (target.hp > 0) {
  86. if (target != null && target.isActive) {
  87. this.sprite.atkjs(target, this._skillData);
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }