FCagePet1.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import FqLogin from "../../../../login/FqLogin";
  2. import { AudioMgr } from "../../../../main/ViewManage";
  3. import FFCalAttr from "../../../data/FFCalAttr";
  4. import AIPet from "../../object/AI/AIPet";
  5. import { GroupType } from "../../object/FObject";
  6. import { SpriteActionType } from "../../object/FSprite";
  7. import PSprite from "../../object/PSprite";
  8. import BaseEvent from "../base/BaseEvent";
  9. const { ccclass, property } = cc._decorator;
  10. /**
  11. * 第一个宠物牢笼
  12. */
  13. @ccclass
  14. export default class FCagePet1 extends BaseEvent {
  15. @property({
  16. displayName: '解救的伙伴id',
  17. })
  18. mPetId: number = 1;
  19. @property({
  20. displayName: '没有钥匙的对话',
  21. type: [cc.String]
  22. })
  23. dialog1: Array<string> = [];
  24. @property({
  25. displayName: '牢笼动画',
  26. tooltip: '显示牢笼的动画',
  27. type: sp.Skeleton
  28. })
  29. spine: sp.Skeleton = null;//牢笼
  30. @property({
  31. displayName: '按钮图标',
  32. type: cc.SpriteFrame
  33. })
  34. mTipsIcon: cc.SpriteFrame = null;
  35. @property({
  36. displayName: '靠近的提示',
  37. type: cc.Sprite
  38. })
  39. mIcon: cc.Sprite = null;//靠近后的提示
  40. @property({
  41. type: [cc.SpriteFrame],
  42. displayName: '不同状态的图标'
  43. })
  44. mIconFrame: Array<cc.SpriteFrame> = [];
  45. @property({
  46. displayName: '牢笼中的伙伴',
  47. type: cc.Node
  48. })
  49. mPet: cc.Node = null;//伙伴
  50. @property({
  51. displayName: '解救出来的对话',
  52. type: [cc.String]
  53. })
  54. dialog2: Array<string> = [];
  55. @property({
  56. displayName: '宠物预制体',
  57. type: cc.Prefab
  58. })
  59. mPetPrefab: cc.Prefab = null;
  60. @property({
  61. type: [cc.Node],
  62. displayName: '需要打开的门'
  63. })
  64. mFenceTrigger: Array<cc.Node> = [];
  65. @property({
  66. displayName: 'npc',
  67. type: cc.Node
  68. })
  69. mNPC2: cc.Node = null;
  70. private isOver = false;
  71. onBegin(tag: number) {
  72. if (this.isOver) {
  73. return;
  74. }
  75. if (tag == 1) {
  76. this.iconTips(true);
  77. this.showOpt(this.mTipsIcon, () => {
  78. this.iconTips(false);
  79. this.closeOpt()
  80. this.openCage()
  81. })
  82. }
  83. }
  84. onEnd(tag: number) {
  85. if (tag == 1) {
  86. this.iconTips(false);
  87. this.closeOpt()
  88. }
  89. }
  90. /**
  91. *
  92. * @param show 是否显示提示
  93. */
  94. private iconTips(show) {
  95. if (this.mIcon) {
  96. if (show) {
  97. this.mIcon.node.active = true;
  98. let head = this.ff.mFFheader;
  99. let count = head.getTmpCount(2001);
  100. if (count > 0) {
  101. this.mIcon.spriteFrame = this.mIconFrame[0]
  102. } else {
  103. this.mIcon.spriteFrame = this.mIconFrame[1]
  104. }
  105. } else {
  106. this.mIcon.node.active = false;
  107. }
  108. }
  109. }
  110. //打开牢笼
  111. private openCage() {
  112. let head = this.ff.mFFheader;
  113. let count = head.getTmpCount(2001);
  114. if (count > 0) {
  115. head.removeTmpGood(2001, 1);
  116. this.isOver = true;
  117. this.spine.setCompleteListener(() => {
  118. this.spine.setCompleteListener(null);
  119. this.showDialog(this.node,this.dialog2,()=>{
  120. this.movePet()
  121. })
  122. });
  123. if (this.spine.findAnimation("open3")) {
  124. this.spine.setAnimation(0, 'open3', false);
  125. } else {
  126. this.spine.setAnimation(0, 'open', false);
  127. }
  128. FqLogin.commitEvent(this.node.name, '', '');
  129. } else {
  130. // this.ff.main.showTips('需要一把牢笼钥匙');
  131. this.showDialog(this.node,this.dialog1,()=>{
  132. })
  133. }
  134. }
  135. private movePet() {
  136. let anim = this.mPet.getComponent(cc.Animation);
  137. let spine = this.mPet.getComponent(sp.Skeleton);
  138. spine.setAnimation(0, SpriteActionType.run, true);
  139. anim.on('finished', this.onFinished, this);
  140. anim.play('cage_pet_move');
  141. }
  142. private onFinished(num, string) {
  143. let anim = this.mPet.getComponent(cc.Animation);
  144. let spine = this.mPet.getComponent(sp.Skeleton);
  145. anim.off('finished', this.onFinished, this);
  146. spine.setAnimation(0, SpriteActionType.stand, true);
  147. this.mPet.destroy()
  148. this.openDoor()
  149. }
  150. public openDoor(){
  151. this.pause()
  152. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  153. cc.tween(this.node).sequence(
  154. cc.callFunc(() => {
  155. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  156. const element = this.mFenceTrigger[i];
  157. this.showFence(element, 'open');
  158. }
  159. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  160. }),
  161. cc.delayTime(1),
  162. cc.callFunc(() => {
  163. this.resume()
  164. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  165. const element = this.mFenceTrigger[i];
  166. element.active = false;
  167. }
  168. })
  169. ).start();
  170. })
  171. }
  172. private showFence(element, action) {
  173. let nodes = element.children;
  174. for (let i = 0; i < nodes.length; i++) {
  175. const element = nodes[i];
  176. let spine = element.getComponent(sp.Skeleton);
  177. if (spine) {
  178. spine.setAnimation(0, action, false);
  179. }
  180. }
  181. }
  182. }