// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { ryw_Event } from "../../FrameWork/Event/EventEnum";
import EventMgr from "../../FrameWork/Event/EventMgr";
import User from "../../FrameWork/User/User";
import AppPlatform from "../../FrameWork/Util/AppPlatform";
import Common5 from "../../Platform/th/Common5";
import UiBase from "../GameBase/UiBase";
import JuQingManager from "../JuQingChat/JuQingManager";
import TaskManager, { MainTaskIdEnum, MainTaskWZEnum } from "../JuQingChat/TaskManager";
import ChallengeManager from "../Manager/ChallengeManager";
import ChuShiXieHuiManager from "../Manager/ChuShiXieHuiManager";
import DiaoLuoManager from "../Manager/DiaoLuoManager";
import FangChanManager from "../Manager/FangChanManager";
import LevelUpManager from "../Manager/LevelUpManager";
import MiShuManager from "../Manager/MiShuManager";
import ShipuManager from "../Manager/ShipuManager";
import TanWeiManager from "../Manager/TanWeiManager";
import UserManager from "../Manager/UserManager";
import ZiChanManager from "../Manager/ZiChanManager";
import NewGuideScript from "../NewGuide/NewGuideScript";
//import NewGuideScript2 from "../NewGuide/NewGuideScript2";
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
import CommonTips from "../SCommon/CommonTips";
import ZiChan from "../ZiChan/ZiChan";
import ChaoFanWangScript from "./ChaoFanWangScript";

const { ccclass, property } = cc._decorator;

@ccclass
export default class MainHall extends UiBase {


    // LIFE-CYCLE CALLBACKS:
    @property(cc.Label)
    clickMoneyLab: cc.Label = null;

    // onLoad () {}
    @property(cc.Label)
    secondMoneyLab: cc.Label = null;

    @property(cc.Sprite)
    chenghaoPic: cc.Sprite = null;
    @property(cc.Label)
    levelLab: cc.Label = null;
    @property(cc.Label)
    chenghao: cc.Label = null;
    @property(cc.Node)
    qipaoNode: cc.Node = null;

    @property(cc.ProgressBar)
    qian_ProgressBar: cc.ProgressBar = null;
    @property(cc.ProgressBar)
    level_ProgressBar: cc.ProgressBar = null;


    isUpdate = false
    dtTime = 0
    dtTimeLevel = 0
    isGuide = false
    isUpdateLevel = false
    isGuideTanWei = false
    isGuideShiPu = false

    clickNum = 0

    dialogIndex: number = 0;
    duihuakuang1: cc.Node;
    duihuakuang2: cc.Node;
    selectIndex: number = 0;

    guideArr = []
    chatConfig = [
        { effectUrl: 'DH/MainHall/sound/哥哥,建议你试下升级哦!', delayTime: 2.21, str: '哥哥,建议你试下升级哦', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/等级越高,每次点击赚钱越多哦', delayTime: 2.83, str: '等级越高,每次点击赚钱越多哦', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/接下来我们试下升级后的点击收益吧', delayTime: 2.68, str: '接下来我们试下升级后的点击收益吧', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/汉升哥哥,人太多忙不过来了,我们招个助理吧', delayTime: 4.35, str: '汉升哥哥,人太多忙不过来了,我们招个助理吧', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/升级可以获得永久点击收益提升哦', delayTime: 3, str: '升级可以获得永久点击收益提升哦', posi: 'qipao3' },
        { effectUrl: 'DH/MainHall/sound/(我记得前世柳家对付别的竞争对手喜欢从原材料下手。)', delayTime: 3.98, str: '(我记得前世柳家对付别的竞争对手喜欢从原材料下手。)', posi: '-1' },
        { effectUrl: 'DH/MainHall/sound/(得先去收购一个农贸市场,不然到时候就被柳家父子打脸了)', delayTime: 4.74, str: '(得先去收购一个农贸市场,不然到时候就被柳家父子打脸了)', posi: '-1' },
        { effectUrl: 'DH/MainHall/sound/(柳家豪,竟然如此没有底线,那就别怪我不客气了。)', delayTime: 4.66, str: '(柳家豪,竟然如此没有底线,那就别怪我不客气了。)', posi: '-1' },
        { effectUrl: 'DH/MainHall/sound/(等我达到一级面点师,再来收拾你们。)', delayTime: 2.57, str: '(等我达到一级面点师,再来收拾你们。)', posi: '-1' },
        { effectUrl: 'DH/MainHall/sound/哥哥,点击这个按钮可以抽取点击收益和秒赚收益的翻倍哦!', delayTime: 4.95, str: '哥哥,点击这个按钮可以抽取点击收益和秒赚收益的翻倍哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,解锁面点可以将秒赚收益翻倍哦!', delayTime: 3.59, str: '哥哥,解锁面点可以将秒赚收益翻倍哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,解锁摊位物品可以增加点击收益翻倍哦!', delayTime: 3.91, str: '哥哥,解锁摊位物品可以增加点击收益翻倍哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,点击这个掉落物品,打开可以获得高品质面点和摊位物品,还有神秘七彩龙珠物品哦!', delayTime: 7.2, str: '哥哥,点击这个掉落物品,打开可以获得高品质面点和摊位物品,还有神秘七彩龙珠物品哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,在这里达到成就可以用领取丰厚奖励哦!', delayTime: 3.67, str: '哥哥,在这里达到成就可以用领取丰厚奖励哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,点击这个按钮可以升级点击收益翻倍哦!', delayTime: 3.65, str: '哥哥,点击这个按钮可以升级点击收益翻倍哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,点击这个可以进行自动点击哦,这样你就可以去干点别的啦!', delayTime: 5.74, str: '哥哥,点击这个可以进行自动点击哦,这样你就可以去干点别的啦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,购买资产可以增加点击收益和秒赚收益倍数哦!', delayTime: 4.69, str: '哥哥,购买资产可以增加点击收益和秒赚收益倍数哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,缺钱可以投资房产进行买卖,赚取差价哦!', delayTime: 4.35, str: '哥哥,缺钱可以投资房产进行买卖,赚取差价哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,努力提升等级获取高级称号可以提升你的排名哦,排名越高领取的奖励越丰厚哦!', delayTime: 8.56, str: '哥哥,努力提升等级获取高级称号可以提升你的排名哦,排名越高领取的奖励越丰厚哦!', posi: 'qipao2' },
        { effectUrl: 'DH/MainHall/sound/哥哥,点击这里进入里面有多种小游戏可以赚钱哦!', delayTime: 4.56, str: '哥哥,点击这里进入里面有多种小游戏可以赚钱哦!', posi: 'qipao2' },
    ]
    guideZiChan: any;
    curStayTime: number;

    start() {
        cc.audioEngine.stopMusic()
        EventMgr.emitEvent_custom(ryw_Event.changeScene);
        EventMgr.onEvent_custom(ryw_Event.changeScene, () => {
            console.log('changeScene++=MainHall')
            this.node.removeFromParent()
            this.node.destroy()
        }, this)
        this.curStayTime = Date.now()


        // PrefabManage.loadPrefabByType(GameType.ChaoFanWang, this.node.getChildByName('prefabNode'), (node) => {
        // })
        // if (User.getRoomGoodStatus() == 0) {
        //     PrefabManage.loadPrefabByType(GameType.chatLongGe)
        //     this.hideSomeBtn(true)
        // }

        this.refreshView()
        EventMgr.onEvent_custom(ryw_Event.MainHallRefreshView, () => {
            this.refreshView()
        }, this)

        let caishen = this.node.getChildByName('财神').getComponent(cc.Animation)
        caishen.on(cc.Animation.EventType.FINISHED, () => {
            this.isUpdate = false
            console.log('财神动画结束')
        }, this);


        EventMgr.onEvent_custom(ryw_Event.ChaiShenEvent, (isUse) => {
            let caishen = this.node.getChildByName('财神')
            if (isUse) {
                this.isUpdate = false
                caishen.active = false
            } else {
                caishen.getComponent(cc.Animation).resume()
            }

        }, this)

        this.refreshHead()
        EventMgr.onEvent_custom(ryw_Event.setHeadImg, () => {
            this.refreshHead()
        }, this)


        this.refreshChengHao()
        EventMgr.onEvent_custom(ryw_Event.levelUpChange, () => {
            this.refreshChengHao()
            this.refreshView()
            this.updateTaskJinDu()
        }, this)


        EventMgr.onEvent_custom(ryw_Event.mishuLock, () => {
            this.refreshView()

        }, this)
        EventMgr.onEvent_custom(ryw_Event.mishuLevelUp, () => {
            this.refreshView()
        }, this)

        EventMgr.onEvent_custom(ryw_Event.unlockItem, () => {
            this.refreshView()
        }, this)
        EventMgr.onEvent_custom(ryw_Event.levelUpitem, () => {
            this.refreshView()
        }, this)
        EventMgr.onEvent_custom(ryw_Event.MultipleIncomeEvent, () => {
            this.refreshView()
        }, this)
        EventMgr.onEvent_custom(ryw_Event.MishuPeixun, () => {
            this.refreshView()
        }, this)
        if (User.getDeskReward()) {
            this.node.getChildByName("UINode").getChildByName("添加桌面").active = false
        }


        EventMgr.onEvent_custom(ryw_Event.updateMoney, () => {
            // this.checkIsMainTask502Finish()
            // this.checkIsMainTask101Finish()
            this.checkTaskFinish()
            this.updateTaskJinDu()
        }, this)
        this.checkTaskFinish()
        // this.checkIsMainTask502Finish()
        // this.checkIsMainTask101Finish


        let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
        let mainId = mainTaskInfo.Id
        if (mainId == MainTaskIdEnum.MainTask_502) {

            this.isGuide = true
        }
        EventMgr.onEvent_custom(ryw_Event.NewGuideEvent, (index) => {
            this.guideNewStep(index)
        }, this)

        this.guideStep()
        this.loadPrefabs()


        EventMgr.onEvent_custom(ryw_Event.swallowToucheEvent, () => {
            let index = User.getFirstStepIndex()
            if (index == 6 || index == 7) {
                this.clickNum++
            }
            // console.log(Common5.CommonGuideIndex, 'Common5.CommonGuideIndex++++++++==')
            // if (Common5.CommonGuideIndex == 3) {
            //     let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('秘书')
            //     this.guideView([node], 150)
            // }
        }, this)
        EventMgr.onEvent_custom(ryw_Event.swallowToucheFinishEvent, () => {
            this.guideStep()
        }, this)

        this.guideTask()
        EventMgr.onEvent_custom(ryw_Event.GuideTask, () => {
            this.guideTask()
        }, this)
        this.guideShipu()
        EventMgr.onEvent_custom(ryw_Event.ExitBtnEvent, () => {
            this.guideShipu()
            if (User.getFirstStepIndex() == 11 && !Common5.isCeBianLanEnter) {
                PrefabManage.loadPrefabByType(GameType.CeBianLan)
                // let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('成就')
                // this.guideView([node], 100)
            }

            let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
            let mainId = mainTaskInfo.Id
            if (mainId == MainTaskIdEnum.MainTask_507) {
                let node = this.node.getChildByName('UINode').getChildByName('主线剧情')
                this.guideView([node], 150)
            }
        }, this)

        // this.checkTaskQiPao()
        this.updateMainTask()
        EventMgr.onEvent_custom(ryw_Event.updateMainTask, () => {
            this.updateMainTask()
        }, this)


        EventMgr.onEvent_custom(ryw_Event.JuQingGuide, () => {
            this.isGuide = true
            this.hideSomeBtn(false)
        }, this)


        EventMgr.onEvent_custom(ryw_Event.My_Guide, () => {
            this.My_Guide()
        }, this)
        this.My_Guide()

        this.schedule(() => {
            this.runGuideArr()
            //计时当前界面停留时间
            if (TaskManager.getCurUnLockMainTaskId() == MainTaskIdEnum.MainTask_511 && User.getStatistics("isJoinDH46") == 0 &&
                (Date.now() / 1000 - this.curStayTime / 1000 >= 1 * 60 || User.getMyLevel() >= 200)) {
                Common5.stopMusic()
                this.node.removeFromParent()
                this.node.destroy()
                PrefabManage.loadPrefabByType(GameType.DH_46)
            }
            // else if (TaskManager.getCurUnLockMainTaskId() == MainTaskIdEnum.MainTask_511 && Date.now() / 1000 - this.curStayTime / 1000 >= 6 * 60) {

            // } 
            else if (TaskManager.getCurUnLockMainTaskId() == MainTaskIdEnum.MainTask_511 && User.getStatistics("smallgameguide") == 0 &&
                !this.node.getChildByName('UINode').getChildByName('小游戏').active &&
                (Date.now() / 1000 - this.curStayTime / 1000 >= 3 * 60 || User.getMyLevel() >= 250)) {
                let node = this.node.getChildByName('UINode').getChildByName('小游戏')
                node.active = true
                this.guideView([node], 0, this.chatConfig[19], "小游戏引导")
            }
        }, 1)
        // let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('升级')
        // //等级
        // let lv = node.getChildByName('lv')
        // lv.getComponent(cc.Label).string = `Lv:${User.getMyLevel()}`
        // //升级的钱数
        // let money = node.getChildByName('str')
        // let levelUpSpned = LevelUpManager.levelUpSpned()
        // money.getComponent(cc.Label).string = `${Common5.getNumberChangeHanzi(levelUpSpned)}`
        // //点击收益
        // let dianji = node.getChildByName('点击收益').getChildByName('str')
        // dianji.getComponent(cc.Label).string = `点击收益:${Common5.getNumberChangeHanzi(LevelUpManager.getCurClickIncome())}`  + '/次'

        // PrefabManage.loadPrefabByType(GameType.GetDiaoLuo)

    }

    My_Guide() {
        let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
        let mainId = mainTaskInfo.Id
        let index = User.getFirstStepIndex()
        if (index == 1000) {
            this.scheduleOnce(() => {
                let zhuanpan = User.getZhuanPanFree()
                if (zhuanpan) {
                    Common5.ReportDY("inLevel", "任务" + TaskManager.getCurUnLockMainTaskId() + '-引导收益翻倍');
                    let node = this.node.getChildByName('UINode').getChildByName('多倍收益')
                    // this.showQiPao(this.chatConfig[9], "qipao_people", () => {
                    // })
                    this.guideView([node], 150, this.chatConfig[9], "多倍收益引导")
                }
            }, 5)
        } else if (index == 1001 && this.node.getChildByName('UINode').getChildByName('diaoLuoNode').children[0].active) {
            let node = this.node.getChildByName('UINode').getChildByName('diaoLuoNode').getChildByName('礼盒')
            // this.showQiPao(this.chatConfig[12], "qipao_people", () => {
            // })
            this.guideView([node], 150, this.chatConfig[12], "掉落引导")
        } else if (index == 1002) {
            let node = this.node.getChildByName('UINode').getChildByName('成就')
            // this.showQiPao(this.chatConfig[13], "qipao_people", () => {
            // })
            this.guideView([node], 0, this.chatConfig[13], "成就引导")
        } else if (index == 1003) {
            let chengjiu1 = cc.sys.localStorage.getItem("成就首次点击收益") ?? '0'
            let chengjiu2 = cc.sys.localStorage.getItem("成就首次自动点击") ?? '0'
            if (chengjiu1 == '1') {
                let node = this.node.getChildByName('UINode').getChildByName('点击收益')
                // this.showQiPao(this.chatConfig[14], "qipao_people", () => {
                // })
                this.guideView([node], 150, this.chatConfig[14], "成就首次点击收益引导")
            } else if (chengjiu2 == '1') {
                let node = this.node.getChildByName('UINode').getChildByName('自动点击')
                // this.showQiPao(this.chatConfig[15], "qipao_people", () => {
                // })
                this.guideView([node], 150, this.chatConfig[15], "成就首次自动点击引导")
            }
        } else if (index == 1101) {
            let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('资产')
            this.guideView([node], 100, this.chatConfig[16], "资产引导")
            // this.showQiPao(this.chatConfig[16], "qipao_people", () => {
            // })
        } else if (index == 1102) {
            let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('房产')
            this.guideView([node], 100, this.chatConfig[17], "房产引导")
            // this.showQiPao(this.chatConfig[17], "qipao_people", () => {
            // })
        } else if (index == 1103) {
            let node = this.node.getChildByName('UINode').getChildByName('排行榜')
            this.guideView([node], 100, this.chatConfig[18], "排行榜引导")
            // this.showQiPao(this.chatConfig[18], "qipao_people", () => {
            // })
        }
    }


    guideTask() {
        let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
        let mainId = mainTaskInfo.Id
        let index = User.getFirstStepIndex()
        if (mainId == MainTaskIdEnum.MainTask_506) {
            let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('对战')
            this.guideView([node], 0)
        } else if (mainId == MainTaskIdEnum.MainTask_507) {
            let node = this.node.getChildByName('UINode').getChildByName('主线剧情')
            this.guideView([node], 150)
        } else if (mainId == MainTaskIdEnum.MainTask_508) {
            let node = this.node.getChildByName('UINode').getChildByName('主线剧情')
            this.guideView([node], 150)
        } else if (mainId == MainTaskIdEnum.MainTask_509 && User.getFirstStepIndex() == 20) {
            // let node = this.node.getChildByName('UINode').getChildByName('点击收益')
            // this.guideView([node], 150)
            // node.getChildByName("黄色按钮视频").active = false
            // this.showQiPao(this.chatConfig[4], "qipao_guide", () => {
            // })
        } else if (mainId == MainTaskIdEnum.MainTask_509 && User.getFirstStepIndex() == 21) {
            let node = this.node.getChildByName('UINode').getChildByName('城市')
            this.guideView([node], 0)
        } else if (mainId == MainTaskIdEnum.MainTask_None) {
            let curstate = User.getCurTaskId()
            // if (curstate[0] == MainTaskIdEnum.MainTask_506 && curstate[1] == 1) {
            //     let node = this.node.getChildByName('UINode').getChildByName('主线剧情')
            //     this.guideView([node], 150)
            // }
        }
        // else if (mainId == MainTaskIdEnum.MainTask_503) {
        //     let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('对战')
        //     this.guideView([node], 100)
        // } else if (mainId == MainTaskIdEnum.MainTask_505 && User.getFirstStepIndex() == 4) {
        //     User.setFirstStepIndex(5)
        //     let node = this.node.getChildByName('UINode').getChildByName('城市')
        //     this.guideView([node], 100)
        // } else if (mainId == MainTaskIdEnum.MainTask_514 && User.getFirstStepIndex() == 6) {
        //     User.setFirstStepIndex(7)
        //     let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('秘书')
        //     this.guideView([node], 100)
        // } else if (mainId == MainTaskIdEnum.MainTask_516 && Common5.TaskGuide516) {
        //     let node = this.node.getChildByName('UINode').getChildByName('城市')
        //     this.guideView([node])
        // }
    }

    guideShipu() {
        // let guideIndexArray = User.getGuideIndexArray()
        // if (guideIndexArray[0] == 1 && guideIndexArray[1] == 0) {
        //     let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('食谱')
        //     this.guideView([node], 100)
        //     guideIndexArray[1] = 1
        //     User.setGuideIndexArray(guideIndexArray)
        // }

        // let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
        // let mainId = mainTaskInfo.Id
        // if (mainId == MainTaskIdEnum.MainTask_504) {
        //     let node = this.node.getChildByName('UINode').getChildByName('主线剧情')
        //     this.guideView([node])
        // }

        // let zhuanpan = User.getZhuanPanFree()
        // let dianjiFirstGuide = User.getDianjiFirstGuide()
        // if (zhuanpan == false && dianjiFirstGuide) {
        //     let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('升级')
        //     let shouzhiNode = node.getChildByName('手指箭头')
        //     shouzhiNode.active = true
        // } else if (zhuanpan == false && dianjiFirstGuide == false && Common5.mishuGuide) {
        //     let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('秘书')
        //     let shouzhiNode = node.getChildByName('手指箭头')
        //     shouzhiNode.active = true
        //     Common5.mishuGuide = false
        // }

        //气泡出现
        // this.checkQiPao()

    }

    checkQiPao() {
        //气泡检测
        let canvas = cc.find('Canvas')
        let prefabLayer = canvas.getChildByName("prefabLayer")
        let guideMishuQipao = User.getGuideMishuQipao()
        let level = User.getMyLevel()
        if (prefabLayer.childrenCount == 1) {
            if (level >= 10 && guideMishuQipao[0] == 0) {
                guideMishuQipao[0] = 1
                User.setGuideMishuQipao(guideMishuQipao)
                this.qipaoAnim('老板,尝试一下多个手指点击吧',)
            } else if (level >= 80 && guideMishuQipao[1] == 0) {
                let mishuLevel = MiShuManager.getMishuClickInCome(0)
                if (mishuLevel) {
                    guideMishuQipao[1] = 1
                    User.setGuideMishuQipao(guideMishuQipao)
                    this.qipaoAnim('老板,你要快速把我升到20级啊')
                } else {
                    guideMishuQipao[1] = 1
                    User.setGuideMishuQipao(guideMishuQipao)
                }

            }

        }
    }

    checkTaskQiPao() {
        let str = this.getTaskStr()
        if (str) {
            this.qipaoAnimForever(str)
        } else {
            this.qipaoNode.stopAllActions()
            this.qipaoNode.active = false
        }

    }

    getTaskStr() {
        let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
        let mainId = mainTaskInfo.Id
        let money = UserManager.getCurMoney()
        let CurClickIncome = LevelUpManager.getCurClickIncome()

        if (mainId == MainTaskIdEnum.MainTask_507) {

            let data = ChallengeManager.getCurChallengeConfigDateById(4)
            let attackNum = data.attackNum
            if (CurClickIncome >= attackNum) {
                return '老板,洛北辰太嚣张了,快去干他吧'
            } else {
                return '洛北辰的攻击力只有2万/点击,轻松吊打他'
            }
        } else if (mainId == MainTaskWZEnum.MainTaskWZ_101) {

            let attackNum = 500000000
            if (money >= attackNum) {
                return '夕颜姐姐太苦了,快去接她回来吧'
            } else {
                return '只要努力升级,赚够3亿还是很轻松的'
            }
        } else if (mainId == MainTaskIdEnum.MainTask_510) {

            let data = ChallengeManager.getCurChallengeConfigDateById(6)
            let attackNum = data.attackNum
            if (CurClickIncome >= attackNum) {
                return '你现在足以对付暗月长老了,快去救夕颜吧'
            } else {
                return '暗月长老的攻击力只有300万/点击,轻松吊打他'
            }
        } if (mainId == MainTaskIdEnum.MainTask_519) {

            let data = ChallengeManager.getCurChallengeConfigDateById(9)
            let attackNum = data.attackNum
            if (CurClickIncome >= attackNum) {
                return '你现在足以对付江啸天了,探寻真相吧'
            } else {
                return '江啸天的攻击力只有100亿/点击,轻松吊打他'
            }
        } else {
            return null
        }



    }
    qipaoAnimForever(str) {
        this.qipaoNode.active = true
        this.qipaoNode.scale = 0.1
        let lab = this.qipaoNode.getChildByName('lab').getComponent(cc.Label)
        lab.string = str
        this.qipaoNode.stopAllActions()
        cc.tween(this.qipaoNode)
            .to(0.2, { scale: 1, opacity: 255 })
            .delay(5.0)
            .call(() => {
                this.qipaoNode.opacity = 0
                this.qipaoNode.scale = 0.1
                let str = this.getTaskStr()
                lab.string = str
            })
            .delay(20)
            .union()
            .repeatForever()
            .start()
    }

    qipaoAnim(str) {
        this.qipaoNode.active = true
        this.qipaoNode.scale = 0.1
        this.qipaoNode.stopAllActions()
        let lab = this.qipaoNode.getChildByName('lab').getComponent(cc.Label)
        lab.string = str
        cc.tween(this.qipaoNode)
            .to(0.2, { scale: 1 })
            .delay(5.0)
            .call(() => {
                this.qipaoNode.active = false
            })
            .start()
    }

    guideNewStep(index) {
        if (index == 1) {
            let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('升级')
            this.guideView([node])
        }
    }

    loadPrefabs() {
        this.scheduleOnce(() => {
            let curSignDay = -1
            let signList = User.getSignList()

            for (let i = 0; i < 7; i++) {
                if (signList[i] == 0) {
                    curSignDay = i
                    break
                }
            }

            let index = User.getFirstStepIndex()
            if (index == 1) {
                let array = [GameType.PeopleLevelUp, GameType.MishuGame, GameType.MultipleIncome]
                PrefabManage.preloadPrefabArray(array)
            } else {
                let array = [GameType.PeopleLevelUp, GameType.MishuGame, GameType.ChallengeChoose, GameType.MultipleIncome, GameType.TanWei, GameType.Shipu, GameType.FangChanGame, GameType.ZiChan, GameType.ChatList, GameType.CityPrefab]
                if (curSignDay == -1) {
                    array = [GameType.PeopleLevelUp, GameType.MishuGame, GameType.ChallengeChoose, GameType.MultipleIncome, GameType.TanWei, GameType.Shipu, GameType.FangChanGame, GameType.ZiChan, GameType.ChatList, GameType.CityPrefab]
                }

                PrefabManage.preloadPrefabArray(array)
            }

        }, 0.5)
    }

    checkTaskFinish() {
        let mainId = TaskManager.getCurUnLockMainTaskId()
        let config = TaskManager.getTaskConfigById(mainId)
        let money = UserManager.getCurMoney()
        let ziChanData = User.getZiChanData()
        let getCurTaskId = User.getCurTaskId()
        //任务505加打点
        // if (mainId == MainTaskIdEnum.MainTask_505) {
        //     let moneys = [1000000, 2000000, 3000000, 4000000, 5000000]
        //     for (let i = moneys.length - 1; i >= 0; i--) {
        //         if (money >= moneys[i]) {
        //             Common5.ReportDY("inLevel", "任务" + TaskManager.getCurUnLockMainTaskId() + `-金钱到达${moneys[i]}万`);
        //             break
        //         }
        //     }
        // } else if (mainId == MainTaskIdEnum.MainTask_509) {
        //     let moneys = [10000000, 20000000, 30000000, 40000000, 50000000]
        //     for (let i = moneys.length - 1; i >= 0; i--) {
        //         if (money >= moneys[i]) {
        //             Common5.ReportDY("inLevel", "任务" + TaskManager.getCurUnLockMainTaskId() + `-金钱到达${moneys[i]}万`);
        //             break
        //         }
        //     }
        // }

        if (mainId == MainTaskIdEnum.MainTask_503 && money >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_503)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_504)
            let node = this.node.getChildByName('UINode').getChildByName('主线剧情')
            this.guideView([node], 150)
        } else if (mainId == MainTaskIdEnum.MainTask_505 && money >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_505)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_506)
            let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('对战')
            this.guideView([node])
        } else if (mainId == MainTaskIdEnum.MainTask_509 && money >= config.taskNum && User.getFirstStepIndex() < 20) {
            User.setFirstStepIndex(21)
            this.guideTask()
        } else if (mainId == MainTaskIdEnum.MainTask_511 && User.getMyLevel() >= config.levelNum && User.getMoney() >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_511)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_512)
            let node = this.node.getChildByName('UINode').getChildByName('城市')
            this.guideView([node], 100)
        } else if (mainId == MainTaskIdEnum.MainTask_514_2 && ziChanData.unLockNum[0] != 1 && User.getMyLevel() >= config.levelNum && User.getMoney() >= config.taskNum) {
            if (!cc.sys.localStorage.getItem("资产引导") && !this.guideZiChan) {
                User.setFirstStepIndex(1101)
                this.My_Guide()
                this.guideZiChan = true
            }
        } else if (mainId == MainTaskIdEnum.MainTask_518_2 && money >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_518_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_519)
        } else if (getCurTaskId[0] == MainTaskIdEnum.MainTask_522 && getCurTaskId[1] == 1) {
            Common5.stopMusic()
            this.node.removeFromParent()
            this.node.destroy()
            PrefabManage.loadPrefabByType(GameType.DH_44)
        } else if (mainId == MainTaskIdEnum.MainTask_523 && User.getMoney() >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_523)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_524)
        } else if (getCurTaskId[0] == MainTaskIdEnum.MainTask_535 && getCurTaskId[1] == 1) {
            Common5.stopMusic()
            this.node.removeFromParent()
            this.node.destroy()
            PrefabManage.loadPrefabByType(GameType.DH_45)
        } else if (mainId == MainTaskIdEnum.MainTask_536 && User.getMyLevel() >= config.levelNum && money >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_536)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_537)
        } else if (mainId == MainTaskIdEnum.MainTask_527_2 && User.getMyLevel() >= config.levelNum && money >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_527_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_528)
        } else if (mainId == MainTaskIdEnum.MainTask_539 && money >= config.taskNum && User.getMyLevel() >= config.levelNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_539)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_540)
        } else if (mainId == MainTaskIdEnum.MainTask_531_2 && User.getMyLevel() >= config.levelNum && money >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_531_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_532)
        } else if (mainId == MainTaskIdEnum.MainTask_541_2 && User.getMyLevel() >= config.levelNum && money >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_541_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_542)
        } else if (mainId == MainTaskIdEnum.MainTask_544_2 && money >= config.taskNum) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_544_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_545)
        } else if (mainId == MainTaskIdEnum.MainTask_547_2 && User.getMyLevel() >= config.levelNum && money >= config.taskNum) {
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_547_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_548)
        } else if (mainId == MainTaskIdEnum.MainTask_514_2 && ziChanData.unLockNum[0] >= 1 && FangChanManager.getRoomState(3) == 1) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_514_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_515)
        } else if (mainId == MainTaskIdEnum.MainTask_532 && ziChanData.unLockNum[1] >= 1 && FangChanManager.getRoomState(6) == 1) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_532)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_533)
        } else if (mainId == MainTaskIdEnum.MainTask_542 && ziChanData.unLockNum[2] >= 1 && FangChanManager.getRoomState(9) == 1) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_542)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_543_1)
        } else if (mainId == MainTaskIdEnum.MainTask_550_2 && ziChanData.unLockNum[3] >= 1 && FangChanManager.getRoomState(12) == 1) {
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_550_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_551_1)
        }


        let myMoney = UserManager.getCurMoney()
        let levelUpSpned = LevelUpManager.levelUpSpned()
        let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('升级')
        if (myMoney - levelUpSpned >= 0) {
            node.getChildByName("黄色按钮视频").active = false
            node.getChildByName("升级").getComponent(cc.Label).string = '升级'
        } else {
            node.getChildByName("黄色按钮视频").active = true
            let level = 5
            if (User.getMyLevel() < 600) {
                level = 5
            } else if (User.getMyLevel() >= 600 && User.getMyLevel() < 900) {
                level = 3
            } else {
                level = 2
            }
            node.getChildByName("升级").getComponent(cc.Label).string = `升级+${level}`
        }

        if (TanWeiManager.getCurShipuCanUnLock(0) == 'all' && TanWeiManager.getLockById(0) && !this.isGuideTanWei &&
            User.getMoney() >= TanWeiManager.getShipuConfigDate(0).unLockMoney) {
            let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('摊位')
            this.guideView([node], 100, this.chatConfig[11])
            this.isGuideTanWei = true
            // this.showQiPao(this.chatConfig[11], "qipao_people", () => {

            // })
        } else if (ShipuManager.getCurShipuCanUnLock(0) == 'all' && ShipuManager.getLockById(0) && !this.isGuideShiPu &&
            User.getMoney() >= ShipuManager.getShipuConfigDate(0).unLockMoney) {
            let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('食谱')
            this.guideView([node], 100, this.chatConfig[10])
            this.isGuideShiPu = true
            // this.showQiPao(this.chatConfig[10], "qipao_people", () => {

            // })
        }
        // else if (User.getChuShiXieHuiLevel()[0] == 1 && !(cc.sys.localStorage.getItem("排行榜引导") ?? 0)) {
        //     let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('食谱')
        //     this.guideView([node], 100, this.chatConfig[10])
        //     this.isGuideShiPu = true
        //     // this.showQiPao(this.chatConfig[10], "qipao_people", () => {

        //     // })
        // }
    }
    // //检测主任务502完成情况
    // checkIsMainTask502Finish() {
    //     if (!this.isGuide) {
    //         return
    //     }
    //     let money = UserManager.getCurMoney()
    //     let config = TaskManager.getTaskConfigById(MainTaskIdEnum.MainTask_502)
    //     let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
    //     let mainId = mainTaskInfo.Id
    //     if (mainId == MainTaskIdEnum.MainTask_502 && this.isGuide) {

    //         if (money - config.taskNum >= 0) {
    //             this.isGuide = false
    //             //引导回家扣钱 进行对话

    //             User.setRoomGoodStatus(6)
    //             Common5.ReportDY("inLevel", '关卡000016-开始剧情');
    //             JuQingManager.unLockNewJuQing('DH_4')
    //             TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_502)
    //             TaskManager.setCurTask(MainTaskIdEnum.MainTask_502_2)

    //             let prefabLayer = cc.director.getScene().getChildByName("Canvas").getChildByName('prefabLayer')
    //             if (prefabLayer.childrenCount == 1) {
    //                 let node = this.node.getChildByName('UINode').getChildByName('主线剧情')
    //                 this.guideView([node], 150)
    //             } else {
    //                 for (let i = 0; i < prefabLayer.childrenCount; i++) {
    //                     if (prefabLayer.children[i].name == 'MainHall') {

    //                     } else {
    //                         prefabLayer.children[i].removeFromParent()
    //                         //prefabLayer.children[i].destroy()
    //                     }
    //                 }
    //                 let node = this.node.getChildByName('UINode').getChildByName('主线剧情')
    //                 this.guideView([node])
    //             }


    //         }
    //     }
    // }

    // checkIsMainTask101Finish() {

    //     let money = UserManager.getCurMoney()
    //     let config = TaskManager.getTaskConfigById(MainTaskWZEnum.MainTaskWZ_101)
    //     let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
    //     let mainId = mainTaskInfo.Id
    //     if (mainId == MainTaskWZEnum.MainTaskWZ_101) {

    //         if (money - config.taskNum >= 0) {

    //             TaskManager.finishCurMainTask(MainTaskWZEnum.MainTaskWZ_101)
    //             TaskManager.setCurTask(MainTaskIdEnum.MainTask_509)
    //             User.setRoomGoodStatus(13)


    //         }
    //     }
    // }


    guideStep() {
        let index = User.getFirstStepIndex()
        if (index == 6 && this.clickNum < 4) {
            if (this.clickNum == 0) {
                PrefabManage.showTextTips("点击摊位开始做拉面赚钱")
            }
            this.guideView([this.node, this.node, this.node, this.node, this.node])
            // let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('升级')
            // this.guideView([node], 100)
            // JuQingManager.unLockNewJuQing('DH_88')
            // User.setFirstStepIndex(3)

            // Common5.CommonGuideIndex = 100
            // EventMgr.emitEvent_custom(ryw_Event.NewGuideEvent, 100)
        } else if (index == 6 && this.clickNum >= 4) {
            this.showQiPao(this.chatConfig[0], "qipao_people", () => {
                this.scheduleOnce(() => {
                    User.setFirstStepIndex(7)
                    this.clickNum = 0
                    this.guideStep()
                }, 0)
            })
        } else if (index == 7 && this.clickNum < 1) {
            if (this.clickNum == 0) {
                // this.showQiPao(this.chatConfig[1], "qipao_people", () => {
                //     this.scheduleOnce(() => {
                Common5.ReportDY("inLevel", "任务" + TaskManager.getCurUnLockMainTaskId() + '-引导升级');
                let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('升级')
                this.guideView([node, node], -1, this.chatConfig[1])
                //     }, 5)
                // })
            }
        } else if (index == 7 && this.clickNum >= 1) {
            this.scheduleOnce(() => {
                User.setFirstStepIndex(8)
                this.clickNum = 0
                this.guideStep()
            }, 3)
        } else if (index == 8) {
            User.setFirstStepIndex(8.5)
            this.clickNum = 0
            this.showQiPao(this.chatConfig[2], "qipao_people", () => {
                this.guideView([this.node, this.node, this.node, this.node, this.node])
                // let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('秘书')
                // this.guideView([node], 100)
            })
        } else if (index == 8.5) {
            User.setFirstStepIndex(9)
            this.clickNum = 0
            this.scheduleOnce(() => {
                this.guideStep()
            }, 5)
        } else if (index == 9) {
            User.setFirstStepIndex(10)
            this.clickNum = 0
            this.showQiPao(this.chatConfig[3], "qipao_people", () => {
                this.scheduleOnce(() => {
                    let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('秘书')
                    this.guideView([node], 100)
                }, 0)
            })
        } else {
        }
    }

    runGuideArr() {
        if (this.guideArr.length > 0) {
            let prefabLayer = cc.director.getScene().getChildByName("Canvas").getChildByName('prefabLayer')
            console.log("prefabLayer.children=", prefabLayer.children)
            if (this.guideArr.length == 1 && prefabLayer.childrenCount == 1 && prefabLayer.children[0].name == 'MainHall' && this.node.getChildByName("蒙版父节点").childrenCount == 0) {
                let _guide = this.guideArr.shift()
                if (_guide) {
                    this.guideView(_guide.nodeArray, _guide.opacity, _guide.qiPao, _guide.name, true)
                }
            } else {
                this.scheduleOnce(() => {
                    let prefabLayer = cc.director.getScene().getChildByName("Canvas").getChildByName('prefabLayer')
                    console.log("prefabLayer.children=", prefabLayer.children)
                    if (prefabLayer.childrenCount == 1 && prefabLayer.children[0].name == 'MainHall' && this.node.getChildByName("蒙版父节点").childrenCount == 0) {
                        let _guide = this.guideArr.shift()
                        if (_guide) {
                            this.guideView(_guide.nodeArray, _guide.opacity, _guide.qiPao, _guide.name, true)
                        }
                    }
                }, 3)
            }

        }
    }

    guideView(nodeArray, opacity = -1, qiPao?, name?, isRun?) {
        if (!isRun) {
            if (nodeArray && nodeArray.length > 0 && this.guideArr && this.guideArr.length > 0) {
                for (let i = 0; i < this.guideArr.length; i++) {
                    if (name && this.guideArr[i].name && name == this.guideArr[i].name) {
                        console.log("已有相同的引导不再添加")
                        return
                    }
                }
            }
            this.guideArr.push({ nodeArray: nodeArray, opacity: opacity, qiPao: qiPao, name: name })
            // this.runGuideArr()
        } else {
            PrefabManage.loadPrefabByType(GameType.GuideMskNode, this.node.getChildByName("蒙版父节点"), (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)
                }
            })
            if (qiPao) {
                this.showQiPao(qiPao, "qipao_people", () => {
                })
            }
        }
    }


    refreshChengHao() {
        let chenghao = LevelUpManager.getChengHao()
        //this.chenghaoPic.string = chenghao
        // Common5.addUrlSprite_custom('jingjie/' + chenghao, this.chenghaoPic)
        this.chenghao.string = chenghao
        let levelLab = User.getMyLevel()
        this.levelLab.string = levelLab + ''

        let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('升级')
        //等级
        let lv = node.getChildByName('lv')
        lv.getComponent(cc.Label).string = `Lv:${User.getMyLevel()}`

        //升级的钱数
        let money = node.getChildByName('str')
        let levelUpSpned = LevelUpManager.levelUpSpned()
        money.getComponent(cc.Label).string = `${Common5.getNumberChangeHanzi(levelUpSpned)}`

        // let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
        // let mainId = mainTaskInfo.Id
        // let config = TaskManager.getTaskConfigById(mainId)
        // if (mainId == MainTaskIdEnum.MainTask_511 && User.getMyLevel() >= config.levelNum && User.getMoney() >= config.taskNum) {
        //     TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_511)
        //     TaskManager.setCurTask(MainTaskIdEnum.MainTask_512)
        //     let node = this.node.getChildByName('UINode').getChildByName('城市')
        //     this.guideView([node], 100)
        // }
    }

    refreshHead() {
        let headSpr = this.node.getChildByName("UINode").getChildByName("head").getChildByName("头像").getComponent(cc.Sprite)
        Common5.addUrlSprite_custom("head/" + User.getHeadImg(), headSpr);

    }

    refreshView() {
        //189465465132184884545
        //let shouyi = LevelUpManager.getCurClickIncome()

        let str1 = LevelUpManager.getCurClickIncome() //人物点击收益(按等级算的) * 属性秘书加成属性摊位加成 * 出摊界面的点击收益按钮倍数 * 出摊界面的收益翻倍
        let allshouyi1 = MiShuManager.getAllIncomeMishu()//秘书秒赚总收益(包含出摊界面的收益翻倍)

        // let allshouyi2 = MiShuManager.getAllIncomeDuiyou()//队友秒赚总收益(包含出摊界面的收益翻倍)
        // let allNum = allshouyi1 + allshouyi2
        let allNum = allshouyi1

        let beishuSP = ShipuManager.getAllShipuInCome()//面点界面的物品秒赚加成
        let beishuTW = TanWeiManager.getAllShipuInCome() //摊位界面的物品点击加成

        let chenghaoInCome = LevelUpManager.getAllChengHaoinCome() //称号倍数

        let zichan = ZiChanManager.getZiChanBeiShu()

        // let mzNum = Math.floor(allNum * beishuSP * beishuTW)
        let clickNum = Math.floor(str1) //点击收益
        let mzNum = Math.floor(allNum * beishuSP * chenghaoInCome * zichan) //秒赚收益

        this.clickMoneyLab.string = '' + Common5.getNumberChangeHanzi(clickNum) + '/次'
        this.secondMoneyLab.string = '' + Common5.getNumberChangeHanzi(mzNum) + '/秒'

        //点击收益
        let node = this.node.getChildByName('UINode').getChildByName('bottom').getChildByName('升级')
        let dianji = node.getChildByName('点击收益').getChildByName('str')
        dianji.getComponent(cc.Label).string = `点击收益:${Common5.getNumberChangeHanzi(clickNum)}` + '/次'

        //解锁
    }
    // 
    update(dt) {
        if (this.isUpdate) {

        } else {
            this.dtTime += dt
            if (this.dtTime >= 25) {
                this.isUpdate = true
                this.playCSAnim()
                this.dtTime = 0
            }
        }


        if (this.isUpdateLevel) {

        } else {
            this.dtTimeLevel += dt
            if (this.dtTimeLevel >= 90) {
                this.isUpdateLevel = true
                // this.playLevelBtnAnim()
                this.dtTimeLevel = 0
            }
        }

    }

    playLevelBtnAnim() {
        let index = User.getFirstStepIndex()
        if (index <= 3) {
            this.isUpdateLevel = false
            return
        }
        let posiNode = this.node.getChildByName('等级posi')
        let levelUp9 = this.node.getChildByName('等级加9')
        let lab = levelUp9.getChildByName('lab').getComponent(cc.Label)
        let endPosi = levelUp9.getPosition()
        let strPosi = posiNode.getPosition()

        let qipaoAddLevelNum = LevelUpManager.getQipaoAddLevelNum()
        lab.string = '等级+' + qipaoAddLevelNum

        levelUp9.setPosition(strPosi)
        levelUp9.scale = 0.3
        levelUp9.active = true
        levelUp9.stopAllActions()
        levelUp9.getComponent(cc.Button).interactable = false

        cc.tween(levelUp9)
            .to(1.0, { x: endPosi.x, y: endPosi.y, scale: 1 }, { easing: 'backOut' })
            .call(() => {
                levelUp9.getComponent(cc.Button).interactable = true

            })
            .delay(15)
            .call(() => {
                levelUp9.active = false
                this.isUpdateLevel = false
            })
            .start()

        cc.tween(levelUp9)
            .repeatForever(
                cc.tween()
                    .to(0.6, { scale: 1.05 })
                    .to(0.6 * 1.5, { scale: 1 })
            )
            .start()


    }



    playCSAnim() {
        let index = User.getFirstStepIndex()
        if (index <= 3) {
            this.isUpdate = false
            return
        }

        let caishen = this.node.getChildByName('财神')
        caishen.active = true
        Common5.playRemoteSpine(caishen, 'Spine/chaishen', '财神', '财神')
        caishen.getComponent(cc.Animation).play('shishenAnim')


    }

    onAnimationFinished() {

    }

    chaishenClickEvent() {
        PrefabManage.loadPrefabByType(GameType.ShiShenSC)
        let caishen = this.node.getChildByName('财神')
        caishen.getComponent(cc.Animation).pause()
    }


    hideSomeBtn(isHide) {
        let uiNode = this.node.getChildByName("UINode")
        if (isHide == true) {

            for (let i = 0; i < uiNode.childrenCount; i++) {
                let node = uiNode.children[i]
                if (i == 0 || i == 1 || i == 2) {

                } else {
                    node.active = !isHide
                }
            }
        } else {

            for (let i = 0; i < uiNode.childrenCount; i++) {
                let node = uiNode.children[i]
                if (i == 0 || i == 1 || i == 2) {

                } else {
                    node.active = !isHide
                }
            }

            let bottom = uiNode.getChildByName('bottom')

            let renwu = uiNode.getChildByName('任务')
            let fuli = uiNode.getChildByName('领取福利')
            let qiandao = uiNode.getChildByName('签到')
            let paihangbang = uiNode.getChildByName('排行榜')
            let shouyi = uiNode.getChildByName('点击收益')
            let duobei = uiNode.getChildByName('多倍收益')

            let city = uiNode.getChildByName('城市')
            let zaixian = uiNode.getChildByName('在线奖励')
            let zidong = uiNode.getChildByName('自动点击')
            let shishen = uiNode.getChildByName('食神赐福')

            bottom.opacity = 0
            // let arrayNode1 = [renwu, fuli, qiandao, paihangbang, shouyi, duobei]
            // let arrayNode2 = [city, zaixian, zidong, shishen]
            let arrayNode1 = [renwu, fuli, paihangbang, shouyi, duobei]
            let arrayNode2 = [city, zidong, shishen]


            this.btnMoveAnim(bottom, 'down')
            arrayNode1.forEach(element => {
                element.opacity = 0
                this.btnMoveAnim(element, 'left')
            });
            arrayNode2.forEach(element => {
                element.opacity = 0
                this.btnMoveAnim(element, 'right')
            });

        }

    }


    btnMoveAnim(node, type) {

        this.scheduleOnce(() => {
            let nodePosix = node.getPosition().x
            let nodePosiy = node.getPosition().y
            if (type == 'down') {
                node.setPosition(cc.v2(nodePosix, nodePosiy - 200))

            } else if (type == 'left') {
                node.setPosition(cc.v2(nodePosix - 200, nodePosiy))

            } if (type == 'right') {
                node.setPosition(cc.v2(nodePosix + 200, nodePosiy))

            }

            node.opacity = 255
            node.active = true
            cc.tween(node)
                .to(0.5, { x: nodePosix, y: nodePosiy }, { easing: 'elasticOut' })
                .start()


        }, 0.1)
    }


    levelUpBtnClick(event) {
        let tab = {
            onClose: (finish) => {
                if (finish) {
                    User.setShowAdNum(User.getShowAdNum() + 1)
                    Common5.ReportDY("inLevel", `任务${TaskManager.getCurUnLockMainTaskId()}-AD-主界面升级`)
                    // Common5.ReportDY("inLevel", "主界面升级-AD-升级加9");
                    let qipaoAddLevelNum = LevelUpManager.getQipaoAddLevelNum()

                    LevelUpManager.peopleLevelUp(qipaoAddLevelNum)
                    event.target.active = false
                    event.target.stopAllActions()
                    this.isUpdateLevel = false

                } else {
                    event.target.active = false
                    event.target.stopAllActions()
                    this.isUpdateLevel = false
                    Common5.showTips_custom("广告未观看完");
                }

            }, onFailed: () => {

            }
        }
        AppPlatform.playVideo_custom(tab)
    }

    // 展示气泡
    showQiPao(curLog, qipaoname, func?, aniFunc?) {
        //cc.audioEngine.stopAllEffects();
        if (curLog != null && curLog != undefined && typeof (curLog) == "number") {
            curLog = this.chatConfig[curLog]
        }
        // if (!curLog) {
        //     return
        // }

        if (curLog.effectUrl && curLog.effectUrl.length > 0) {
            Common5.playRemoteAudioEffect(curLog.effectUrl);
            // Common5.playEffectCustom("GameRes", curLog.effectUrl);
        }

        let string_ = curLog.str
        let qiPaoPos_ = curLog.posi ?? curLog.qiPaoPos
        let delayTime_ = curLog.delayTime ?? curLog.delay

        if (aniFunc) {
            aniFunc()
        }

        if (qiPaoPos_ != '-1') {
            let node = this.node.getChildByName(qipaoname);
            let qiPao = node.getChildByName(qiPaoPos_);
            qiPao.stopAllActions()
            this.showDialogStr(string_, qiPao.getChildByName("str"))
            // qiPao.getChildByName("str").getComponent(cc.Label).string = string_
            qiPao.active = true
            // let scale = qiPao.scale
            qiPao.scale = 0
            cc.tween(qiPao)
                .to(0.2, { scale: 1 / this.node.scale })
                .delay(delayTime_)
                .call(() => {
                    qiPao.active = false;
                })
                .start();
        } else {
            let chatLog = this.node.getChildByName('chatLog')
            chatLog.active = true
            if (curLog.endStr) {
                chatLog.getChildByName("str").getComponent(cc.Label).string = curLog.endStr
            } else {
                if (this.selectIndex == 1) {
                    chatLog.getChildByName("str").getComponent(cc.Label).string = curLog.str1
                } else {
                    chatLog.getChildByName("str").getComponent(cc.Label).string = string_
                }
            }
            //this.showDialogStr(string_, chatLog.getChildByName("str"))
            chatLog.stopAllActions()
            cc.tween(chatLog)
                .delay(delayTime_)
                .call(() => {
                    chatLog.active = false;
                })
                .start();
        }

        this.scheduleOnce(() => {
            func && func();
        }, delayTime_ + 0.2);
    }

    // 逐字显示
    showDialogStr(str, dialogStr, finishFunc?) {
        let curStr = ""
        let curIndex = 0
        let callFunc = () => {
            curStr += str[curIndex++]
            dialogStr.getComponent(cc.Label).string = curStr
            if (curIndex >= str.length) {
                finishFunc && finishFunc()
            }
        }
        this.schedule(callFunc, 0.05, str.length - 1);
    }

    // 展示点击说话
    showClickDialog(curLog, func?, aniFunc?) {
        let text = curLog.str;
        if (text.length > 7) {
            text = curLog.str.slice(0, 6) + '...';
        }
        let dialog = this.node.getChildByName('对话框');
        dialog.getChildByName('lab').getComponent(cc.Label).string = text;
        dialog.active = true;
        this["_clickDialog"] = curLog;
        this["_clickDialogCallback"] = func;
        this["_clickDialogAniCallback"] = aniFunc;

        this.duihuakuang1 = dialog

        if (curLog.str1) {
            let text = curLog.str1;
            if (text.length > 7) {
                text = curLog.str1.slice(0, 6) + '...';
            }
            let node = cc.instantiate(dialog)
            node.name = "第二个选择"
            this.node.addChild(node)
            let position = dialog.position.clone()
            position.y += dialog.getContentSize().height
            node.setPosition(position)
            node.getChildByName('lab').getComponent(cc.Label).string = text;

            this.duihuakuang2 = node
        }
    }

    // 点击展示对话
    onClickShowDialog(event) {
        let target = event.target;
        target.active = false;
        if (this.duihuakuang1) {
            this.duihuakuang1.active = false
        }
        if (this.duihuakuang2) {
            this.duihuakuang2.active = false
        }

        if (target.name == "第二个选择") {
            this.selectIndex = 1
        } else {
            this.selectIndex = 0
        }

        let clickDialog = this["_clickDialog"];
        let clickDialogCallback = this["_clickDialogCallback"];
        let clickDialogAniCallback = this["_clickDialogAniCallback"];
        if (clickDialog) {
            this.showQiPao(clickDialog, "", () => {
                clickDialogCallback && clickDialogCallback();
            }, clickDialogAniCallback);
        }
    }

    updateMainTask() {
        let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
        let mainId = mainTaskInfo.Id
        let ziChanData = User.getZiChanData()
        let config = TaskManager.getTaskConfigById(mainId)
        if (mainId == MainTaskIdEnum.MainTask_514_2) {
            // User.setFirstStepIndex(1101)
            // this.My_Guide()
        } else if (mainId == MainTaskIdEnum.MainTask_532 && ziChanData.unLockNum[1] >= 1) {
            // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_532)
            // TaskManager.setCurTask(MainTaskIdEnum.MainTask_533)
        } else if (mainId == MainTaskIdEnum.MainTask_542 && ziChanData.unLockNum[2] >= 1) {
            // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_542)
            // TaskManager.setCurTask(MainTaskIdEnum.MainTask_543_1)
        } else if (mainId == MainTaskIdEnum.MainTask_539) {
            if (User.getMoney() >= config.taskNum && User.getMyLevel() >= config.levelNum) {
                // UserManager.subMoney(config.taskNum)
                TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_539)
                TaskManager.setCurTask(MainTaskIdEnum.MainTask_540)
            }
        } else if (mainId == MainTaskIdEnum.MainTask_554_2 && config.taskXuanPiaoNum && User.getUserIQ() >= config.taskXuanPiaoNum) {
            //选票
            TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_554_2)
            TaskManager.setCurTask(MainTaskIdEnum.MainTask_555)
        }

        this.updateTaskJinDu()

        //刷新称号
        let chenghao = LevelUpManager.getChengHao()
        this.chenghao.string = chenghao

        //小游戏图标显示
        if (mainId > MainTaskIdEnum.MainTask_511) {
            let node = this.node.getChildByName('UINode').getChildByName('小游戏')
            node.active = true
        }
    }

    updateTaskJinDu() {
        let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
        let mainId = mainTaskInfo.Id
        let config = TaskManager.getTaskConfigById(mainId)
        if (config && config.levelNum) {
            this.level_ProgressBar.node.active = true
            this.level_ProgressBar.progress = User.getMyLevel() / config.levelNum
            this.level_ProgressBar.node.getChildByName("jindu").getComponent(cc.Label).string = `${User.getMyLevel()}/${config.levelNum}`
        } else {
            this.level_ProgressBar.node.active = false
        }

        if (config && config.taskNum) {
            this.qian_ProgressBar.node.active = true
            this.qian_ProgressBar.progress = Number((User.getMoney() / config.taskNum).toFixed(2))
            this.qian_ProgressBar.node.getChildByName("jindu").getComponent(cc.Label).string = `${Common5.getNumberChangeHanzi(User.getMoney())}/${Common5.getNumberChangeHanzi(config.taskNum)}`
        } else {
            this.qian_ProgressBar.node.active = false
        }

        // if (mainId == MainTaskIdEnum.MainTask_516_2 && config && User.getMyLevel() >= config.levelNum && User.getMoney() >= config.taskNum) {

        // }
    }
}