FCageShooter.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import FqLogin from "../../../../login/FqLogin";
  2. import { HttpStateType, ReveData } from "../../../../util/CHttp";
  3. import FFCalAttr from "../../../data/FFCalAttr";
  4. import AIPet from "../../object/AI/AIPet";
  5. import { GroupType } from "../../object/FObject";
  6. import FSprite, { SpriteActionType } from "../../object/FSprite";
  7. import PSprite from "../../object/PSprite";
  8. import BaseEvent from ".././base/BaseEvent";
  9. /**
  10. * 解救射手
  11. */
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class FCageShooter extends BaseEvent {
  15. @property({
  16. displayName: '解救的伙伴id',
  17. })
  18. mPetId: number = 1;
  19. @property({
  20. displayName: '牢笼动画',
  21. tooltip: '显示牢笼的动画',
  22. type: sp.Skeleton
  23. })
  24. spine: sp.Skeleton = null;//牢笼
  25. @property({
  26. displayName: '牢笼中的伙伴',
  27. type: cc.Node
  28. })
  29. mPet: cc.Node = null;//伙伴
  30. @property({
  31. displayName: '伙伴预制体',
  32. type: cc.Prefab
  33. })
  34. mPetPrefab: cc.Prefab = null;
  35. @property({
  36. displayName: '靠近的提示',
  37. type: cc.Sprite
  38. })
  39. mIcon: cc.Sprite = null;//靠近后的提示
  40. @property({
  41. type: [cc.SpriteFrame],
  42. displayName: '不同状态的图标'
  43. })
  44. mIconFrame: Array<cc.SpriteFrame> = [];
  45. @property({
  46. displayName: '提示图标',
  47. type: cc.SpriteFrame
  48. })
  49. mTipsIcon: cc.SpriteFrame = null;
  50. @property({
  51. type: [cc.Node],
  52. displayName: '需要打开的门'
  53. })
  54. mDoor: Array<cc.Node> = [];
  55. @property([cc.String])
  56. text: Array<string> = [];
  57. private isOver = false;
  58. onLoad() {
  59. super.onLoad()
  60. if (this.mIcon) {
  61. this.mIcon.node.active = false;
  62. }
  63. let petAttr = this.ff.main.player.getPet(this.mPetId)
  64. if (petAttr) {
  65. this.isOver = true
  66. if (this.spine.findAnimation("open3")) {
  67. this.spine.setAnimation(0, 'open3', false);
  68. } else {
  69. this.spine.setAnimation(0, 'open', false);
  70. }
  71. this.mPet.destroy()
  72. for (let i = 0; i < this.mDoor.length; i++) {
  73. const element = this.mDoor[i];
  74. element.destroy()
  75. }
  76. }
  77. }
  78. onBegin(tag: number) {
  79. if (this.isOver) {
  80. return;
  81. }
  82. if (tag == 1) {
  83. this.iconTips(true);
  84. this.showOpt(this.mTipsIcon, () => {
  85. this.iconTips(false);
  86. this.closeOpt()
  87. this.openCage()
  88. })
  89. }
  90. }
  91. onEnd(tag: number) {
  92. if (tag == 1) {
  93. this.iconTips(false);
  94. this.closeOpt()
  95. }
  96. }
  97. /**
  98. *
  99. * @param show 是否显示提示
  100. */
  101. private iconTips(show) {
  102. if (this.mIcon) {
  103. if (show) {
  104. this.mIcon.node.active = true;
  105. let head = this.ff.mFFheader;
  106. let count = head.getTmpCount(2001);
  107. if (count > 0) {
  108. this.mIcon.spriteFrame = this.mIconFrame[0]
  109. } else {
  110. this.mIcon.spriteFrame = this.mIconFrame[1]
  111. }
  112. } else {
  113. this.mIcon.node.active = false;
  114. }
  115. }
  116. }
  117. //打开牢笼
  118. private openCage() {
  119. let head = this.ff.mFFheader;
  120. let count = head.getTmpCount(2001);
  121. if (count > 0) {
  122. this.isOver = true;
  123. this.spine.setCompleteListener(() => {
  124. this.spine.setCompleteListener(null);
  125. this.movePet()
  126. });
  127. if (this.spine.findAnimation("open3")) {
  128. this.spine.setAnimation(0, 'open3', false);
  129. } else {
  130. this.spine.setAnimation(0, 'open', false);
  131. }
  132. FqLogin.commitEvent(this.node.name, '', '');
  133. } else {
  134. this.ff.main.showTips('需要一把牢笼钥匙');
  135. }
  136. }
  137. private movePet() {
  138. let anim = this.mPet.getComponent(cc.Animation);
  139. let spine = this.mPet.getComponent(sp.Skeleton);
  140. spine.setAnimation(0, SpriteActionType.run, true);
  141. anim.on('finished', this.onFinished, this);
  142. anim.play('cage_pet_move');
  143. }
  144. private onFinished(num, string) {
  145. let anim = this.mPet.getComponent(cc.Animation);
  146. let spine = this.mPet.getComponent(sp.Skeleton);
  147. anim.off('finished', this.onFinished, this);
  148. spine.setAnimation(0, SpriteActionType.stand, true);
  149. //开始对话
  150. this.dialog(0)
  151. }
  152. private dialog(index: number) {
  153. if (index >= this.text.length) {
  154. this.getPet()
  155. return;
  156. }
  157. let texts = this.text[index].split('|')
  158. let mid = parseInt(texts.shift());
  159. if (mid == -1) {//主角
  160. let my = this.ff.mainSprite.node;
  161. this.showDialog(my, texts, () => {
  162. index++;
  163. this.dialog(index);
  164. });
  165. } else {
  166. let my = this.mPet;
  167. let pos = cc.v2()
  168. pos.x = this.node.x + my.x
  169. pos.y = this.node.y + my.y
  170. pos.y += my.height
  171. this.showDialogPos(pos, texts, () => {
  172. index++;
  173. this.dialog(index);
  174. });
  175. }
  176. }
  177. /**
  178. * 解救伙伴
  179. */
  180. private getPet() {
  181. this.isOver = true
  182. let head = this.ff.mFFheader;
  183. head.removeTmpGood(2001, 1);
  184. let msg = {
  185. petId: this.mPetId
  186. }
  187. let main = this.ff.main
  188. main.gameHttp.sendJson('stage/v1/getPet', msg, (state, reve: ReveData) => {
  189. main.stopLoad();
  190. if (state == HttpStateType.SUCCESS) {
  191. if (reve.retCode == 0) {
  192. let player = main.player;
  193. let petAttr = reve.data.petObject
  194. player.pet[this.mPetId] = petAttr;
  195. petAttr.id = this.mPetId;
  196. let node = cc.instantiate(this.mPetPrefab);
  197. node.group = GroupType.A;
  198. node.x = this.node.x + this.mPet.x
  199. node.y = this.node.y + this.mPet.y
  200. let sp = node.addComponent(PSprite);
  201. let attrData = FFCalAttr.getAttr(this.ff.main, petAttr)
  202. sp.setAttrData(attrData)
  203. this.ff.addRole(sp);
  204. sp.hp = sp.attrData.hp
  205. sp.addComponent(AIPet);
  206. this.mPet.removeFromParent();
  207. for (let i = 0; i < this.mDoor.length; i++) {
  208. const element = this.mDoor[i];
  209. element.destroy()
  210. }
  211. } else {
  212. main.showTips(reve.message);
  213. }
  214. } else {
  215. main.showTips('网络异常');
  216. }
  217. });
  218. }
  219. }