/*
 * @Author: YeeChan
 * @Date: 2021-12-30 14:42:48
 * @Description: 体力管理器
 */

import { ryw_Event } from "../../FrameWork/Event/EventEnum";
import EventMgr from "../../FrameWork/Event/EventMgr";
import GameMgr from "../../FrameWork/Mgr/GameMgr";


export default class DayUnlock {

    private static DayUnlockAllNum: number = 0;//无限体力看得视频数量(侦探笔记)
    private static DayUnlockAllTime: number = 0;//无限体力 时间点(侦探笔记)
    private static DayUnlockAllTipNum: number = 0;//免费看提示


    private static DayUnlockAllNum_fkwz: number = 0;//无限体力看得视频数量(疯狂文字)
    private static DayUnlockAllTime_fkwz: number = 0;//无限体力 时间点(疯狂文字)



    //定时器
    private static interval = null;
    /**
     * 初始数据
     * @param data 
     */
    public static initData(data: any) {
        this.DayUnlockAllNum = this.verify(data.DayUnlockAllNum, 0);
        this.DayUnlockAllTime = this.verify(data.DayUnlockAllTime, 0);

        this.DayUnlockAllNum_fkwz = this.verify(data.DayUnlockAllNum_fkwz, 0);
        this.DayUnlockAllTime_fkwz = this.verify(data.DayUnlockAllTime_fkwz, 0);

        this.DayUnlockAllTipNum = this.verify(data.DayUnlockAllTipNum, 0);
        if (this.interval) {
            clearInterval(this.interval);
            this.interval = null;
        }
        this.interval = setInterval(() => {
            // this.updateDayUnlocksicalTime();
        }, 1000)
        this.updateDayUnlocksicalTime();
        this.updateDayUnlocksicalTime_fkwz();
    }

    /**
     * 获取所有数据
     * @returns 
     */
    public static getData() {
        let tab = { 
            DayUnlockAllNum: this.DayUnlockAllNum, 
            DayUnlockAllTime: this.DayUnlockAllTime,
            DayUnlockAllTipNum:this.DayUnlockAllTipNum,
            DayUnlockAllNum_fkwz: this.DayUnlockAllNum_fkwz, 
            DayUnlockAllTime_fkwz: this.DayUnlockAllTime_fkwz
        };
        return tab;
    }

    public static resetData() {
        this.DayUnlockAllNum = 0
        this.DayUnlockAllTime = 0
        this.DayUnlockAllTipNum = 0
        this.DayUnlockAllNum_fkwz = 0
        this.DayUnlockAllTime_fkwz = 0
    }
    
    


    /**
     * 获取无限体力看视频的次数(侦探笔记)
     * @returns 
     */
    public static getDayUnlockVideoAllNum() {
        return this.DayUnlockAllNum;
    }

    /**
     * 设置无限体力看视频的次数(侦探笔记)
     * @param num 
     */
    public static setDayUnlocVideoAllNum(num: number) {
        this.DayUnlockAllNum = num;
        this.DayUnlockAllNum_fkwz = num;

    }



    //提示不要看广告
    public static getDayUnlockVideoAllTipNum() {
        return this.DayUnlockAllTipNum;
    }
    public static setDayUnlocVideoAllTipNum(num: number) {
        this.DayUnlockAllTipNum = num;
    }


    

    

    /**
     * 获取无限体力看视频的次数(疯狂文字)
     * @returns 
     */
    public static getDayUnlockVideoAllNum_fkwz() {
        return this.DayUnlockAllNum_fkwz;
    }

    /**
     * 设置无限体力看视频的次数(疯狂文字)
     * @param num 
     */
    public static setDayUnlocVideoAllNum_fkwz(num: number) {
        this.DayUnlockAllNum_fkwz = num;
    }


    /**
     * 无限体力的时间(侦探笔记)
     * @param num 
     * @returns 
     */
    public static getDayUnlockVideoAllTime() {
        //return this.DayUnlockAllTime;
        let ctime = this.getNowTime()
        let addTime = this.DayUnlockAllTime-ctime
        return addTime!
    }

    /**
     * 无限体力的时间(侦探笔记)
     * @param num 
     */
    public static setDayUnlockVideoAllTime(num: number) {
        this.DayUnlockAllTime = num;
        
    }

    /**
     * 无限体力的时间(疯狂文字)
     * @param num 
     * @returns 
     */
    public static getDayUnlockVideoAllTime_fkwz() {
        return this.DayUnlockAllTime_fkwz;
    }

    /**
     * 无限体力的时间(疯狂文字)
     * @param num 
     */
    public static setDayUnlockVideoAllTime_fkwz(num: number) {
        this.DayUnlockAllTime_fkwz = num;
    }

    /**
     * 更新体力数据 需要放入定时器中(侦探笔记)
     */
    public static updateDayUnlocksicalTime() {
        let again = false;
        if (this.getDayUnlockVideoAllTime() > 0) {//无限体力中
            EventMgr.emitEvent_custom(ryw_Event.unLockAllLevelTmp);
            console.log("unLockAllLevelTmp_ztbj");
        }
        if (again) {
            this.updateDayUnlocksicalTime();
        }
    }
    /**
     * 更新体力数据 需要放入定时器中(疯狂文字)
     */
    public static updateDayUnlocksicalTime_fkwz() {
        let again = false;
        if (this.getDayUnlockVideoAllTime_fkwz() > 0) {//无限体力中
            EventMgr.emitEvent_custom(ryw_Event.unLockAllLevelTmp_fkwz);
            console.log("unLockAllLevelTmp_fkwz");
        }
        if (again) {
            this.updateDayUnlocksicalTime_fkwz();
        }
    }

    /**
     * 增加一个新的无限体力24小时(侦探笔记)
     * @param show 
     */
    public static addNewDayUnlocksicalAll() {
        //增加时间
        let ctime = this.getNowTime() + (24 * 60 * 60 * 1000);
        // if (this.getDayUnlockVideoAllTime() > 0) {
        //     ctime = this.getDayUnlockVideoAllTime() + (24 * 60 * 60 * 1000);
        // }
        this.setDayUnlockVideoAllTime(ctime)
        GameMgr.getInstance_custom().saveGameData_custom();
        this.updateDayUnlocksicalTime();

        //this.addNewDayUnlocksicalAll_fkwz()
    }
    /**
     * 增加一个新的无限体力24小时(疯狂文字)
     * @param show 
     */
    public static addNewDayUnlocksicalAll_fkwz() {
        //增加时间
        let ctime = this.getNowTime() + (24 * 60 * 60 * 1000);
        // if (this.getDayUnlockVideoAllTime_fkwz() > 0) {
        //     ctime = this.getDayUnlockVideoAllTime_fkwz() + (24 * 60 * 60 * 1000);
        // }
        this.setDayUnlockVideoAllTime_fkwz(ctime)
        GameMgr.getInstance_custom().saveGameData_custom();
        this.updateDayUnlocksicalTime_fkwz();
    }
    /**
        * 获取当前的时间戳
        */
    public static getNowTime(): number {
        return (new Date()).getTime();
    }


    /**
     * 数据校验
     * @param data 校验的数据
     * @param defaultValue 默认值
     */
    public static verify(data: any, defaultValue: any) {
        if (data !== undefined) {
            return data;
        }
        return defaultValue;
    }

    /**
     * 格式化时间获取:时分秒 00:00
     * @param {number} 时间秒
     */
    public static formatTime3(time: number): string {

        let str: string = "";

        let m: number = time / 60;
        m = parseInt(m + "");
        let s: number = time - m * 60;
        s = parseInt(s + "");

        if (m > 9) {
            str += m + ":";
        }
        else {
            str += "0" + m + ":";
        }
        if (s > 9) {
            str += s;
        }
        else {
            str += "0" + s;
        }
        return str;
    }




    /**
     * 格式化时间获取:时分秒 00:00:00
     * @param {number} 时间戳差值(ms)
     */
    public static formatTime(time: number): string {
        let str: string = "";
        let h: number = time / 3600;
        h = parseInt(h + "");
        let m: number = (time - h * 3600) / 60;
        m = parseInt(m + "");
        let s: number = time - h * 3600 - m * 60;
        s = parseInt(s + "");
        if (h > 0) {
            str += h + ":";
        }
        if (m > 9) {
            str += m + ":";
        }
        else {
            str += "0" + m + ":";
        }
        if (s > 9) {
            str += s + "";
        }
        else {
            str += "0" + s;
        }
        return str;
    }




}