FAltarLight.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. onLoad() {
  64. super.onLoad()
  65. if (this.mIcon) {
  66. this.mIcon.node.active = false;
  67. }
  68. }
  69. start() {
  70. this.spine.active = false;
  71. }
  72. /**
  73. *
  74. * @param show 是否显示提示
  75. */
  76. private iconTips(show) {
  77. if (this.mIcon) {
  78. if (show) {
  79. this.mIcon.node.active = true;
  80. let head = this.ff.mFFheader;
  81. let count = head.getTmpCount(this.goodId);
  82. if (count > 0) {
  83. this.mIcon.spriteFrame = this.mIconFrame[0]
  84. } else {
  85. this.mIcon.spriteFrame = this.mIconFrame[1]
  86. }
  87. } else {
  88. this.mIcon.node.active = false;
  89. }
  90. }
  91. }
  92. onBegin(tag: number) {
  93. if (this.spine.active) {
  94. return;
  95. }
  96. if (tag == 1) {
  97. this.iconTips(true);
  98. this.showOpt(this.mTipsIcon, () => {
  99. this.submit()
  100. })
  101. }
  102. }
  103. onEnd(tag: number) {
  104. if (tag == 1) {
  105. this.closeButton();
  106. }
  107. }
  108. public closeButton() {
  109. this.iconTips(false);
  110. this.closeOpt()
  111. }
  112. public submit() {
  113. if (this.spine.active) {
  114. this.ff.main.showTips('祭火已经点亮');
  115. return;
  116. }
  117. this.closeButton();
  118. let head = this.ff.mFFheader;
  119. let count = head.getTmpCount(this.goodId);
  120. if (count > 0) {
  121. head.removeTmpGood(this.goodId, 1);
  122. this.spine.active = true;
  123. let fAltar = this.altar.getComponent(FAltar);
  124. let fAltarGear = this.altar.getComponent(FAltarGear);
  125. if (fAltar) {
  126. fAltar.check();
  127. } else if (fAltarGear) {
  128. let ok = fAltarGear.check();
  129. if (this.text.length > 0 && !ok) {
  130. this.d0()
  131. }
  132. if (ok) {
  133. FqLogin.commitEvent(this.node.name, '', '');
  134. }
  135. }
  136. } else {
  137. this.ff.main.showTips('需要祭火');
  138. }
  139. }
  140. private d0() {
  141. this.ff.pauseSprite(true);
  142. let dialogs = this.text;
  143. let mapDialog = new FMapDialog(this.ff, this.mMapDialog);
  144. let pos = cc.v2();
  145. let ga = this.ff.getGroupBy(GroupType.A);
  146. let spine = ga[0]
  147. pos.x = spine.node.x;
  148. pos.y = spine.node.y + spine.node.height;
  149. mapDialog.showDialog(dialogs,
  150. pos,
  151. spine.spine,
  152. () => {
  153. this.ff.pauseSprite(false);
  154. }
  155. );
  156. }
  157. // private checkOpen() {
  158. // //检查其它开关是否打开
  159. // this.pause();
  160. // this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  161. // cc.tween(this.node).sequence(
  162. // cc.callFunc(() => {
  163. // for (let i = 0; i < this.mFenceTrigger.length; i++) {
  164. // const element = this.mFenceTrigger[i];
  165. // this.showFence(element, SpineName.OPEN);
  166. // }
  167. // this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  168. // }),
  169. // cc.delayTime(1),
  170. // cc.callFunc(() => {
  171. // this.resume()
  172. // for (let i = 0; i < this.mFenceTrigger.length; i++) {
  173. // const element = this.mFenceTrigger[i];
  174. // element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  175. // }
  176. // })
  177. // ).start();
  178. // })
  179. // }
  180. // private showFence(element, action) {
  181. // let nodes = element.children;
  182. // for (let i = 0; i < nodes.length; i++) {
  183. // const element = nodes[i];
  184. // let spine: sp.Skeleton = element.getComponent(sp.Skeleton);
  185. // if (spine) {
  186. // spine.setAnimation(0, action, false);
  187. // }
  188. // }
  189. // }
  190. }