FCagePet1.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. import FqLogin from "../../../login/FqLogin";
  2. import { AudioMgr } from "../../../main/ViewManage";
  3. import FFCalAttr from "../../data/FFCalAttr";
  4. import BaseEvent from "../../fight/evnet/base/BaseEvent";
  5. import AIPet from "../../fight/object/AI/AIPet";
  6. import { GroupType } from "../../fight/object/FObject";
  7. import { SpriteActionType } from "../../fight/object/FSprite";
  8. import PSprite from "../../fight/object/PSprite";
  9. const { ccclass, property } = cc._decorator;
  10. /**
  11. * 第一个宠物牢笼
  12. */
  13. @ccclass
  14. export default class FCagePet1 extends BaseEvent {
  15. @property({
  16. displayName: '解救的伙伴id',
  17. })
  18. mPetId: number = 1;
  19. @property({
  20. displayName: '没有钥匙的对话',
  21. type: [cc.String]
  22. })
  23. dialog1: Array<string> = [];
  24. @property({
  25. displayName: '牢笼动画',
  26. tooltip: '显示牢笼的动画',
  27. type: sp.Skeleton
  28. })
  29. spine: sp.Skeleton = null;//牢笼
  30. @property({
  31. displayName: '按钮图标',
  32. type: cc.SpriteFrame
  33. })
  34. mTipsIcon: cc.SpriteFrame = 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.Node
  48. })
  49. mPet: cc.Node = null;//伙伴
  50. @property({
  51. displayName: '宠物预制体',
  52. type: cc.Prefab
  53. })
  54. mPetPrefab: cc.Prefab = null;
  55. @property({
  56. type: [cc.Node],
  57. displayName: '需要打开的门'
  58. })
  59. mFenceTrigger: Array<cc.Node> = [];
  60. @property({
  61. displayName: '落单的精灵',
  62. type: cc.Node
  63. })
  64. mNPC2: cc.Node = null;
  65. @property({
  66. displayName: '路过的矮人',
  67. type: cc.Node
  68. })
  69. mNPC3: cc.Node = null;
  70. private isOver = false;
  71. onLoad(){
  72. super.onLoad()
  73. this.mNPC3.active = false
  74. }
  75. onBegin(tag: number) {
  76. if (this.isOver) {
  77. return;
  78. }
  79. if (tag == 1) {
  80. this.iconTips(true);
  81. this.showOpt(this.mTipsIcon, () => {
  82. this.iconTips(false);
  83. this.closeOpt()
  84. this.openCage()
  85. })
  86. }
  87. }
  88. onEnd(tag: number) {
  89. if (tag == 1) {
  90. this.iconTips(false);
  91. this.closeOpt()
  92. }
  93. }
  94. /**
  95. *
  96. * @param show 是否显示提示
  97. */
  98. private iconTips(show) {
  99. if (this.mIcon) {
  100. if (show) {
  101. this.mIcon.node.active = true;
  102. let head = this.ff.mFFheader;
  103. let count = head.getTmpCount(2001);
  104. if (count > 0) {
  105. this.mIcon.spriteFrame = this.mIconFrame[0]
  106. } else {
  107. this.mIcon.spriteFrame = this.mIconFrame[1]
  108. }
  109. } else {
  110. this.mIcon.node.active = false;
  111. }
  112. }
  113. }
  114. //打开牢笼
  115. private openCage() {
  116. let head = this.ff.mFFheader;
  117. let count = head.getTmpCount(2001);
  118. if (count > 0) {
  119. head.removeTmpGood(2001, 1);
  120. this.isOver = true;
  121. this.pause()
  122. this.spine.setCompleteListener(() => {
  123. this.spine.setCompleteListener(null);
  124. this.movePet()
  125. });
  126. if (this.spine.findAnimation("open3")) {
  127. this.spine.setAnimation(0, 'open3', false);
  128. } else {
  129. this.spine.setAnimation(0, 'open', false);
  130. }
  131. FqLogin.commitEvent(this.node.name, '', '');
  132. } else {
  133. // this.ff.main.showTips('需要一把牢笼钥匙');
  134. this.showDialog(this.node,this.dialog1,()=>{
  135. })
  136. }
  137. }
  138. private movePet() {
  139. let anim = this.mPet.getComponent(cc.Animation);
  140. let spine = this.mPet.getComponent(sp.Skeleton);
  141. spine.setAnimation(0, SpriteActionType.run, true);
  142. anim.on('finished', this.onFinished, this);
  143. anim.play('cage_pet_move');
  144. cc.tween(this.mNPC2).sequence(
  145. cc.moveTo(1,cc.v2(3202,3990)),
  146. cc.callFunc(()=>{
  147. this.npcDialog()
  148. })
  149. ).start()
  150. }
  151. private onFinished(num, string) {
  152. let anim = this.mPet.getComponent(cc.Animation);
  153. let spine = this.mPet.getComponent(sp.Skeleton);
  154. anim.off('finished', this.onFinished, this);
  155. spine.setAnimation(0, SpriteActionType.stand, true);
  156. }
  157. /**
  158. * 落单的精灵:多么快活的小家伙!
  159. 落单的精灵:你做了一件好事。做好事的人心地善良,人也会变得漂亮。
  160. 落单的精灵:我的妈妈告诉我,人类就是这么变漂亮的。
  161. 角色:……
  162. 落单的精灵:快看,这只小鹿非常喜欢你。它没有红鼻子,但也非常可爱。
  163. 落单的精灵:但是它一直待在你身边,这让我有点沮丧。
  164. */
  165. private npcDialog(){
  166. let text = [
  167. '多么快活的小家伙!',
  168. '你做了一件好事。做好事的人心地善良,人也会变得漂亮。',
  169. '我的妈妈告诉我,人类就是这么变漂亮的。',
  170. ]
  171. this.showDialog(this.mNPC2,text,()=>{
  172. this.meDialog1_1()
  173. })
  174. }
  175. private meDialog1_1(){
  176. let text = [
  177. '……',
  178. ]
  179. this.showDialog(this.ff.mainSprite.node,text,()=>{
  180. this.npcDialog1_1()
  181. })
  182. }
  183. private npcDialog1_1(){
  184. let text = [
  185. '快看,这只小鹿非常喜欢你。它没有红鼻子,但也非常可爱。',
  186. '但是它一直待在你身边,这让我有点沮丧。'
  187. ]
  188. this.showDialog(this.mNPC2,text,()=>{
  189. this.meDialog()
  190. })
  191. }
  192. private meDialog(){
  193. let text = [
  194. '你也帮助了它。',
  195. ]
  196. this.showDialog(this.ff.mainSprite.node,text,()=>{
  197. this.npcDialog1()
  198. })
  199. }
  200. private npcDialog1(){
  201. let text = [
  202. '等等……它似乎不是普通的小鹿。',
  203. ]
  204. this.showDialog(this.mNPC2,text,()=>{
  205. this.npcDialog2()
  206. })
  207. }
  208. private npcDialog2(){
  209. let text = [
  210. '这是一只战斗宠物,难怪会出现在这里……',
  211. '落单的精灵:恭喜你,它是你的伙伴了!',
  212. ]
  213. this.showDialog(this.mNPC2,text,()=>{
  214. this.getPet()
  215. this.npcDialog3()
  216. })
  217. }
  218. private getPet(){
  219. let node = cc.instantiate(this.mPetPrefab);
  220. node.group = GroupType.A;
  221. node.x = this.node.x + this.mPet.x
  222. node.y = this.node.y + this.mPet.y
  223. let sp = node.addComponent(PSprite);
  224. let attrData = this.ff.main.sManage.getMonsterData(1003);
  225. sp.setAttrData(attrData)
  226. this.ff.addRole(sp);
  227. sp.hp = sp.attrData.hp
  228. sp.addComponent(AIPet);
  229. this.mPet.removeFromParent();
  230. }
  231. private npcDialog3(){
  232. let text = [
  233. '小法师,我要走了。我得去寻找我的弟弟。',
  234. ]
  235. this.showDialog(this.mNPC2,text,()=>{
  236. this.npc3()
  237. })
  238. }
  239. private npc3(){
  240. this.mNPC3.active = true
  241. cc.tween(this.mNPC3).sequence(
  242. cc.moveTo(1,cc.v2(3340,3943)),
  243. cc.callFunc(()=>{
  244. this.npc3Dialog()
  245. })
  246. ).start()
  247. }
  248. private npc3Dialog(){
  249. let text = [
  250. '强大的法师,请……啊!!!',
  251. ]
  252. this.showDialog(this.mNPC3,text,()=>{
  253. this.npc2T()
  254. })
  255. }
  256. /**
  257. * NPC2踢飞NPC3
  258. */
  259. private npc2T(){
  260. cc.tween(this.mNPC2).sequence(
  261. cc.moveTo(0.5,cc.v2(3340,3943)),
  262. cc.callFunc(()=>{
  263. this.npc3Fly()
  264. })
  265. ).start()
  266. }
  267. private npc3Fly(){
  268. let node = this.mNPC3.children[1]
  269. node.active = true
  270. cc.tween(this.mNPC3).sequence(
  271. cc.moveBy(0.7,cc.v2(800,800)),
  272. cc.callFunc(()=>{
  273. this.npcDialog4()
  274. }),
  275. cc.destroySelf()
  276. ).start()
  277. cc.tween(this.mNPC3).repeatForever(
  278. cc.rotateBy(0.1,60)
  279. ).start()
  280. }
  281. private npcDialog4(){
  282. let text = [
  283. '不用为别的事物分心。小法师,你似乎刚刚成为法师?',
  284. ]
  285. this.showDialog(this.mNPC2,text,()=>{
  286. this.meDialog2()
  287. })
  288. }
  289. private meDialog2(){
  290. let text = [
  291. '是的。',
  292. '告知失落之地的事情。',
  293. ]
  294. this.showDialog(this.ff.mainSprite.node,text,()=>{
  295. this.npcDialog5()
  296. })
  297. }
  298. private npcDialog5(){
  299. let text = [
  300. '等等!!',
  301. '发生了这么可怕的事情,怎么现在才告诉我。',
  302. '我改变了主意,小法师,在森林中等我。'
  303. ]
  304. this.showDialog(this.mNPC2,text,()=>{
  305. this.npc2Move()
  306. })
  307. }
  308. private npc2Move(){
  309. cc.tween(this.mNPC2).sequence(
  310. cc.moveBy(1,cc.v2(0,-500)),
  311. cc.callFunc(()=>{
  312. this.openDoor()
  313. }),
  314. cc.destroySelf()
  315. ).start()
  316. }
  317. private openDoor(){
  318. this.pause()
  319. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  320. cc.tween(this.node).sequence(
  321. cc.callFunc(() => {
  322. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  323. const element = this.mFenceTrigger[i];
  324. this.showFence(element, 'open');
  325. }
  326. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  327. }),
  328. cc.delayTime(1),
  329. cc.callFunc(() => {
  330. this.resume()
  331. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  332. const element = this.mFenceTrigger[i];
  333. element.active = false;
  334. }
  335. })
  336. ).start();
  337. })
  338. }
  339. private showFence(element, action) {
  340. let nodes = element.children;
  341. for (let i = 0; i < nodes.length; i++) {
  342. const element = nodes[i];
  343. let spine = element.getComponent(sp.Skeleton);
  344. if (spine) {
  345. spine.setAnimation(0, action, false);
  346. }
  347. }
  348. }
  349. }