FBigBomb.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import FqLogin from "../../../../login/FqLogin";
  2. import FSprite from "../../object/FSprite";
  3. import BaseEvent from "../base/BaseEvent";
  4. const { ccclass, property } = cc._decorator;
  5. enum BoomStatus {
  6. safe, //安全阶段
  7. warning, //警告阶段
  8. boom, //爆炸阶段
  9. end, //爆炸结束
  10. }
  11. /**
  12. * 定时炸弹
  13. */
  14. @ccclass
  15. export default class FBigBomb extends BaseEvent {
  16. @property({
  17. displayName: "怪物ID"
  18. })
  19. monsterId: number = 0;
  20. @property({
  21. displayName: '提示图标',
  22. type: cc.SpriteFrame
  23. })
  24. mTipsIcon: cc.SpriteFrame = null;
  25. @property({
  26. displayName: "提示文字"
  27. })
  28. text: string = "";
  29. @property({
  30. displayName: "需要的物品ID"
  31. })
  32. goodId: number = 0;
  33. @property({
  34. displayName: '爆炸动画',
  35. type: sp.Skeleton
  36. })
  37. spine: sp.Skeleton = null;
  38. @property({
  39. displayName: "警告区域",
  40. })
  41. warningArea = new cc.Vec2();
  42. @property({
  43. displayName: "爆炸范围",
  44. })
  45. boomArea = new cc.Vec2();
  46. @property({
  47. displayName: "警告时间(秒)"
  48. })
  49. warningTime: number = 0;
  50. @property({
  51. displayName: "爆炸时间(秒)"
  52. })
  53. boomTime: number = 0;
  54. public spriteList: Array<FSprite> = [];
  55. isFire: boolean = false;
  56. boomStatus: BoomStatus = BoomStatus.safe;
  57. tempTime: number = 0;
  58. isHit: boolean = false;
  59. isWarning: boolean = false;
  60. start() {
  61. let boxs = this.node.getComponents(cc.PhysicsBoxCollider)
  62. boxs[0].size = new cc.Size(this.warningArea.x, this.warningArea.y);
  63. boxs[1].size = new cc.Size(this.boomArea.x, this.boomArea.y);
  64. }
  65. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  66. if (other.node.group == 'A' && self.tag == 1) {
  67. let obj = other.node.getComponent(FSprite);
  68. if (this.spriteList.indexOf(obj) == -1) {
  69. this.spriteList.push(obj);
  70. }
  71. }
  72. if (other.node.group == 'A' && other.tag == 1) {
  73. let obj = other.node.getComponent(FSprite);
  74. this.ff = obj.ff;
  75. if (self.tag == 0) {
  76. if (!this.isFire) {
  77. this.fire();
  78. }
  79. }
  80. }
  81. }
  82. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  83. if (other.node.group == 'A' && self.tag == 1) {
  84. let obj = other.node.getComponent(FSprite);
  85. this.removeSprite(obj);
  86. }
  87. if(self.tag == 0){
  88. this.closeOpt();
  89. }
  90. }
  91. private removeSprite(sprite: FSprite) {
  92. for (let i = 0; i < this.spriteList.length; i++) {
  93. const element = this.spriteList[i];
  94. if (element == sprite) {
  95. this.spriteList.splice(i, 1);
  96. break
  97. }
  98. }
  99. }
  100. fire() {
  101. let count = this.ff.mFFheader.getTmpCount(this.goodId);
  102. this.showOpt(this.mTipsIcon, () => {
  103. this.closeOpt();
  104. if (count > 0) {
  105. this.isFire = true;
  106. this.ff.mFFheader.removeTmpGood(this.goodId, 1);
  107. if (!this.isWarning) {
  108. this.warning();
  109. }
  110. } else {
  111. this.ff.main.showTips(this.text);
  112. }
  113. })
  114. }
  115. // 警告
  116. warning() {
  117. this.isWarning = true;
  118. this.spine.setAnimation(0, "boom1", true);
  119. this.boomStatus = BoomStatus.warning;
  120. let tempTime = 0;
  121. let call = () => {
  122. tempTime += 0.1;
  123. if (tempTime >= this.warningTime) {
  124. // console.log("===警告结束===");
  125. this.boom();
  126. this.unschedule(call);
  127. }
  128. }
  129. this.schedule(call, 0.1);
  130. }
  131. //爆炸
  132. boom() {
  133. this.spine.setAnimation(0, "boom2", false);
  134. this.boomStatus = BoomStatus.boom;
  135. let tempTime = 0;
  136. let call = () => {
  137. tempTime += 0.1;
  138. if (tempTime >= this.boomTime) {
  139. // console.log("===爆炸结束===");
  140. FqLogin.commitEvent(this.node.name, '', '');
  141. this.end();
  142. this.unschedule(call);
  143. } else {
  144. if (!this.isHit) {
  145. this.hit();
  146. }
  147. }
  148. }
  149. this.schedule(call, 0.1);
  150. }
  151. hit() {
  152. this.isHit = true;
  153. this.spriteList.forEach(sprite => {
  154. let main = this.ff.main;
  155. let attrData = main.sManage.getMonsterData(this.monsterId);
  156. sprite.bAtkjs(attrData)
  157. })
  158. }
  159. //爆炸结束
  160. end() {
  161. this.boomStatus = BoomStatus.end;
  162. this.node.active = false;
  163. }
  164. }