import User from "../../FrameWork/User/User";
import Common5 from "../../Platform/th/Common5";
import GameBaseScript from "../GameRoomRes/GameBaseScript";
import TaskManager, { MainTaskIdEnum } from "../JuQingChat/TaskManager";
import ChuShiXieHuiManager from "../Manager/ChuShiXieHuiManager";
import UserManager from "../Manager/UserManager";
import NewGuideScript from "../NewGuide/NewGuideScript";
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
import CommonTips from "../SCommon/CommonTips";
import GetAward from "../SCommon/GetAward";
import DHBase from "./DHBase";
const { ccclass, property, disallowMultiple, menu } = cc._decorator;

@ccclass
@disallowMultiple()
@menu('对话剧情/DH_29')
export default class DH_29 extends DHBase {
    chatConfig = [
        { effectUrl: 'DH/DH_29/sound/小子,没想到你竟然真的敢来市区。', delayTime: 4.35, str: '小子,没想到你竟然真的敢来市区。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_29/sound/以为我不知道你们的手段,断供我食材?就这。。。呵呵', delayTime: 5.29, str: '以为我不知道你们的手段,断供我食材?就这。。。呵呵', posi: '-1' },
        { effectUrl: 'DH/DH_29/sound/你怎么知道我的计划?又靠你那师傅?', delayTime: 3.52, str: '你怎么知道我的计划?又靠你那师傅?', posi: 'qipao2' },
        { effectUrl: 'DH/DH_29/sound/就不告诉你,气死你。哈哈!', delayTime: 2.6, str: '就不告诉你,气死你。哈哈!', posi: '-1' },
        { effectUrl: 'DH/DH_29/sound/你完了,你彻底完了,竟然敢如此羞辱我。', delayTime: 5.58, str: '你完了,你彻底完了,竟然敢如此羞辱我。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_29/sound/住手,以为蒙面我就不认识你们了?还不快滚。', delayTime: 4.06, str: '住手,以为蒙面我就不认识你们了?还不快滚。', posi: 'qipao1' },
        { effectUrl: 'DH/DH_29/sound/怎么样,你没事吧。我送你去医院吧。', delayTime: 3.46, str: '怎么样,你没事吧。我送你去医院吧。', posi: 'qipao3' },
        { effectUrl: 'DH/DH_29/sound/不用了,没什么事,回去冰敷下就好了。谢谢你了。', delayTime: 4.06, str: '不用了,没什么事,回去冰敷下就好了。谢谢你了。', posi: '-1' },
        { effectUrl: 'DH/DH_29/sound/真是太对不起了。我回去一定会想办法给您补偿的。', delayTime: 4.43, str: '真是太对不起了。我回去一定会想办法给您补偿的。', posi: 'qipao3' },
    ]

    @property(sp.Skeleton)
    nanzhu: sp.Skeleton = null
    @property(sp.Skeleton)
    nanzhu_big: sp.Skeleton = null

    @property(sp.Skeleton)
    liujiahao: sp.Skeleton = null
    @property(sp.Skeleton)
    liujiahao_big: sp.Skeleton = null

    @property(sp.Skeleton)
    liuruyan: sp.Skeleton = null

    @property(sp.Skeleton)
    quan: sp.Skeleton = null
    @property(sp.Skeleton)
    jiao: sp.Skeleton = null


    @property(cc.Node)
    m_bg: cc.Node = null
    @property(cc.Node)
    MoveNodes: cc.Node = null

    start() {
        Common5.playRemoteAudioMusic("remotesound/effect/紧张氛围-10秒", true)
        Common5.preLoadRemoteAudioByChatConfig(this.chatConfig);
        super.start();
        this.continueStory();
        // this.scheduleOnce(() => {
        //     PrefabManage.preloadPrefabByType(GameType.DH_299)
        // })
    }

    // 继续剧情
    continueStory() {
        this.scheduleOnce(() => {
            PrefabManage.preloadPrefabByType(GameType.DH_30)
        })
        // this.nanzhu_big.setAnimation(0, "待机", true)
        // this.liujiahao_big.setAnimation(0, "待机", true)
        this.nanzhu.node.active = true
        this.liujiahao.node.active = true
        this.liuruyan.node.active = false
        this.liujiahao.setAnimation(0, "柳加豪待机", true)
        const dialogEvents = [
            // (func) => {
            //     this.runBg(0, 2, this.MoveNodes.getChildByName("柳加豪"), () => {
            //         func()
            //     })
            // },
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.liujiahao.setAnimation(0, "柳加豪说话", true)
                });
            },
            (func) => {
                this.liujiahao.setAnimation(0, "柳加豪待机", true)
                // this.runBg(1, 2, this.MoveNodes.getChildByName("男主"), () => {
                func()
                // })
            },
            (func) => {
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    this.nanzhu.setAnimation(0, "男主嘲笑说话", true)
                });
            },
            (func) => {
                this.nanzhu.setAnimation(0, "男主待机", true)
                // this.runBg(1, 2, this.MoveNodes.getChildByName("柳加豪"), () => {
                func()
                // })
            },
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.liujiahao.setAnimation(0, "柳加豪说话", true)
                });
            },
            (func) => {
                this.liujiahao.setAnimation(0, "柳加豪待机", true)
                // this.runBg(1, 2, this.MoveNodes.getChildByName("男主"), () => {
                func()
                // })
            },
            (func) => {
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    this.nanzhu.setAnimation(0, "男主嘲笑说话", true)
                });
            },
            (func) => {
                this.nanzhu.node.active = true
                this.liujiahao.node.active = true
                this.nanzhu.setAnimation(0, "男主待机", true)
                this.liujiahao.setAnimation(0, "柳加豪待机", true)
                this.nanzhu_big.node.active = false
                this.liujiahao_big.node.active = false
                // this.runBg(1, 1, this.node, () => {
                func()
                // })
            },
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.liujiahao.setAnimation(0, "柳加豪说话", true)
                });
            },
            (func) => {
                // 柳家豪消失,出现两个黑衣人。啪啪一拳一脚(动效)揍了男主一顿的插图。
                this.liujiahao.setAnimation(0, "柳加豪消失", false)
                this.liujiahao.setCompleteListener(() => {
                    this.liujiahao.setCompleteListener(null)
                    this.scheduleOnce(() => {
                        this.liujiahao.setAnimation(0, "混混出现", false)
                        this.liujiahao.setCompleteListener(() => {
                            this.liujiahao.setCompleteListener(null)
                            this.liujiahao.setAnimation(0, "混混待机", true)
                            Common5.playRemoteAudioEffect("remotesound/effect/挨打声")
                            this.quan.node.active = true
                            this.quan.timeScale = 0.5
                            this.quan.setAnimation(0, "animation", false)
                            this.quan.setCompleteListener(() => {
                                this.quan.setCompleteListener(null)
                                this.quan.node.active = false
                                Common5.playRemoteAudioEffect("remotesound/effect/挨打声")
                                this.jiao.node.active = true
                                this.jiao.timeScale = 0.5
                                this.jiao.setCompleteListener(() => {
                                    this.jiao.setCompleteListener(null)
                                    this.jiao.node.active = false
                                    this.nanzhu.setAnimation(0, "男主躺待机", true)
                                    func()
                                })
                            })
                        })
                    }, 1)
                })
            },
            (func) => {
                this.liuruyan.node.active = true
                this.liuruyan.setAnimation(0, "柳如燕出场", false)
                this.liuruyan.setCompleteListener(() => {
                    this.liuruyan.setCompleteListener(null)
                    this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                        this.liuruyan.setAnimation(0, "柳如燕说话", true)
                    });
                })
            },
            (func) => {
                this.liuruyan.setAnimation(0, "柳如燕待机", true)
                // 一个黑衣人踩在男主身上,从身上收脚转身对着燕子躬身后消失(动效)
                this.liujiahao.setAnimation(0, "混混离开", false)
                this.liujiahao.setCompleteListener(() => {
                    this.liujiahao.setCompleteListener(null)
                    this.liujiahao.node.active = false
                    this.nanzhu.node.active = false
                    this.liuruyan.setAnimation(0, "柳如燕扶人", false)
                    this.liuruyan.setCompleteListener(() => {
                        this.liuruyan.setCompleteListener(null)
                        func()
                    })
                })
            },
            (func) => {
                this.liuruyan.setAnimation(0, "柳如燕男主待机", true)
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.liuruyan.setAnimation(0, "柳如燕男主女说话", true)
                });
            },
            (func) => {
                this.liuruyan.setAnimation(0, "柳如燕男主待机", true)
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    this.liuruyan.setAnimation(0, "柳如燕男主男说话", true)
                });
            },
            (func) => {
                this.liuruyan.setAnimation(0, "柳如燕男主待机", true)
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.liuruyan.setAnimation(0, "柳如燕男主女说话", true)
                });
            },
        ]
        const dialogCallFunc = (logEvents: any[]) => {
            logEvents.shift()(() => {
                if (logEvents.length > 0) {
                    dialogCallFunc(logEvents);
                } else {
                    TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_535)
                    // TaskManager.setCurTask(MainTaskIdEnum.MainTask_536)
                    // PrefabManage.loadPrefabByType(GameType.commonTips, null, (node) => {
                    //     let config = ChuShiXieHuiManager.getManagerConfigById(3)
                    //     node.getComponent(CommonTips).init(`认证一级面点师需要达到的条件:人物等级${config.dengji},报名费用:${Common5.getNumberChangeHanzi(config.moneystr)}`, () => {
                    PrefabManage.showBlackGuoDu(() => {
                        this.node.removeFromParent()
                        this.node.destroy()
                        PrefabManage.loadPrefabByType(GameType.MainHall)
                    })
                    //     })
                    // })
                    // PrefabManage.loadPrefabByType(GameType.GetAward, null, (prefabNode) => {
                    //     let goods = [{ goodId: 1733, goodNum: 1 }];
                    //     prefabNode.getComponent(GetAward).initView(goods, () => {
                    //         // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_530)
                    //         // User.setRoomGoodStatus("DH_299")
                    //         // UserManager.clearAndaddStructureFlash("cf_FengRenYuan")
                    //     });
                    // });
                    // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_202)
                    // TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_203)
                    // this.node.destroy()
                }
            });
        }
        dialogCallFunc(dialogEvents);
    }

    guideView(nodeArray, opacity = -1) {
        PrefabManage.loadPrefabByType(GameType.GuideMskNode, this.node, (prefab) => {
            // prefab.zIndex = 199
            let guideNodeArray = nodeArray
            let firstNode = guideNodeArray.shift()
            prefab.getComponent(NewGuideScript).setBindNode(firstNode, guideNodeArray)
            if (opacity != -1) {
                prefab.getComponent(NewGuideScript).setOpacityMaskNode(opacity)
            }
        })
    }

    runBg(time, scale, endnode, callFunc) {
        cc.tween(this.m_bg)
            .to(time, { scale: scale })
            .start()
        cc.tween(this.m_bg)
            .sequence(
                cc.tween().to(time, { position: cc.v2(-endnode.position.x * scale, -endnode.position.y * scale) }),
                cc.tween().call(() => {
                    callFunc()
                })
            )
            .start()
    }
}