JG0108.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import BaseEvent from "../fight/evnet/base/BaseEvent";
  2. import FSprite from "../fight/object/FSprite";
  3. /**
  4. * 地刺
  5. */
  6. const { ccclass, property } = cc._decorator;
  7. interface ThornSprite {
  8. isAtk: boolean,
  9. sprite: FSprite
  10. }
  11. @ccclass
  12. export default class JG0108 extends BaseEvent {
  13. @property({
  14. displayName: '数值(怪物id)'
  15. })
  16. public monsterId = 1001;
  17. @property({
  18. displayName: '地刺出现间隔时间'
  19. })
  20. public interval = 2;
  21. @property({
  22. type: sp.Skeleton,
  23. displayName: '地刺动画'
  24. })
  25. public spine: sp.Skeleton = null;
  26. private isAtk = false;
  27. private isPause = false;
  28. //当前处于碰撞区域的对象
  29. private spriteList: Array<ThornSprite> = [];
  30. start() {
  31. this.run();
  32. }
  33. update(dt) {
  34. if (!this.ff.lockCamera) {
  35. if (!this.ff.lockCamera != this.isPause) {
  36. this.isPause = true;
  37. if (this.spine) {
  38. this.spine.paused = true;
  39. }
  40. return
  41. }
  42. } else {
  43. if (!this.ff.lockCamera != this.isPause) {
  44. this.isPause = false;
  45. if (this.spine) {
  46. this.spine.paused = false;
  47. }
  48. }
  49. }
  50. if (this.isAtk) {
  51. this.spriteList.forEach(element => {
  52. this.rmHP(element);
  53. });
  54. }
  55. }
  56. private rmHP(thornSprite: ThornSprite) {
  57. if (thornSprite.isAtk) {
  58. return;
  59. }
  60. if (thornSprite.sprite.hp <= 0) {
  61. return;
  62. }
  63. thornSprite.isAtk = true;
  64. let main = this.ff.main;
  65. let attrData = main.sManage.getMonsterData(this.monsterId);
  66. thornSprite.sprite.bAtkjs(attrData);
  67. }
  68. private run() {
  69. this.spriteList.forEach(element => {
  70. element.isAtk = false;
  71. });
  72. if (!this.interval) {
  73. this.isAtk = true;
  74. } else {
  75. cc.tween(this).sequence(
  76. cc.delayTime(this.interval),
  77. cc.callFunc(() => {
  78. this.playAtk();
  79. })
  80. ).start()
  81. }
  82. }
  83. private playAtk() {
  84. this.isAtk = true;
  85. this.spine.setAnimation(0, 'atk', false);
  86. this.spine.setCompleteListener(() => {
  87. this.isAtk = false;
  88. this.spine.setCompleteListener(null);
  89. this.spine.setAnimation(0, 'idle', true);
  90. this.run()
  91. });
  92. }
  93. onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  94. if (other.node.group == 'A') {
  95. let obj = other.node.getComponent(FSprite);
  96. this.ff = obj.ff;
  97. this.pushSprite(obj);
  98. }
  99. }
  100. onEndContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  101. if (other.node.group == 'A') {
  102. let obj = other.node.getComponent(FSprite);
  103. this.removeSprite(obj);
  104. }
  105. }
  106. private pushSprite(sprite: FSprite) {
  107. for (let i = 0; i < this.spriteList.length; i++) {
  108. const element = this.spriteList[i];
  109. if (element.sprite == sprite) {
  110. return
  111. }
  112. }
  113. this.spriteList.push({
  114. isAtk: false,
  115. sprite: sprite
  116. })
  117. }
  118. private removeSprite(sprite: FSprite) {
  119. for (let i = 0; i < this.spriteList.length; i++) {
  120. const element = this.spriteList[i];
  121. if (element.sprite == sprite) {
  122. this.spriteList.splice(i, 1);
  123. break
  124. }
  125. }
  126. }
  127. }