FCagePet1.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. import FqLogin from "../../../../login/FqLogin";
  2. import { AudioMgr } from "../../../../main/ViewManage";
  3. import FFCalAttr from "../../../data/FFCalAttr";
  4. import AIPet from "../../object/AI/AIPet";
  5. import { GroupType } from "../../object/FObject";
  6. import { SpriteActionType } from "../../object/FSprite";
  7. import PSprite from "../../object/PSprite";
  8. import BaseEvent from "../base/BaseEvent";
  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. '快看,这只小鹿非常喜欢你。它没有红鼻子,但也非常可爱。',
  172. '但是它一直待在你身边,这让我有点沮丧。'
  173. ]
  174. this.showDialog(this.mNPC2,text,()=>{
  175. this.meDialog()
  176. })
  177. }
  178. private meDialog(){
  179. let text = [
  180. '你也帮助了它。',
  181. ]
  182. this.showDialog(this.ff.mainSprite.node,text,()=>{
  183. this.npcDialog1()
  184. })
  185. }
  186. private npcDialog1(){
  187. let text = [
  188. '等等……它似乎不是普通的小鹿。',
  189. ]
  190. this.showDialog(this.mNPC2,text,()=>{
  191. this.npcDialog2()
  192. })
  193. }
  194. private npcDialog2(){
  195. let text = [
  196. '这是一只战斗宠物,难怪会出现在这里……',
  197. '落单的精灵:恭喜你,它是你的伙伴了!',
  198. ]
  199. this.showDialog(this.mNPC2,text,()=>{
  200. this.getPet()
  201. this.npcDialog3()
  202. })
  203. }
  204. private getPet(){
  205. let node = cc.instantiate(this.mPetPrefab);
  206. node.group = GroupType.A;
  207. node.x = this.node.x + this.mPet.x
  208. node.y = this.node.y + this.mPet.y
  209. let sp = node.addComponent(PSprite);
  210. let attrData = this.ff.main.sManage.getMonsterData(1003);
  211. sp.setAttrData(attrData)
  212. this.ff.addRole(sp);
  213. sp.hp = sp.attrData.hp
  214. sp.addComponent(AIPet);
  215. this.mPet.removeFromParent();
  216. }
  217. private npcDialog3(){
  218. let text = [
  219. '小法师,我要走了。我得去寻找我的弟弟。',
  220. ]
  221. this.showDialog(this.mNPC2,text,()=>{
  222. this.npc3()
  223. })
  224. }
  225. private npc3(){
  226. this.mNPC3.active = true
  227. cc.tween(this.mNPC3).sequence(
  228. cc.moveTo(1,cc.v2(3340,3943)),
  229. cc.callFunc(()=>{
  230. this.npc3Dialog()
  231. })
  232. ).start()
  233. }
  234. private npc3Dialog(){
  235. let text = [
  236. '强大的法师,请……啊!!!',
  237. ]
  238. this.showDialog(this.mNPC3,text,()=>{
  239. this.npc2T()
  240. })
  241. }
  242. /**
  243. * NPC2踢飞NPC3
  244. */
  245. private npc2T(){
  246. cc.tween(this.mNPC2).sequence(
  247. cc.moveTo(0.5,cc.v2(3340,3943)),
  248. cc.callFunc(()=>{
  249. this.npc3Fly()
  250. })
  251. ).start()
  252. }
  253. private npc3Fly(){
  254. cc.tween(this.mNPC3).sequence(
  255. cc.moveBy(0.7,cc.v2(800,800)),
  256. cc.callFunc(()=>{
  257. this.npcDialog4()
  258. }),
  259. cc.destroySelf()
  260. ).start()
  261. cc.tween(this.mNPC3).repeatForever(
  262. cc.rotateBy(0.1,60)
  263. ).start()
  264. }
  265. private npcDialog4(){
  266. let text = [
  267. '不用为别的事物分心。小法师,你似乎刚刚成为法师?',
  268. ]
  269. this.showDialog(this.mNPC2,text,()=>{
  270. this.meDialog2()
  271. })
  272. }
  273. private meDialog2(){
  274. let text = [
  275. '是的。',
  276. '告知失落之地的事情。',
  277. ]
  278. this.showDialog(this.ff.mainSprite.node,text,()=>{
  279. this.npcDialog5()
  280. })
  281. }
  282. private npcDialog5(){
  283. let text = [
  284. '等等!!',
  285. '发生了这么可怕的事情,怎么现在才告诉我。',
  286. '我改变了主意,小法师,在森林中等我。'
  287. ]
  288. this.showDialog(this.mNPC2,text,()=>{
  289. this.npc2Move()
  290. })
  291. }
  292. private npc2Move(){
  293. cc.tween(this.mNPC2).sequence(
  294. cc.moveBy(1,cc.v2(0,-500)),
  295. cc.callFunc(()=>{
  296. this.openDoor()
  297. }),
  298. cc.destroySelf()
  299. ).start()
  300. }
  301. private openDoor(){
  302. this.pause()
  303. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  304. cc.tween(this.node).sequence(
  305. cc.callFunc(() => {
  306. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  307. const element = this.mFenceTrigger[i];
  308. this.showFence(element, 'open');
  309. }
  310. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  311. }),
  312. cc.delayTime(1),
  313. cc.callFunc(() => {
  314. this.resume()
  315. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  316. const element = this.mFenceTrigger[i];
  317. element.active = false;
  318. }
  319. })
  320. ).start();
  321. })
  322. }
  323. private showFence(element, action) {
  324. let nodes = element.children;
  325. for (let i = 0; i < nodes.length; i++) {
  326. const element = nodes[i];
  327. let spine = element.getComponent(sp.Skeleton);
  328. if (spine) {
  329. spine.setAnimation(0, action, false);
  330. }
  331. }
  332. }
  333. }