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_36')
export default class DH_36 extends DHBase {
    chatConfig = [
        { effectUrl: 'DH/DH_36/sound/汉升啊,没想到你天赋这么好,我徒儿有厨神之姿啊。', delayTime: 6.94, str: '汉升啊,没想到你天赋这么好,我徒儿有厨神之姿啊。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_36/sound/师傅,我哪有什么天赋呀,全靠您的悉心栽培。', delayTime: 4.04, str: '师傅,我哪有什么天赋呀,全靠您的悉心栽培。', posi: '-1' },
        { effectUrl: 'DH/DH_36/sound/你就别谦虚了,等你达到特一级,就来接任会长吧。', delayTime: 5.87, str: '你就别谦虚了,等你达到特一级,就来接任会长吧。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_36/sound/啊,师傅!我到特一级面点师就做会长吗?这太急了吧。', delayTime: 5.71, str: '啊,师傅!我到特一级面点师就做会长吗?这太急了吧。', posi: '-1' },
        { effectUrl: 'DH/DH_36/sound/嗯,冲击厨神需要做过会长,你先去达到特一级面点师再说。', delayTime: 7.54, str: '嗯,冲击厨神需要做过会长,你先去达到特一级面点师再说。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_36/sound/(柳家,等我当上会长再来收拾你们)', delayTime: 3.38, str: '(柳家,等我当上会长再来收拾你们)', posi: '-1' },
    ]

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

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

    start() {
        Common5.playRemoteAudioMusic("remotesound/effect/茶厅音乐", true)
        Common5.preLoadRemoteAudioByChatConfig(this.chatConfig);
        super.start();
        this.continueStory();
        // this.scheduleOnce(() => {
        //     PrefabManage.preloadPrefabByType(GameType.DH_369)
        // })
    }

    // 继续剧情
    continueStory() {
        this.scheduleOnce(() => {
            PrefabManage.preloadPrefabByType(GameType.DH_37)
        })
        this.nanzhu.setAnimation(0, "男主待机", true)
        this.weihuizhang.setAnimation(0, "魏会长待机", true)
        const dialogEvents = [
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.weihuizhang.setAnimation(0, "魏会长说话", true)
                });
            },
            (func) => {
                this.weihuizhang.setAnimation(0, "魏会长待机", true)
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    this.nanzhu.setAnimation(0, "男主说话", true)
                });
            },
            (func) => {
                this.nanzhu.setAnimation(0, "男主待机", true)
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.weihuizhang.setAnimation(0, "魏会长说话", true)
                });
            },
            (func) => {
                this.weihuizhang.setAnimation(0, "魏会长待机", true)
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    this.nanzhu.setAnimation(0, "男主说话", true)
                });
            },
            (func) => {
                this.nanzhu.setAnimation(0, "男主待机", true)
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.weihuizhang.setAnimation(0, "魏会长说话", true)
                });
            },
            (func) => {
                this.weihuizhang.setAnimation(0, "魏会长待机", true)
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    // this.nanzhu.setAnimation(0, "男主说话", true)
                });
            },
        ]
        const dialogCallFunc = (logEvents: any[]) => {
            logEvents.shift()(() => {
                if (logEvents.length > 0) {
                    dialogCallFunc(logEvents);
                } else {
                    this.nanzhu.setAnimation(0, "男主待机", true)
                    TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_547_1)
                    TaskManager.setCurTask(MainTaskIdEnum.MainTask_547_2)
                    // TaskManager.setCurTask(MainTaskIdEnum.MainTask_548)
                    PrefabManage.loadPrefabByType(GameType.commonTips, null, (node) => {
                        let config = ChuShiXieHuiManager.getManagerConfigById(5)
                        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_369")
                    //         // 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()
    }
}