FAltarGear.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { HttpStateType, ReveData } from "../../../../util/CHttp";
  2. import FMap from "../../map/FMap";
  3. import FAltarLight from "./FAltarLight";
  4. const SpineName = {
  5. IDLE: "idle",
  6. IDLE2: "idle2",
  7. CLOSE: "close",
  8. OPEN: "open"
  9. }
  10. /**
  11. * 事件机关
  12. */
  13. const { ccclass, property } = cc._decorator;
  14. @ccclass
  15. export default class FAltarGear extends cc.Component {
  16. @property({
  17. displayName: '对应的地图物件'
  18. })
  19. public mapGoodId: string = '27';
  20. @property({
  21. type: [cc.Node],
  22. displayName: '祭坛灯柱'
  23. })
  24. public altarLight: Array<cc.Node> = [];
  25. /**
  26. * 控制的栅栏机关
  27. */
  28. @property({
  29. displayName: '控制的机关',
  30. type: [cc.Node],
  31. })
  32. mFenceTrigger: Array<cc.Node> = [];
  33. private map: FMap = null;
  34. onLoad() {
  35. this.map = this.node.parent.parent.getComponent(FMap);
  36. }
  37. /**
  38. * 检查灯柱点亮情况
  39. */
  40. public check() {
  41. for (let i = 0; i < this.altarLight.length; i++) {
  42. const element = this.altarLight[i];
  43. let altarLight = element.getComponent(FAltarLight)
  44. if (!altarLight.spine.active) {
  45. return false;
  46. }
  47. }
  48. this.openGear();
  49. return true
  50. }
  51. private openGear() {
  52. let ff = this.map.ff;
  53. ff.pauseSprite(true);
  54. this.moveCamera(() => {
  55. this.mFenceTrigger.forEach(element => {
  56. let spine = element.children[0].getComponent(sp.Skeleton);
  57. if (spine) {
  58. spine.setAnimation(0, SpineName.OPEN, false);
  59. spine.setCompleteListener(() => {
  60. spine.setCompleteListener(null);
  61. element.zIndex = -9999;
  62. element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  63. })
  64. }
  65. });
  66. });
  67. }
  68. private moveCamera(callFunc: Function) {
  69. let map = this.map;
  70. let camera = map.mCamera;
  71. let pos = cc.v2();
  72. let winsize = cc.winSize;
  73. pos.x = this.node.x - winsize.width / 2;
  74. pos.y = this.node.y - winsize.height / 2;
  75. cc.tween(camera.node).sequence(
  76. cc.moveTo(1, pos).easing(cc.easeOut(1)),
  77. cc.callFunc(() => {
  78. callFunc && callFunc();
  79. }),
  80. cc.delayTime(1),
  81. cc.callFunc(() => {
  82. map.ff.pauseSprite(false);
  83. })
  84. ).start()
  85. }
  86. }