import { app } from "../App";
import GBattleData, { GBattleDataInfo } from "../battle/base/values/GAttributeData";
import { API } from "../consts/API";
import { GAPI, ModeOnHookOV } from "../consts/GAPI";
import GOnHookManager from "../manager/battle/mode/GOnHookManager";
import { GUI } from "../ui/UIConfig";
import BaseData from "./BaseData";

export enum GOnHookDataEnum{
    UPDATE = "GOnHookDataEnum_UPDATE",                  //刷新信息
}

//无限模式数据类
export default class GOnHookData extends BaseData{

    info:ModeOnHookOV;

    //是否允许下一关
    get isNextLevel(){
        if(!this.info) return false;
        return this.info.hookInfo.mapStates[this.info.onHookMap] >= 4;
    }

    async onInit() {
        await this.onUpdateInfo();
        console.log("GOnHookData Info",this.info);

    }

    //刷新数据
    async onUpdateInfo(info?){
        this.info = info || await GAPI.GOnHookInfo();
        app.event.emit(GOnHookDataEnum.UPDATE);
    }

    //切换地图
    async setMap(mapId:number){

        this.info = await GAPI.GOnHookSetMap(mapId,GOnHookManager.getIns().getKillSreepsIds());
        app.layer.Open(GUI.Tips,{text:"切换地图成功"});

    }

    //下一关
    async onNextLevel(){
        let info = await GAPI.GOnHookNextLevel(GOnHookManager.getIns().getKillSreepsIds());
        this.onUpdateInfo(info);
    }

    //战胜当前关卡
    async onWinLevel(){
        this.onUpdateInfo(await GAPI.GOnHookWinLevel())
    }

    //返回当前进度
    getProgress(){
        return this.info.hookInfo.mapStates[this.info.onHookMap] || 0
    }

}

