FCage.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import FSprite, { SpriteActionType } from "../../object/FSprite";
  2. import PSprite from "../../object/PSprite";
  3. import WOneByone from ".././map1/WOneByone";
  4. import BaseEvent from ".././base/BaseEvent";
  5. /**
  6. * 牢笼,可解救伙伴
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class FCage extends BaseEvent {
  11. @property(cc.Prefab)
  12. mMapDialog: cc.Prefab = null;
  13. @property(sp.Skeleton)
  14. spine: sp.Skeleton = null;//牢笼
  15. @property(cc.Node)
  16. mPet: cc.Node = null;//伙伴
  17. @property({
  18. type:[cc.Prefab],
  19. displayName: '解救的对象'
  20. })
  21. mMonster: Array<cc.Prefab> = [];
  22. @property(cc.Node)
  23. guides: Array<cc.Node> = [];//引导标识
  24. @property({
  25. displayName: '靠近的提示',
  26. type:cc.Sprite
  27. })
  28. mIcon: cc.Sprite = null;//靠近后的提示
  29. @property({
  30. type:[cc.SpriteFrame],
  31. displayName: '不同状态的图标'
  32. })
  33. mIconFrame: Array<cc.SpriteFrame> = [];
  34. @property({
  35. displayName: '提示图标',
  36. type:cc.SpriteFrame
  37. })
  38. mTipsIcon: cc.SpriteFrame = null;
  39. private isOver = false;
  40. onLoad() {
  41. super.onLoad()
  42. if(this.mIcon){
  43. this.mIcon.node.active = false;
  44. }
  45. }
  46. onBegin(tag:number){
  47. if(this.isOver){
  48. return;
  49. }
  50. if(tag == 1){
  51. this.showButton();
  52. }
  53. }
  54. onEnd(tag:number){
  55. if(tag == 1){
  56. this.closeButton();
  57. }
  58. }
  59. public showButton(){
  60. this.iconTips(true);
  61. this.showOpt(this.mTipsIcon,()=>{
  62. this.openCage()
  63. })
  64. }
  65. public closeButton(){
  66. this.iconTips(false);
  67. this.closeOpt()
  68. }
  69. /**
  70. *
  71. * @param show 是否显示提示
  72. */
  73. private iconTips(show){
  74. if(this.mIcon){
  75. if(show){
  76. this.mIcon.node.active = true;
  77. let head = this.ff.mFFheader;
  78. let count = head.getTmpCount(2001);
  79. if(count > 0){
  80. this.mIcon.spriteFrame = this.mIconFrame[0]
  81. }else{
  82. this.mIcon.spriteFrame = this.mIconFrame[1]
  83. }
  84. }else{
  85. this.mIcon.node.active = false;
  86. }
  87. }
  88. }
  89. /**
  90. * 事件结束,清除事件
  91. */
  92. public delEvent(){
  93. this.node.removeComponent(cc.PhysicsBoxCollider);
  94. }
  95. //打开牢笼
  96. private openCage(){
  97. this.closeButton();
  98. let head = this.ff.mFFheader;
  99. let count = head.getTmpCount(2001);
  100. if(count > 0){
  101. this.isOver = true;
  102. for (let i = 0; i < this.guides.length; i++) {
  103. const element = this.guides[i];
  104. element.destroy();
  105. }
  106. this.guides = [];
  107. this.spine.setCompleteListener(() => {
  108. this.spine.setCompleteListener(null);
  109. this.startStory();
  110. });
  111. this.spine.setAnimation(0, 'open', false);
  112. }else{
  113. this.ff.main.showTips('我需要一把牢笼钥匙');
  114. }
  115. }
  116. public startStory(){
  117. /**
  118. * 暂停所有
  119. */
  120. this.ff.pauseSprite(true);
  121. this.ff.mBlockInputEvents.active = true;
  122. this.movePet();
  123. }
  124. private movePet(){
  125. let anim = this.mPet.getComponent(cc.Animation);
  126. let spine = this.mPet.getComponent(sp.Skeleton);
  127. spine.setAnimation(0, SpriteActionType.run, true);
  128. anim.on('finished',this.onFinished,this);
  129. anim.play('cage_pet_move');
  130. }
  131. private onFinished(num, string){
  132. let anim = this.mPet.getComponent(cc.Animation);
  133. let spine = this.mPet.getComponent(sp.Skeleton);
  134. anim.off('finished',this.onFinished,this);
  135. spine.setAnimation(0, SpriteActionType.stand, true);
  136. this.showDialog2();
  137. }
  138. private showDialog2(){
  139. let dialogs = [
  140. '伟大的古尔薇格,谢谢你把小女巫送来',
  141. '我是琳达,这是鲍西',
  142. '敌人抓我们时,为了保护我,这个傻子冲到了最前面第一个被打晕了,我也被他们抓了',
  143. '还好你及时赶到,救了我们',
  144. '我们还有个同伴,露西,正在前面与敌人作战',
  145. '请你过去帮帮她',
  146. ];
  147. let node = cc.instantiate(this.mMapDialog);
  148. node.group = 'map'
  149. node.zIndex = 9999;
  150. node.x = this.node.x + this.mPet.x;
  151. node.y = this.node.y + this.mPet.y + this.mPet.height;
  152. node.parent = this.ff.mMap.mSprites;
  153. let obo = node.getComponent(WOneByone);
  154. obo.dialogs = dialogs;
  155. obo.setCallback(()=>{
  156. node.destroy();
  157. this.ff.setBlockInputCallback(null);
  158. this.ff.pauseSprite(false);
  159. this.ff.mBlockInputEvents.active = false;
  160. this.node.removeComponent(cc.PhysicsBoxCollider);
  161. // this.getPet();
  162. });
  163. this.ff.setBlockInputCallback(()=>{
  164. obo.jump();
  165. });
  166. obo._start();
  167. }
  168. /**
  169. * 解救伙伴
  170. */
  171. private getPet(){
  172. this.delEvent()
  173. let head = this.ff.mFFheader;
  174. let mainSprite = this.ff.mainSprite;
  175. let pos = mainSprite.node.getPosition()
  176. pos.x -= this.node.x;
  177. pos.y -= this.node.y;
  178. let spine = this.mPet.getComponent(sp.Skeleton);
  179. spine.setAnimation(0, SpriteActionType.run, true);
  180. cc.tween(this.mPet).sequence(
  181. cc.moveTo(1,pos),
  182. cc.callFunc(()=>{
  183. head.removeTmpGood(2001,1);
  184. this.mPet.removeFromParent();
  185. this.mMonster.forEach(element => {
  186. let node = cc.instantiate(element);
  187. let sp = node.getComponent(PSprite);
  188. this.ff.addRole(sp);
  189. });
  190. })
  191. ).start()
  192. }
  193. }