JG0111_1.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import FqLogin from "../../../login/FqLogin";
  2. import { AudioMgr } from "../../../main/ViewManage";
  3. import BaseEvent from "../../fight/evnet/base/BaseEvent";
  4. import { SpriteActionType } from "../../fight/object/FSprite";
  5. /**
  6. * 多组按钮控制开门-解救宠物剧情
  7. */
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class JG0111_1 extends BaseEvent {
  11. @property({
  12. displayName: '替换的图片',
  13. type: cc.Sprite,
  14. })
  15. mIcon: cc.Sprite = null;
  16. @property({
  17. displayName: '未踩上图片',
  18. type: cc.SpriteFrame,
  19. })
  20. mIcon0: cc.SpriteFrame = null;
  21. @property({
  22. displayName: '踩上后的图片',
  23. type: cc.SpriteFrame,
  24. })
  25. mIcon1: cc.SpriteFrame = null;
  26. /**
  27. * 控制的地刺
  28. */
  29. @property({
  30. displayName: '控制的地刺',
  31. type: [cc.Node],
  32. })
  33. mFenceTrigger: Array<cc.Node> = [];
  34. @property({
  35. displayName: '困住的宠物',
  36. type: cc.Node,
  37. })
  38. mPet: cc.Node = null;
  39. @property({
  40. displayName: '对话用NPC',
  41. type: cc.Node,
  42. })
  43. mNpc: cc.Node = null;
  44. /**
  45. * 控制的地刺
  46. */
  47. @property({
  48. displayName: '控制的机关',
  49. type: [cc.Node],
  50. })
  51. mFenceTrigger1: Array<cc.Node> = [];
  52. /**
  53. * 机关是否已经结束
  54. */
  55. public isOver = false;
  56. private count = 0;
  57. onLoad() {
  58. super.onLoad();
  59. this.node.zIndex = -9999;
  60. this.mNpc.active = false;
  61. }
  62. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  63. if (other.node.group != 'bullet') {
  64. this.count++
  65. this.onBegin(self.tag)
  66. }
  67. }
  68. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  69. if (other.node.group != 'bullet') {
  70. this.count--
  71. if (this.count <= 0) {
  72. this.count = 0;
  73. this.onEnd(self.tag)
  74. }
  75. }
  76. }
  77. onBegin(tag: number) {
  78. this.mIcon.spriteFrame = this.mIcon1;
  79. this.checkOpen();
  80. }
  81. onEnd(tag: number) {
  82. }
  83. private checkOpen() {
  84. if (this.isOver) {
  85. return
  86. }
  87. this.isOver = true;
  88. this.pause();
  89. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  90. cc.tween(this.node).sequence(
  91. cc.callFunc(() => {
  92. this.showFence(this.mFenceTrigger[0], 'down');
  93. let nodes = this.mFenceTrigger[1].children
  94. for (let i = 0; i < nodes.length; i++) {
  95. const element = nodes[i];
  96. this.showFence(element, 'down');
  97. }
  98. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  99. }),
  100. cc.delayTime(1),
  101. cc.callFunc(() => {
  102. this.mFenceTrigger[0].getComponent(cc.PhysicsBoxCollider).enabled = false;
  103. this.startPlot()
  104. })
  105. ).start();
  106. })
  107. }
  108. private showFence(element, action) {
  109. let nodes = element.children;
  110. for (let i = 0; i < nodes.length; i++) {
  111. const element = nodes[i];
  112. let spine: sp.Skeleton = element.getComponent(sp.Skeleton);
  113. if (spine) {
  114. spine.setAnimation(0, action, false);
  115. }
  116. }
  117. }
  118. /**
  119. * 开始剧情
  120. * 1.NPC从左边移动出现
  121. */
  122. private startPlot() {
  123. this.mNpc.active = true;
  124. cc.tween(this.mNpc).sequence(
  125. cc.moveTo(1, cc.v2(3180, 5870)),
  126. cc.callFunc(() => {
  127. this.dialog1()
  128. })
  129. ).start()
  130. let mainSprite = this.ff.mainSprite
  131. mainSprite.setLR(-1)
  132. mainSprite.playAction(SpriteActionType.run, true)
  133. cc.tween(mainSprite.node).sequence(
  134. cc.moveTo(1, cc.v2(3388, 5813)),
  135. cc.callFunc(() => {
  136. mainSprite.playAction(SpriteActionType.stand, true)
  137. })
  138. ).start()
  139. }
  140. /**
  141. * 落单的精灵:太好了太好了!!(落单的精灵鼓掌)
  142. 落单的精灵:你成功救出了这头小鹿,我之前尝试了很多次都无法成功。
  143. 落单的精灵:不得不承认,你出乎了我的意料。
  144. */
  145. private dialog1() {
  146. let text = [
  147. '太好了太好了!!',
  148. '你成功救出了这头小鹿,我之前尝试了很多次都无法成功。',
  149. '不得不承认,你出乎了我的意料。'
  150. ]
  151. this.showDialog(this.mNpc, text, () => {
  152. this.escape()
  153. })
  154. }
  155. /**
  156. * 小鹿逃跑
  157. */
  158. private escape() {
  159. for (let i = 0; i < this.mFenceTrigger1.length; i++) {
  160. const element = this.mFenceTrigger1[i];
  161. element.active = false
  162. }
  163. let spine = this.mPet.getComponent(sp.Skeleton)
  164. spine.setAnimation(0, SpriteActionType.run, true);
  165. cc.tween(this.mPet).sequence(
  166. cc.moveBy(1,cc.v2(0,-500)),
  167. cc.callFunc(()=>{
  168. this.dialog2()
  169. }),
  170. cc.destroySelf()
  171. ).start()
  172. }
  173. private dialog2() {
  174. let text = [
  175. '逃跑了……',
  176. ]
  177. let mainSprite = this.ff.mainSprite
  178. this.showDialog(mainSprite.node, text, () => {
  179. this.dialog3()
  180. })
  181. }
  182. private dialog3() {
  183. let text = [
  184. '快追!!',
  185. ]
  186. this.showDialog(this.mNpc, text, () => {
  187. cc.tween(this.mNpc).sequence(
  188. cc.moveTo(1, cc.v2(3294, 5085)),
  189. cc.callFunc(() => {
  190. this.resume()
  191. }),
  192. cc.destroySelf()
  193. ).start()
  194. })
  195. }
  196. }