FAltarLight.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import FqLogin from "../../../../login/FqLogin";
  2. import { AudioMgr } from "../../../../main/ViewManage";
  3. import FF from "../../FF";
  4. import FMap from "../../map/FMap";
  5. import { GroupType } from "../../object/FObject";
  6. import FSprite from "../../object/FSprite";
  7. import BaseEvent from "../base/BaseEvent";
  8. import FMapDialog from "../dialog/FMapDialog";
  9. import FAltar from "./FAltar";
  10. import FAltarGear from "./FAltarGear";
  11. const SpineName = {
  12. IDLE: "idle",
  13. IDLE2: "idle2",
  14. CLOSE: "close",
  15. OPEN: "open"
  16. }
  17. /**
  18. * 祭坛灯柱
  19. */
  20. const { ccclass, property } = cc._decorator;
  21. @ccclass
  22. export default class FAltarLight extends BaseEvent {
  23. @property({
  24. displayName: '对应的地图物件'
  25. })
  26. public mapGoodId: string = '27';
  27. @property({
  28. displayName: '需要的物品id'
  29. })
  30. public goodId = 2002;
  31. @property({
  32. type: cc.Node,
  33. displayName: '点亮火焰动画'
  34. })
  35. public spine: cc.Node = null;
  36. @property({
  37. type: cc.Node,
  38. displayName: '完成后触发对象'
  39. })
  40. public altar: cc.Node = null;
  41. @property({
  42. displayName: '靠近的提示',
  43. type: cc.Sprite
  44. })
  45. mIcon: cc.Sprite = null;//靠近后的提示
  46. @property({
  47. type: [cc.SpriteFrame],
  48. displayName: '不同状态的图标'
  49. })
  50. mIconFrame: Array<cc.SpriteFrame> = [];
  51. @property(cc.Prefab)
  52. mMapDialog: cc.Prefab = null;
  53. @property({
  54. displayName: '提示图标',
  55. type: cc.SpriteFrame
  56. })
  57. mTipsIcon: cc.SpriteFrame = null;
  58. @property({
  59. displayName: '点亮后的对话',
  60. type: [cc.String]
  61. })
  62. text: Array<string> = [];
  63. // /**
  64. // * 控制的栅栏机关
  65. // */
  66. // @property({
  67. // displayName: '控制的机关',
  68. // type: [cc.Node],
  69. // })
  70. // mFenceTrigger: Array<cc.Node> = [];
  71. onLoad() {
  72. super.onLoad()
  73. if (this.mIcon) {
  74. this.mIcon.node.active = false;
  75. }
  76. }
  77. start() {
  78. this.spine.active = false;
  79. }
  80. /**
  81. *
  82. * @param show 是否显示提示
  83. */
  84. private iconTips(show) {
  85. if (this.mIcon) {
  86. if (show) {
  87. this.mIcon.node.active = true;
  88. let head = this.ff.mFFheader;
  89. let count = head.getTmpCount(this.goodId);
  90. if (count > 0) {
  91. this.mIcon.spriteFrame = this.mIconFrame[0]
  92. } else {
  93. this.mIcon.spriteFrame = this.mIconFrame[1]
  94. }
  95. } else {
  96. this.mIcon.node.active = false;
  97. }
  98. }
  99. }
  100. onBegin(tag: number) {
  101. if (this.spine.active) {
  102. return;
  103. }
  104. if (tag == 1) {
  105. this.iconTips(true);
  106. this.showOpt(this.mTipsIcon, () => {
  107. this.submit()
  108. })
  109. }
  110. }
  111. onEnd(tag: number) {
  112. if (tag == 1) {
  113. this.closeButton();
  114. }
  115. }
  116. public closeButton() {
  117. this.iconTips(false);
  118. this.closeOpt()
  119. }
  120. public submit() {
  121. if (this.spine.active) {
  122. this.ff.main.showTips('祭火已经点亮');
  123. return;
  124. }
  125. this.closeButton();
  126. let head = this.ff.mFFheader;
  127. let count = head.getTmpCount(this.goodId);
  128. if (count > 0) {
  129. head.removeTmpGood(this.goodId, 1);
  130. this.spine.active = true;
  131. let fAltar = this.altar.getComponent(FAltar);
  132. let fAltarGear = this.altar.getComponent(FAltarGear);
  133. if (fAltar) {
  134. fAltar.check();
  135. } else if (fAltarGear) {
  136. let ok = fAltarGear.check();
  137. if (this.text.length > 0 && !ok) {
  138. this.d0()
  139. }
  140. if (ok) {
  141. FqLogin.commitEvent(this.node.name, '', '');
  142. }
  143. }
  144. } else {
  145. this.ff.main.showTips('需要祭火');
  146. }
  147. }
  148. private d0() {
  149. this.ff.pauseSprite(true);
  150. let dialogs = this.text;
  151. let mapDialog = new FMapDialog(this.ff, this.mMapDialog);
  152. let pos = cc.v2();
  153. let ga = this.ff.getGroupBy(GroupType.A);
  154. let spine = ga[0]
  155. pos.x = spine.node.x;
  156. pos.y = spine.node.y + spine.node.height;
  157. mapDialog.showDialog(dialogs,
  158. pos,
  159. spine.spine,
  160. () => {
  161. this.ff.pauseSprite(false);
  162. }
  163. );
  164. }
  165. // private checkOpen() {
  166. // //检查其它开关是否打开
  167. // this.pause();
  168. // this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  169. // cc.tween(this.node).sequence(
  170. // cc.callFunc(() => {
  171. // for (let i = 0; i < this.mFenceTrigger.length; i++) {
  172. // const element = this.mFenceTrigger[i];
  173. // this.showFence(element, SpineName.OPEN);
  174. // }
  175. // this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  176. // }),
  177. // cc.delayTime(1),
  178. // cc.callFunc(() => {
  179. // this.resume()
  180. // for (let i = 0; i < this.mFenceTrigger.length; i++) {
  181. // const element = this.mFenceTrigger[i];
  182. // element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  183. // }
  184. // })
  185. // ).start();
  186. // })
  187. // }
  188. // private showFence(element, action) {
  189. // let nodes = element.children;
  190. // for (let i = 0; i < nodes.length; i++) {
  191. // const element = nodes[i];
  192. // let spine: sp.Skeleton = element.getComponent(sp.Skeleton);
  193. // if (spine) {
  194. // spine.setAnimation(0, action, false);
  195. // }
  196. // }
  197. // }
  198. }