FOpenDoorChat.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import FqLogin from "../../../../login/FqLogin";
  2. import { AudioMgr } from "../../../../main/ViewManage";
  3. import BaseEvent from "../base/BaseEvent";
  4. import WOneByone from "../map1/WOneByone";
  5. import FOpenDoorCheck from "./FOpenDoorCheck";
  6. /**
  7. * 对话开门
  8. */
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class FOpenDoorChat extends BaseEvent{
  12. @property(cc.Prefab)
  13. mMapDialog: cc.Prefab = null;
  14. @property({
  15. displayName:'对话内容',
  16. type:[cc.String]
  17. })
  18. text: Array<string> = [];
  19. @property({
  20. displayName: '完成后的对话',
  21. type:[cc.String]
  22. })
  23. finish: Array<string> = [];//完成后的对话
  24. @property({
  25. displayName: '靠近的提示',
  26. type:cc.Node
  27. })
  28. icon: cc.Node = null;
  29. @property({
  30. displayName: '提示图标',
  31. type:cc.SpriteFrame
  32. })
  33. mTipsIcon: cc.SpriteFrame = null;
  34. @property({
  35. displayName: '驱赶条件对象',
  36. type:FOpenDoorCheck
  37. })
  38. mCheck: FOpenDoorCheck = null;
  39. @property({
  40. displayName: '需要打开的门',
  41. type:cc.Node
  42. })
  43. mOpenDoor: cc.Node = null;
  44. @property({
  45. displayName: '精灵动画',
  46. type:sp.Skeleton
  47. })
  48. spine: sp.Skeleton = null;
  49. onLoad(){
  50. super.onLoad()
  51. }
  52. onBegin(tag:number){
  53. if(!this.mOpenDoor.active){
  54. return
  55. }
  56. if(tag == 1){
  57. this.showOpt(this.mTipsIcon,()=>{
  58. this.closeOpt()
  59. this.pause()
  60. this.startDialog()
  61. })
  62. }
  63. }
  64. onEnd(tag:number){
  65. if(tag == 1){
  66. this.closeOpt()
  67. }
  68. }
  69. public startDialog(){
  70. if(this.mCheck.mDriveNode.active){
  71. this.dialog1(0);
  72. }else{
  73. this.dialog2(0);
  74. }
  75. }
  76. private dialog1(index:number){
  77. if(index >= this.text.length){
  78. this.resume()
  79. return;
  80. }
  81. let texts = this.text[index].split('|')
  82. let mid = parseInt(texts.shift());
  83. if(mid == -1){//主角
  84. let my = this.ff.mainSprite.node;
  85. this.showDialog(my,texts,()=>{
  86. index ++;
  87. this.dialog1(index);
  88. });
  89. }else{
  90. this.showDialog(this.node,texts,()=>{
  91. index ++;
  92. this.dialog1(index);
  93. });
  94. }
  95. }
  96. private dialog2(index:number){
  97. if(index >= this.finish.length){
  98. this.spine.setCompleteListener(()=>{
  99. this.spine.setCompleteListener(null)
  100. this.spine.destroy()
  101. this.moveCamera(this.mOpenDoor.getPosition(),1,()=>{
  102. this.openGear()
  103. })
  104. })
  105. this.spine.setAnimation(0,'escape2',false)
  106. return;
  107. }
  108. let texts = this.finish[index].split('|')
  109. let mid = parseInt(texts.shift());
  110. if(mid == -1){//主角
  111. let my = this.ff.mainSprite.node;
  112. this.showDialog(my,texts,()=>{
  113. index ++;
  114. this.dialog2(index);
  115. });
  116. }else{
  117. this.showDialog(this.node,texts,()=>{
  118. index ++;
  119. this.dialog2(index);
  120. });
  121. }
  122. }
  123. private openGear() {
  124. if(this.icon){
  125. this.icon.active = false;
  126. }
  127. let nodes = this.mOpenDoor.children;
  128. nodes.forEach(element => {
  129. let spine = element.getComponent(sp.Skeleton);
  130. if (spine) {
  131. spine.setCompleteListener(() => {
  132. element.active = false;
  133. });
  134. spine.setAnimation(0, 'close', false);
  135. }
  136. });
  137. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  138. cc.tween(this.ff.mMap.node).sequence(
  139. cc.delayTime(1),
  140. cc.callFunc(() => {
  141. this.mOpenDoor.active = false;
  142. this.resume()
  143. this.node.destroy()
  144. FqLogin.commitEvent(this.node.name,'','');
  145. })
  146. ).start()
  147. }
  148. }