FStory_rescue.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { RewardData } from "../../../data/sdata/SManage";
  2. import FF from "../../FF";
  3. import FSprite from "../../object/FSprite";
  4. import WOneByone from "./WOneByone";
  5. /**
  6. * 剧情1:解救伙伴
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class FStory_rescue extends cc.Component {
  11. @property(cc.Prefab)
  12. mMapDialog: cc.Prefab = null;
  13. @property(dragonBones.ArmatureDisplay)
  14. mMonster: dragonBones.ArmatureDisplay = null;
  15. @property({
  16. type:cc.Node,
  17. displayName: '任务提示'
  18. })
  19. public iconTouch:cc.Node = null;
  20. private ff:FF;
  21. onLoad() {
  22. }
  23. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  24. if(other.node.group == 'A'){
  25. let obj = other.node.getComponent(FSprite);
  26. this.ff = obj.ff;
  27. if(obj == this.ff.mainSprite){
  28. this.showButton();
  29. }
  30. }
  31. }
  32. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  33. if(other.node.group == 'A'){
  34. let obj = other.node.getComponent(FSprite);
  35. if(obj == this.ff.mainSprite){
  36. this.closeButton();
  37. }
  38. }
  39. }
  40. public showButton(){
  41. this.ff.control.mEventButton.node.active = true;
  42. this.ff.control.mEventButton.setCallback(()=>{
  43. this.startStory();
  44. });
  45. }
  46. public closeButton(){
  47. this.ff.control.mEventButton.node.active = false;
  48. }
  49. public startStory(){
  50. /**
  51. * 暂停所有
  52. */
  53. this.iconTouch.active = false;
  54. this.ff.pauseSprite(true);
  55. this.ff.mBlockInputEvents.active = true;
  56. this.showDialog1();
  57. }
  58. private showDialog1(){
  59. let dialogs = [
  60. '别打我,我就是个零时工',
  61. '钥匙给你',
  62. ];
  63. let node = cc.instantiate(this.mMapDialog);
  64. node.group = 'map'
  65. node.zIndex = 9999;
  66. node.x = this.node.x;
  67. node.y = this.node.y + this.node.height;
  68. node.parent = this.ff.mMap.mSprites;
  69. let obo = node.getComponent(WOneByone);
  70. obo.dialogs = dialogs;
  71. obo.setCallback(()=>{
  72. node.destroy();
  73. this.ff.setBlockInputCallback(null);
  74. this.ff.pauseSprite(false);
  75. this.ff.mBlockInputEvents.active = false;
  76. this.closeButton();
  77. this.node.removeComponent(cc.PhysicsBoxCollider);
  78. this.addKey();
  79. });
  80. this.ff.setBlockInputCallback(()=>{
  81. obo.jump();
  82. });
  83. obo._start();
  84. }
  85. /**
  86. * 添加一个钥匙
  87. */
  88. private addKey(){
  89. let list:Array<RewardData> = [
  90. {
  91. type:2,//0:money,1:gole,2:good
  92. icon:'icon/good/2001',
  93. count:1,//数量
  94. id:2001,//道具对应的id
  95. pz:0,
  96. star:0,
  97. PR:0
  98. }
  99. ];
  100. let pos = this.mMonster.node.parent.getPosition();
  101. this.ff.addGoods(list,pos);
  102. let header = this.ff.mFFheader;
  103. header.addTmpGood(2001,1);
  104. }
  105. }