FAltarGear.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.setCompleteListener(() => {
  59. element.zIndex = -9999;
  60. element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  61. });
  62. spine.setAnimation(0, SpineName.OPEN, false);
  63. }
  64. });
  65. });
  66. }
  67. private moveCamera(callFunc: Function) {
  68. let map = this.map;
  69. let camera = map.mCamera;
  70. let pos = cc.v2();
  71. let winsize = cc.winSize;
  72. pos.x = this.node.x - winsize.width / 2;
  73. pos.y = this.node.y - winsize.height / 2;
  74. cc.tween(camera.node).sequence(
  75. cc.moveTo(1, pos).easing(cc.easeOut(1)),
  76. cc.callFunc(() => {
  77. callFunc && callFunc();
  78. }),
  79. cc.delayTime(1),
  80. cc.callFunc(() => {
  81. map.ff.pauseSprite(false);
  82. })
  83. ).start()
  84. }
  85. }