import { TD } from "../App";
import { Dungeon, GAPI } from "../consts/GAPI";
import BaseData from "./BaseData";

export default class DungeonData extends BaseData{

    info:{[key:string]:Dungeon};

    async onInit() {
        await this.UpdateInfo();
    }

    //获取信息
    async getInfo(){
        if(this.info){
            return this.info;
        }else{
            return await this.UpdateInfo();
        }
    }

    //更新信息
    async UpdateInfo(){
        return this.info = await GAPI.GDungeonGetInfo();
    }

    //获取指定Id的进度
    async getInfoProcess(id:number){
        return ((await this.getInfo())[`${id}`] as Dungeon).dungeonCfgItemId;
    }

    //获取指定副本的最大关卡
    getMaxProcess(id:number){
        let datas = TD[`TbGSysDungeon${160001}`].getDataList();
        return datas[datas.length - 1].id;
    }

    //挑战
    async challenge(dungeonId:number,dungeonItemId:number){
        this.info = await GAPI.GDungeonChallenge(dungeonId,dungeonItemId)
    }

}