Guide1.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. import i18n from "../../../../i18n/i18n";
  2. import DialogButton from "../../box/DialogButton";
  3. import { SpriteActionType } from "../../object/FSprite";
  4. import WOneByone from "../map1/WOneByone";
  5. import GuideBase from "./GuideBase";
  6. /**
  7. * 第一个引导剧情
  8. */
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class Guide1 extends GuideBase {
  12. @property(cc.Prefab)
  13. mMapDialog: cc.Prefab = null;
  14. @property(sp.Skeleton)
  15. spine: sp.Skeleton = null;//餐桌动画
  16. @property(cc.Node)
  17. speak1: cc.Node = null;//1:洛基:祝众神之王与王后,仙福永享寿与天齐
  18. @property([cc.Node])
  19. speak2: Array<cc.Node> = [];//2:干杯
  20. @property(cc.Node)
  21. speak3: cc.Node = null;//3小兵:报告,巨人来袭
  22. @property(cc.Node)
  23. speak3Move: cc.Node = null;//小兵目标位置
  24. @property(cc.Node)
  25. speak4: cc.Node = null;//4 洛基:跑……
  26. @property(cc.Node)
  27. speak5: cc.Node = null;//5 提尔:索尔:杀……
  28. @property(cc.Node)
  29. speak6: cc.Node = null;//5 芙蕾雅,弗雷:……
  30. @property(cc.Node)
  31. speak7: cc.Node = null;//6 npc
  32. @property(cc.Prefab)
  33. mChoiseDialog: cc.Prefab = null;//选择对话框
  34. //播放炸弹动画
  35. //主角入场
  36. onLoad(){
  37. this.node.zIndex = -9999;
  38. }
  39. public run(){
  40. let map = this.ff.mMap;
  41. let winSize = cc.winSize
  42. let camera = map.mCamera;
  43. camera.node.x = this.node.x - winSize.width/2;
  44. camera.node.y = this.node.y - winSize.height/2;
  45. this.ff.pauseSprite(true);
  46. this.ff.mBlockInputEvents.active = true;
  47. this.showDialog1();
  48. }
  49. private showDialog1(){
  50. let dialogs = [
  51. '干的不错',
  52. '身为阿萨神族的守护者,保卫阿斯加德不受邪恶的侵扰是我们的职责',
  53. '你叫什么名字?',
  54. '真不错,听名字就知道有前途',
  55. '有朝一日,希望你能成为阿斯加德新的守护神……',
  56. '来,一起祝众神之王与王后,仙福永享寿与天齐',
  57. ];
  58. let node = cc.instantiate(this.mMapDialog);
  59. node.group = 'map'
  60. node.zIndex = 9999;
  61. node.x = this.node.x + this.speak1.x;
  62. node.y = this.node.y + this.speak1.y + this.speak1.height;
  63. node.parent = this.ff.mMap.mSprites;
  64. let obo = node.getComponent(WOneByone);
  65. obo.dialogs = dialogs;
  66. obo.setCallback(()=>{
  67. node.destroy();
  68. this.ff.setBlockInputCallback(null);
  69. // this.ff.pauseSprite(false);
  70. // this.ff.mBlockInputEvents.active = false;
  71. // this.node.removeComponent(cc.PhysicsBoxCollider);
  72. this.showDialog2();
  73. });
  74. this.ff.setBlockInputCallback(()=>{
  75. obo.jump();
  76. });
  77. obo._start();
  78. }
  79. private showDialog2(){
  80. let dialogs = [
  81. '干杯',
  82. ];
  83. let nodes:Array<cc.Node> = []
  84. for (let i = 0; i < this.speak2.length; i++) {
  85. const element = this.speak2[i];
  86. let node = cc.instantiate(this.mMapDialog);
  87. node.group = 'map'
  88. node.zIndex = 9999;
  89. node.x = this.node.x + element.x;
  90. node.y = this.node.y + element.y + element.height;
  91. node.parent = this.ff.mMap.mSprites;
  92. let obo = node.getComponent(WOneByone);
  93. obo.dialogs = dialogs;
  94. nodes.push(node);
  95. obo._start();
  96. }
  97. this.ff.setBlockInputCallback(null);
  98. cc.tween(this.node).sequence(
  99. cc.delayTime(1),
  100. cc.callFunc(()=>{
  101. nodes.forEach(da => {
  102. da.destroy();
  103. });
  104. this.showDialog3();
  105. })
  106. ).start();
  107. }
  108. //小兵跑出来,然后说话
  109. private showDialog3(){
  110. cc.tween(this.speak3).sequence(
  111. cc.moveTo(1,this.speak3Move.getPosition()),
  112. cc.callFunc(()=>{
  113. this.showDialog3_1()
  114. })
  115. ).start()
  116. }
  117. private showDialog3_1(){
  118. let dialogs = [
  119. '报…报告……',
  120. '报告各位大神,邪恶四巨兽军团正在接近…',
  121. '从彩虹桥正面攻入…',
  122. '请…请…请……',
  123. ];
  124. let node = cc.instantiate(this.mMapDialog);
  125. node.group = 'map'
  126. node.zIndex = 9999;
  127. node.x = this.node.x + this.speak3.x;
  128. node.y = this.node.y + this.speak3.y + this.speak3.height;
  129. node.parent = this.ff.mMap.mSprites;
  130. let obo = node.getComponent(WOneByone);
  131. obo.dialogs = dialogs;
  132. obo.setCallback(()=>{
  133. node.destroy();
  134. this.ff.setBlockInputCallback(null);
  135. this.showDialog4();
  136. });
  137. this.ff.setBlockInputCallback(()=>{
  138. obo.jump();
  139. });
  140. obo._start();
  141. }
  142. private showDialog4(){
  143. let dialogs = [
  144. '这是什么鬼东西',
  145. ];
  146. let node = cc.instantiate(this.mMapDialog);
  147. node.group = 'map'
  148. node.zIndex = 9999;
  149. node.x = this.node.x + this.speak4.x;
  150. node.y = this.node.y + this.speak4.y + this.speak4.height;
  151. node.parent = this.ff.mMap.mSprites;
  152. let obo = node.getComponent(WOneByone);
  153. obo.dialogs = dialogs;
  154. obo.setCallback(()=>{
  155. node.destroy();
  156. this.ff.setBlockInputCallback(null);
  157. // this.ff.pauseSprite(false);
  158. // this.ff.mBlockInputEvents.active = false;
  159. this.showDialog5();
  160. });
  161. this.ff.setBlockInputCallback(()=>{
  162. obo.jump();
  163. });
  164. obo._start();
  165. }
  166. private showDialog5(){
  167. let dialogs = [
  168. '伟大的圣母玛利亚呀',
  169. ];
  170. let node = cc.instantiate(this.mMapDialog);
  171. node.group = 'map'
  172. node.zIndex = 9999;
  173. node.x = this.node.x + this.speak5.x;
  174. node.y = this.node.y + this.speak5.y + this.speak5.height;
  175. node.parent = this.ff.mMap.mSprites;
  176. let obo = node.getComponent(WOneByone);
  177. obo.dialogs = dialogs;
  178. obo.setCallback(()=>{
  179. node.destroy();
  180. this.ff.setBlockInputCallback(null);
  181. // this.ff.pauseSprite(false);
  182. // this.ff.mBlockInputEvents.active = false;
  183. this.showDialog6();
  184. });
  185. this.ff.setBlockInputCallback(()=>{
  186. obo.jump();
  187. });
  188. obo._start();
  189. }
  190. private showDialog6(){
  191. let dialogs = [
  192. '……',
  193. ];
  194. let node = cc.instantiate(this.mMapDialog);
  195. node.group = 'map'
  196. node.zIndex = 9999;
  197. node.x = this.node.x + this.speak6.x;
  198. node.y = this.node.y + this.speak6.y + this.speak6.height;
  199. node.parent = this.ff.mMap.mSprites;
  200. let obo = node.getComponent(WOneByone);
  201. obo.dialogs = dialogs;
  202. obo.setCallback(()=>{
  203. node.destroy();
  204. this.ff.setBlockInputCallback(null);
  205. // this.ff.pauseSprite(false);
  206. // this.ff.mBlockInputEvents.active = false;
  207. this.showDialog7();
  208. });
  209. this.ff.setBlockInputCallback(()=>{
  210. obo.jump();
  211. });
  212. obo._start();
  213. }
  214. //播放炸弹
  215. private showDialog7(){
  216. this.spine.setCompleteListener(() => {
  217. this.spine.setCompleteListener(null);
  218. this.spine.setAnimation(0, 'idle', true);
  219. this.dead();
  220. this.mainMove();
  221. });
  222. this.spine.setAnimation(0, 'in', false);
  223. }
  224. private dead(){
  225. let spines = this.getAllSpine();
  226. for (let i = 0; i < spines.length; i++) {
  227. const spine = spines[i];
  228. spine.setCompleteListener(()=>{
  229. spine.setCompleteListener(null);
  230. spine.setAnimation(0, SpriteActionType.yun2, true);
  231. });
  232. spine.setAnimation(0, SpriteActionType.yun, false);
  233. }
  234. }
  235. private getAllSpine():Array<sp.Skeleton>{
  236. let nodes = this.node.children;
  237. let spines = [];
  238. for (let i = 0; i < nodes.length; i++) {
  239. const node = nodes[i];
  240. let spriteNode = node.getChildByName('juese01');
  241. if (spriteNode) {
  242. spriteNode.zIndex = 2
  243. let spineNode0 = spriteNode.getChildByName('spineRight');
  244. if(spineNode0){
  245. let spine = spineNode0.getComponent(sp.Skeleton);
  246. spines.push(spine);
  247. }
  248. }
  249. }
  250. return spines;
  251. }
  252. //主角移动进场
  253. private mainMove(){
  254. let mainSprite = this.ff.mainSprite;
  255. let pos = cc.v2()
  256. pos.x = this.node.x + this.speak3Move.x;
  257. pos.y = this.node.y + this.speak3Move.y;
  258. mainSprite.playAction2(SpriteActionType.run);
  259. cc.tween(mainSprite.node).sequence(
  260. cc.moveTo(1,pos),
  261. cc.callFunc(()=>{
  262. mainSprite.playAction2(SpriteActionType.stand);
  263. this.showDialog8();
  264. })
  265. ).start();
  266. }
  267. private showDialog8(){
  268. let dialogs = [
  269. '危险,保护众神之王,保护众神之母',
  270. '保护,保护……',
  271. ];
  272. let mainSprite = this.ff.mainSprite;
  273. let node = cc.instantiate(this.mMapDialog);
  274. node.group = 'map'
  275. node.zIndex = 9999;
  276. node.x = mainSprite.node.x;
  277. node.y = mainSprite.node.y + mainSprite.node.height;
  278. node.parent = this.ff.mMap.mSprites;
  279. let obo = node.getComponent(WOneByone);
  280. obo.dialogs = dialogs;
  281. obo.setCallback(()=>{
  282. node.destroy();
  283. this.ff.setBlockInputCallback(null);
  284. // this.ff.pauseSprite(false);
  285. // this.ff.mBlockInputEvents.active = false;
  286. this.showDialog9();
  287. });
  288. this.ff.setBlockInputCallback(()=>{
  289. obo.jump();
  290. });
  291. obo._start();
  292. }
  293. private showDialog9(){
  294. this.speak7.active = true;
  295. let spine = this.speak7.getChildByName('chuansongmen1');
  296. spine.active = true;
  297. let monster = this.speak7.getChildByName('monster56');
  298. monster.active = true;
  299. monster.opacity = 0;
  300. cc.tween(monster).sequence(
  301. cc.fadeIn(1),
  302. cc.callFunc(()=>{
  303. this.showDialog9_1();
  304. })
  305. ).start();
  306. }
  307. private showDialog9_1(){
  308. let dialogs = [
  309. '亲爱的孩子,谁来保护你呢?',
  310. ];
  311. let mainNode = this.speak7;
  312. let node = cc.instantiate(this.mMapDialog);
  313. node.group = 'map'
  314. node.zIndex = 9999;
  315. node.x = this.node.x + mainNode.x;
  316. node.y = this.node.y + mainNode.y + mainNode.height;
  317. node.parent = this.ff.mMap.mSprites;
  318. let obo = node.getComponent(WOneByone);
  319. obo.dialogs = dialogs;
  320. obo.setCallback(()=>{
  321. node.destroy();
  322. this.ff.setBlockInputCallback(null);
  323. // this.ff.pauseSprite(false);
  324. // this.ff.mBlockInputEvents.active = false;
  325. this.showDialog9_1_1();
  326. });
  327. this.ff.setBlockInputCallback(()=>{
  328. obo.jump();
  329. });
  330. obo._start();
  331. }
  332. private showDialog9_1_1(){
  333. let node:cc.Node = cc.instantiate(this.mChoiseDialog)
  334. node.parent = this.ff.node
  335. let dialog = node.getComponent(DialogButton);
  336. dialog.setCallback(()=>{
  337. node.destroy();
  338. this.showDialog9_1_2();
  339. })
  340. }
  341. private showDialog9_1_2(){
  342. let dialogs = [
  343. '剧情要改……',
  344. ];
  345. let mainNode = this.speak7;
  346. let node = cc.instantiate(this.mMapDialog);
  347. node.group = 'map'
  348. node.zIndex = 9999;
  349. node.x = this.node.x + mainNode.x;
  350. node.y = this.node.y + mainNode.y + mainNode.height;
  351. node.parent = this.ff.mMap.mSprites;
  352. let obo = node.getComponent(WOneByone);
  353. obo.dialogs = dialogs;
  354. obo.setCallback(()=>{
  355. node.destroy();
  356. this.ff.setBlockInputCallback(null);
  357. // this.ff.pauseSprite(false);
  358. // this.ff.mBlockInputEvents.active = false;
  359. this.showDialog9_2_1();
  360. });
  361. this.ff.setBlockInputCallback(()=>{
  362. obo.jump();
  363. });
  364. obo._start();
  365. }
  366. private showDialog9_2_1(){
  367. let node = this.speak7.getChildByName('1')
  368. node.active = true;
  369. let chuansongmen2 = this.speak7.getChildByName('chuansongmen2');
  370. chuansongmen2.active = true;
  371. this.ff.setBlockInputCallback(()=>{
  372. node.active = false;
  373. chuansongmen2.active = false;
  374. this.showDialog9_2_2();
  375. });
  376. }
  377. private showDialog9_2_2(){
  378. let dialogs = [
  379. '哎呀,搞错了',
  380. '再来',
  381. ];
  382. let mainNode = this.speak7;
  383. let node = cc.instantiate(this.mMapDialog);
  384. node.group = 'map'
  385. node.zIndex = 9999;
  386. node.x = this.node.x + mainNode.x;
  387. node.y = this.node.y + mainNode.y + mainNode.height;
  388. node.parent = this.ff.mMap.mSprites;
  389. let obo = node.getComponent(WOneByone);
  390. obo.dialogs = dialogs;
  391. obo.setCallback(()=>{
  392. node.destroy();
  393. this.ff.setBlockInputCallback(null);
  394. // this.ff.pauseSprite(false);
  395. // this.ff.mBlockInputEvents.active = false;
  396. this.showDialog9_2_3();
  397. });
  398. this.ff.setBlockInputCallback(()=>{
  399. obo.jump();
  400. });
  401. obo._start();
  402. }
  403. private showDialog9_2_3(){
  404. let nodes:Array<cc.Node> = [];
  405. for (let i = 2; i <= 5; i++) {
  406. let node = this.speak7.getChildByName(''+i)
  407. nodes.push(node)
  408. }
  409. let index = 0;
  410. let chuansongmen2 = this.speak7.getChildByName('chuansongmen2');
  411. chuansongmen2.active = true;
  412. nodes[0].active = true;
  413. let dialogs = [
  414. '巨狼芬尼尔',
  415. '黑龙尼德霍格',
  416. '尘世巨蟒耶梦加德',
  417. '死境之主海拉',
  418. ];
  419. let mainNode = this.speak7;
  420. let node = cc.instantiate(this.mMapDialog);
  421. node.group = 'map'
  422. node.zIndex = 9999;
  423. node.x = this.node.x + mainNode.x;
  424. node.y = this.node.y + mainNode.y + mainNode.height;
  425. node.parent = this.ff.mMap.mSprites;
  426. let obo = node.getComponent(WOneByone);
  427. obo.isOver = true;
  428. obo.label.string = i18n.t(dialogs[0])
  429. this.ff.setBlockInputCallback(()=>{
  430. index ++;
  431. if(index >= nodes.length){
  432. node.destroy();
  433. nodes[index-1].active = false;
  434. chuansongmen2.active = false;
  435. this.showDialog9_3();
  436. }else{
  437. nodes[index-1].active = false;
  438. nodes[index].active = true;
  439. obo.label.string = i18n.t(dialogs[index])
  440. }
  441. });
  442. }
  443. private showDialog9_3(){
  444. let dialogs = [
  445. '剧情要改',
  446. ];
  447. let mainNode = this.speak7;
  448. let node = cc.instantiate(this.mMapDialog);
  449. node.group = 'map'
  450. node.zIndex = 9999;
  451. node.x = this.node.x + mainNode.x;
  452. node.y = this.node.y + mainNode.y + mainNode.height;
  453. node.parent = this.ff.mMap.mSprites;
  454. let obo = node.getComponent(WOneByone);
  455. obo.dialogs = dialogs;
  456. obo.setCallback(()=>{
  457. node.destroy();
  458. this.ff.setBlockInputCallback(null);
  459. this.ff.pauseSprite(false);
  460. this.ff.mBlockInputEvents.active = false;
  461. this.speak7.active = false;
  462. });
  463. this.ff.setBlockInputCallback(()=>{
  464. obo.jump();
  465. });
  466. obo._start();
  467. }
  468. }