123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- import FqLogin from "../../../../login/FqLogin";
- import { AudioMgr } from "../../../../main/ViewManage";
- import FFCalAttr from "../../../data/FFCalAttr";
- import AIPet from "../../object/AI/AIPet";
- import { GroupType } from "../../object/FObject";
- import { SpriteActionType } from "../../object/FSprite";
- import PSprite from "../../object/PSprite";
- import BaseEvent from "../base/BaseEvent";
- const { ccclass, property } = cc._decorator;
- /**
- * 第一个宠物牢笼
- */
- @ccclass
- export default class FCagePet1 extends BaseEvent {
- @property({
- displayName: '解救的伙伴id',
- })
- mPetId: number = 1;
- @property({
- displayName: '没有钥匙的对话',
- type: [cc.String]
- })
- dialog1: Array<string> = [];
- @property({
- displayName: '牢笼动画',
- tooltip: '显示牢笼的动画',
- type: sp.Skeleton
- })
- spine: sp.Skeleton = null;//牢笼
- @property({
- displayName: '按钮图标',
- type: cc.SpriteFrame
- })
- mTipsIcon: cc.SpriteFrame = null;
- @property({
- displayName: '靠近的提示',
- type: cc.Sprite
- })
- mIcon: cc.Sprite = null;//靠近后的提示
- @property({
- type: [cc.SpriteFrame],
- displayName: '不同状态的图标'
- })
- mIconFrame: Array<cc.SpriteFrame> = [];
- @property({
- displayName: '牢笼中的伙伴',
- type: cc.Node
- })
- mPet: cc.Node = null;//伙伴
- @property({
- displayName: '宠物预制体',
- type: cc.Prefab
- })
- mPetPrefab: cc.Prefab = null;
- @property({
- type: [cc.Node],
- displayName: '需要打开的门'
- })
- mFenceTrigger: Array<cc.Node> = [];
- @property({
- displayName: '落单的精灵',
- type: cc.Node
- })
- mNPC2: cc.Node = null;
- @property({
- displayName: '路过的矮人',
- type: cc.Node
- })
- mNPC3: cc.Node = null;
- private isOver = false;
- onLoad(){
- super.onLoad()
- this.mNPC3.active = false
- }
- onBegin(tag: number) {
- if (this.isOver) {
- return;
- }
- if (tag == 1) {
- this.iconTips(true);
- this.showOpt(this.mTipsIcon, () => {
- this.iconTips(false);
- this.closeOpt()
- this.openCage()
- })
- }
- }
- onEnd(tag: number) {
- if (tag == 1) {
- this.iconTips(false);
- this.closeOpt()
- }
- }
- /**
- *
- * @param show 是否显示提示
- */
- private iconTips(show) {
- if (this.mIcon) {
- if (show) {
- this.mIcon.node.active = true;
- let head = this.ff.mFFheader;
- let count = head.getTmpCount(2001);
- if (count > 0) {
- this.mIcon.spriteFrame = this.mIconFrame[0]
- } else {
- this.mIcon.spriteFrame = this.mIconFrame[1]
- }
- } else {
- this.mIcon.node.active = false;
- }
- }
- }
- //打开牢笼
- private openCage() {
- let head = this.ff.mFFheader;
- let count = head.getTmpCount(2001);
- if (count > 0) {
- head.removeTmpGood(2001, 1);
- this.isOver = true;
- this.pause()
- this.spine.setCompleteListener(() => {
- this.spine.setCompleteListener(null);
- this.movePet()
- });
- if (this.spine.findAnimation("open3")) {
- this.spine.setAnimation(0, 'open3', false);
- } else {
- this.spine.setAnimation(0, 'open', false);
- }
- FqLogin.commitEvent(this.node.name, '', '');
- } else {
- // this.ff.main.showTips('需要一把牢笼钥匙');
- this.showDialog(this.node,this.dialog1,()=>{
- })
- }
- }
- private movePet() {
- let anim = this.mPet.getComponent(cc.Animation);
- let spine = this.mPet.getComponent(sp.Skeleton);
- spine.setAnimation(0, SpriteActionType.run, true);
- anim.on('finished', this.onFinished, this);
- anim.play('cage_pet_move');
- cc.tween(this.mNPC2).sequence(
- cc.moveTo(1,cc.v2(3202,3990)),
- cc.callFunc(()=>{
- this.npcDialog()
- })
- ).start()
- }
- private onFinished(num, string) {
- let anim = this.mPet.getComponent(cc.Animation);
- let spine = this.mPet.getComponent(sp.Skeleton);
- anim.off('finished', this.onFinished, this);
- spine.setAnimation(0, SpriteActionType.stand, true);
- }
- /**
- * 落单的精灵:多么快活的小家伙!
- 落单的精灵:你做了一件好事。做好事的人心地善良,人也会变得漂亮。
- 落单的精灵:我的妈妈告诉我,人类就是这么变漂亮的。
- 角色:……
- 落单的精灵:快看,这只小鹿非常喜欢你。它没有红鼻子,但也非常可爱。
- 落单的精灵:但是它一直待在你身边,这让我有点沮丧。
- */
- private npcDialog(){
- let text = [
- '多么快活的小家伙!',
- '你做了一件好事。做好事的人心地善良,人也会变得漂亮。',
- '我的妈妈告诉我,人类就是这么变漂亮的。',
- '……',
- '快看,这只小鹿非常喜欢你。它没有红鼻子,但也非常可爱。',
- '但是它一直待在你身边,这让我有点沮丧。'
- ]
- this.showDialog(this.mNPC2,text,()=>{
- this.meDialog()
- })
- }
- private meDialog(){
- let text = [
- '你也帮助了它。',
- ]
- this.showDialog(this.ff.mainSprite.node,text,()=>{
- this.npcDialog1()
- })
- }
- private npcDialog1(){
- let text = [
- '等等……它似乎不是普通的小鹿。',
- ]
- this.showDialog(this.mNPC2,text,()=>{
- this.npcDialog2()
- })
- }
- private npcDialog2(){
- let text = [
- '这是一只战斗宠物,难怪会出现在这里……',
- '落单的精灵:恭喜你,它是你的伙伴了!',
- ]
- this.showDialog(this.mNPC2,text,()=>{
- this.getPet()
- this.npcDialog3()
- })
- }
- private getPet(){
- let node = cc.instantiate(this.mPetPrefab);
- node.group = GroupType.A;
- node.x = this.node.x + this.mPet.x
- node.y = this.node.y + this.mPet.y
- let sp = node.addComponent(PSprite);
- let attrData = this.ff.main.sManage.getMonsterData(1003);
- sp.setAttrData(attrData)
- this.ff.addRole(sp);
- sp.hp = sp.attrData.hp
- sp.addComponent(AIPet);
- this.mPet.removeFromParent();
- }
- private npcDialog3(){
- let text = [
- '小法师,我要走了。我得去寻找我的弟弟。',
- ]
- this.showDialog(this.mNPC2,text,()=>{
- this.npc3()
- })
- }
- private npc3(){
- this.mNPC3.active = true
- cc.tween(this.mNPC3).sequence(
- cc.moveTo(1,cc.v2(3340,3943)),
- cc.callFunc(()=>{
- this.npc3Dialog()
- })
- ).start()
- }
- private npc3Dialog(){
- let text = [
- '强大的法师,请……啊!!!',
- ]
- this.showDialog(this.mNPC3,text,()=>{
- this.npc2T()
- })
- }
- /**
- * NPC2踢飞NPC3
- */
- private npc2T(){
- cc.tween(this.mNPC2).sequence(
- cc.moveTo(0.5,cc.v2(3340,3943)),
- cc.callFunc(()=>{
- this.npc3Fly()
- })
- ).start()
- }
- private npc3Fly(){
- cc.tween(this.mNPC3).sequence(
- cc.moveBy(0.7,cc.v2(800,800)),
- cc.callFunc(()=>{
- this.npcDialog4()
- }),
- cc.destroySelf()
- ).start()
- cc.tween(this.mNPC3).repeatForever(
- cc.rotateBy(0.1,60)
- ).start()
- }
- private npcDialog4(){
- let text = [
- '不用为别的事物分心。小法师,你似乎刚刚成为法师?',
- ]
- this.showDialog(this.mNPC2,text,()=>{
- this.meDialog2()
- })
- }
- private meDialog2(){
- let text = [
- '是的。',
- '告知失落之地的事情。',
- ]
- this.showDialog(this.ff.mainSprite.node,text,()=>{
- this.npcDialog5()
- })
- }
- private npcDialog5(){
- let text = [
- '等等!!',
- '发生了这么可怕的事情,怎么现在才告诉我。',
- '我改变了主意,小法师,在森林中等我。'
- ]
- this.showDialog(this.mNPC2,text,()=>{
- this.npc2Move()
- })
- }
- private npc2Move(){
- cc.tween(this.mNPC2).sequence(
- cc.moveBy(1,cc.v2(0,-500)),
- cc.callFunc(()=>{
- this.openDoor()
- }),
- cc.destroySelf()
- ).start()
- }
- private openDoor(){
- this.pause()
- this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
- cc.tween(this.node).sequence(
- cc.callFunc(() => {
- for (let i = 0; i < this.mFenceTrigger.length; i++) {
- const element = this.mFenceTrigger[i];
- this.showFence(element, 'open');
- }
- this.ff.main.playerEffectByPath(AudioMgr.openDoor);
- }),
- cc.delayTime(1),
- cc.callFunc(() => {
- this.resume()
- for (let i = 0; i < this.mFenceTrigger.length; i++) {
- const element = this.mFenceTrigger[i];
- element.active = false;
- }
- })
- ).start();
- })
- }
- private showFence(element, action) {
- let nodes = element.children;
- for (let i = 0; i < nodes.length; i++) {
- const element = nodes[i];
- let spine = element.getComponent(sp.Skeleton);
- if (spine) {
- spine.setAnimation(0, action, false);
- }
- }
- }
- }
|