import { Framework } from "../../framework/Framework";

//位置数据拼接系数
export let BattleLayoutScale = 10000

export enum BattleLayoutPos {//战斗布局,f1-f15为出战区,b1-b15为后备区  value: 10000*raceID + level    
    'b1',
    'b2',
    'b3',
    'b4',
    'b5',
    'b6',
    'b7',
    'b8',
    'b9',
     'b10',
     'b11',
     'b12',
     'b13',
     'b14',
     'b15',
     'f1',                                    
     'f2',
     'f3',
     'f4',
     'f5',
     'f6',
     'f7',
     'f8',
     'f9',
     'f10',
     'f11',
     'f12',
     'f13',
     'f14',
     'f15',
}

export enum BattleOptsType{
    //生成
    New = 1,
    //合成
    Merge = 2,
    //移动
    Move = 3,
    //销毁
    Remove = 4,
    //击杀敌人
    Kill = 11,
}

export interface BattleOptsBase{
    type:BattleOptsType;
}

export interface BattleOptsNew extends BattleOptsBase{
    type:BattleOptsType.New;
    //位置 BattleLayoutPos
    pos:string;
    //种族
    raceID:number;
    //等级
    level:number;
}

export interface BattleOptsMerge extends BattleOptsBase{
    type:BattleOptsType.Merge;
    //目标位置
    targetPos:string;
    //源位置
    srcPos:string;
}

export interface BattleOptsMove extends BattleOptsBase{
    type:BattleOptsType.Move;
    //目标位置
    targetPos:string;
    //源位置
    srcPos:string;
}

export interface BattleOptsRemove extends BattleOptsBase{
    type:BattleOptsType.Remove;
    //位置
    pos:string;
}

export interface BattleOptsKill extends BattleOptsBase{
    type:BattleOptsType.Kill;
    //敌人id
    typeID:number;
    //击杀数量
    count:number;
}

export interface Duplicate{
    chapter:number,                          // 当前解锁的最大章节编号(重置进新章节前更新)
    max_process: number,                     // 主线进度(最大挑战成功的关卡id)
    process: number,                         // 当前挂机进度(关卡id)
    start_time: number,                    // 挂机时间  ?
}

export interface BattleLayoutData{
    typeID: number;
    raceID: number;
    level: number;
}

class Data {
    // 当前关卡数据
    private _duplicate:Duplicate = null;
    //
    private _layout = []
    //章节奖励领取情况
    private _duplicate_reward:{[id:string]:number} = {}
    //登录初始化数据
    setLoginData(data){
        if(data.duplicate){
            this._duplicate = data.duplicate
        }

        if(data.duplicate_reward){
            this._duplicate_reward = data.duplicate_reward
        }

        if(data.layout){
            this._layout = []
            Object.values(BattleLayoutPos).forEach(value => {
                const element = data.layout[value]
                if(element != undefined){
                    this._layout.push(element)
                }
            });

        }
    }

    get duplicate(){
        return this._duplicate
    }
    set duplicate(value){
        this._duplicate = value
    }

    set layout(layout:{[id:string]:number} | Array<number>){
        // 兼容旧数据
        if(Array.isArray(layout)){
            this._layout = layout
        }else{
            this._layout = []
            Object.values(BattleLayoutPos).forEach(value => {
                const element = layout[value]
                if(element != undefined){
                    this._layout.push(element)
                }
            });
        }
    }
    get layout():number[]{
        return this._layout
    }

    get duplicateReward(){
        return this._duplicate_reward
    }
    set duplicateReward(value){
        this._duplicate_reward = value
    }

    //检查章节奖励是否领取
    checkDuplicate(chapterID:number|string){
        return this._duplicate_reward[chapterID.toString()] || 0
    }

    
    
}

export let BattleData = new Data;