FOpenDoorCheck.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import BaseEvent from "../base/BaseEvent";
  2. /**
  3. * 完成开门条件
  4. */
  5. const {ccclass, property} = cc._decorator;
  6. @ccclass
  7. export default class FOpenDoorCheck extends BaseEvent {
  8. @property({
  9. displayName: '需要的物品id'
  10. })
  11. public goodId = 2002;
  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.SpriteFrame
  22. })
  23. mTipsIcon: cc.SpriteFrame = null;
  24. @property({
  25. displayName: '驱赶的对象',
  26. type:cc.Node
  27. })
  28. mDriveNode: cc.Node = null;
  29. @property({
  30. displayName: '棍子',
  31. type:cc.Node
  32. })
  33. mGunNode: cc.Node = null;
  34. @property({
  35. displayName: '乌鸦',
  36. type:sp.Skeleton
  37. })
  38. mSpine: sp.Skeleton = null;
  39. onLoad(){
  40. super.onLoad()
  41. this.mGunNode.active = false
  42. }
  43. onBegin(tag:number){
  44. if(tag == 1){
  45. if(!this.mDriveNode.active){
  46. return
  47. }
  48. this.showOpt(this.mTipsIcon,()=>{
  49. this.closeOpt()
  50. let head = this.ff.mFFheader;
  51. let count = head.getTmpCount(this.goodId);
  52. if(count > 0){
  53. this.ff.pauseSprite(true);
  54. this.ff.mBlockInputEvents.active = true;
  55. head.removeTmpGood(this.goodId,1);
  56. this.mGunNode.active = true
  57. this.mSpine.setAnimation(0, 'hurt', false);
  58. cc.tween(this.mGunNode).sequence(
  59. cc.moveBy(0.2,cc.v2(0,40)),
  60. cc.moveBy(0.2,cc.v2(0,-40)),
  61. cc.moveBy(0.2,cc.v2(0,40)),
  62. cc.moveBy(0.2,cc.v2(0,-40)),
  63. cc.moveBy(0.2,cc.v2(0,40)),
  64. cc.moveBy(0.2,cc.v2(0,-40)),
  65. cc.callFunc(()=>{
  66. this.flyGo()
  67. }),
  68. cc.moveBy(0.2,cc.v2(0,20)),
  69. cc.moveBy(0.2,cc.v2(0,-20)),
  70. cc.fadeOut(1),
  71. ).start()
  72. }else{
  73. this.dialog(0)
  74. }
  75. })
  76. }
  77. }
  78. private flyGo(){
  79. this.ff.pauseSprite(false);
  80. this.ff.mBlockInputEvents.active = false;
  81. this.mSpine.setCompleteListener(()=>{
  82. this.mDriveNode.active = false
  83. this.pause()
  84. this.showDialog(this.ff.mainSprite.node,['乌鸦被赶走了,去告诉神秘人吧'],()=>{
  85. this.resume()
  86. });
  87. })
  88. this.mSpine.setAnimation(0, 'fly', false);
  89. }
  90. onEnd(tag:number){
  91. if(tag == 1){
  92. this.closeOpt()
  93. }
  94. }
  95. private dialog(index:number){
  96. if(index >= this.text.length){
  97. this.closeOpt()
  98. this.ff.pauseSprite(false);
  99. this.ff.mBlockInputEvents.active = false;
  100. return;
  101. }
  102. let texts = this.text[index].split('|')
  103. let mid = parseInt(texts.shift());
  104. if(mid == -1){//主角
  105. let my = this.ff.mainSprite.node;
  106. this.showDialog(my,texts,()=>{
  107. index ++;
  108. this.dialog(index);
  109. });
  110. }
  111. }
  112. }