FExtra.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import { HttpStateType, ReveData } from "../../../../util/CHttp";
  2. import FF from "../../FF";
  3. import FMap from "../../map/FMap";
  4. import FSprite from "../../object/FSprite";
  5. import WOneByone from "../map1/WOneByone";
  6. /**
  7. * 打开附加关卡
  8. */
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class FExtra extends cc.Component {
  12. @property({
  13. type:cc.Integer,
  14. displayName: '附加关卡id'
  15. })
  16. public extraId:number = 1001;
  17. @property({
  18. type:cc.Node,
  19. displayName: '开启特效'
  20. })
  21. public spine:cc.Node = null;
  22. @property({
  23. type:cc.Node,
  24. displayName: '任务提示'
  25. })
  26. public iconTouch:cc.Node = null;
  27. /**
  28. * 控制的栅栏
  29. */
  30. @property([cc.Node])
  31. mFenceTrigger: Array<cc.Node> = [];
  32. @property(cc.Prefab)
  33. mMapDialog: cc.Prefab = null;
  34. private ff:FF
  35. private map:FMap;
  36. onLoad () {
  37. this.spine.active = false;
  38. this.map = this.node.parent.parent.getComponent(FMap);
  39. }
  40. start () {
  41. let ff = this.map.ff;
  42. let stage = ff.main.player.stage;
  43. if(stage.extraStage.indexOf(this.extraId) >= 0){
  44. this.node.active = false;
  45. this.mFenceTrigger.forEach(element => {
  46. element.active = false;
  47. });
  48. }else{
  49. this.node.active = true;
  50. }
  51. }
  52. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  53. if(other.node.group == 'A'){
  54. let obj = other.node.getComponent(FSprite);
  55. this.ff = obj.ff;
  56. if(obj == this.ff.mainSprite){
  57. this.showButton();
  58. }
  59. }
  60. }
  61. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  62. if(other.node.group == 'A'){
  63. let obj = other.node.getComponent(FSprite);
  64. this.ff = obj.ff;
  65. if(obj == this.ff.mainSprite){
  66. this.closeButton();
  67. }
  68. }
  69. }
  70. public showButton(){
  71. this.ff.control.mEventButton.node.active = true;
  72. this.ff.control.mEventButton.setCallback(()=>{
  73. this.startStory();
  74. });
  75. }
  76. public closeButton(){
  77. this.ff.control.mEventButton.node.active = false;
  78. }
  79. public startStory(){
  80. /**
  81. * 暂停所有
  82. */
  83. this.ff.pauseSprite(true);
  84. this.iconTouch.active = false;
  85. this.ff.mBlockInputEvents.active = true;
  86. this.showDialog1();
  87. }
  88. private showDialog1(){
  89. let dialogs = [
  90. '城堡里有个美丽的公主',
  91. '刚收到消息,说她后妈嫉妒她的美貌,用毒苹果把她毒死了',
  92. '现在去夺取解药,应该还能救活她',
  93. ];
  94. let node = cc.instantiate(this.mMapDialog);
  95. node.group = 'map'
  96. node.zIndex = 9999;
  97. node.x = this.node.x;
  98. node.y = this.node.y + this.node.height;
  99. node.parent = this.ff.mMap.mSprites;
  100. let obo = node.getComponent(WOneByone);
  101. obo.dialogs = dialogs;
  102. obo.setCallback(()=>{
  103. node.destroy();
  104. this.playAction();
  105. });
  106. this.ff.setBlockInputCallback(()=>{
  107. obo.jump();
  108. });
  109. obo._start();
  110. }
  111. private exitExtra(){
  112. this.ff.pauseSprite(false);
  113. this.ff.mBlockInputEvents.active = false;
  114. this.node.removeComponent(cc.PhysicsBoxCollider);
  115. }
  116. private playAction(){
  117. this.spine.active = true;
  118. let spine = this.spine.getComponent(sp.Skeleton);
  119. spine.setCompleteListener(() => {
  120. spine.setCompleteListener(null);
  121. this.spine.active = false;
  122. this.openExtraStage();
  123. });
  124. spine.setAnimation(0, 'vs_direct', false);
  125. }
  126. private moveCarmea(){
  127. let map = this.ff.mMap;
  128. let camera = map.mCamera;
  129. let cameraPos = this.mFenceTrigger[0];
  130. let pos = cc.v2();
  131. let winsize = cc.winSize;
  132. pos.x = cameraPos.x-winsize.width/2;
  133. pos.y = cameraPos.y-winsize.height/2;
  134. cc.tween(camera.node).sequence(
  135. cc.moveTo(1.5,pos),
  136. cc.callFunc(()=>{
  137. this.mFenceTrigger.forEach(element => {
  138. this.showFence(element,'close');
  139. });
  140. }),
  141. cc.delayTime(1),
  142. cc.callFunc(()=>{
  143. this.mFenceTrigger.forEach(element => {
  144. element.active = false;
  145. });
  146. this.exitExtra();
  147. })
  148. ).start();
  149. }
  150. private showFence(element,action){
  151. // let nodes = element.children;
  152. // nodes.forEach(tmp => {
  153. // let spine = tmp.getComponent(sp.Skeleton);
  154. // if(spine){
  155. // spine.setAnimation(0, action, false);
  156. // }
  157. // });
  158. }
  159. /**
  160. * 打开关卡
  161. */
  162. private openExtraStage(){
  163. let msg = {
  164. id:this.extraId
  165. }
  166. let ff = this.ff;
  167. ff.main.gameHttp.sendJson('stage/v1/openExtraStage',msg,(state,reve:ReveData)=>{
  168. if(state == HttpStateType.SUCCESS){
  169. if(reve.retCode == 0){
  170. let player = ff.main.player;
  171. let stage = player.stage;
  172. stage.extraStage.push(this.extraId);
  173. this.moveCarmea();
  174. }else{
  175. this.exitExtra();
  176. ff.main.showTips(reve.message);
  177. }
  178. }else{
  179. this.exitExtra();
  180. ff.main.showTips('网络异常');
  181. }
  182. });
  183. }
  184. }