import { GlobalVariable } from "../game_module/GlobalVariable";
import GameTool from "../Util/GameTool";
import { CfgManager } from "./CfgManager";
import { PlayerManager } from "./PlayerManager";

export class Level {
    public road_list = [];
    public gold: number;
    public fail_gold: number = 0;
    public enemy: number;
    enemy_hp: number;
    isgold: boolean;
    enemy_cloth:number;
    constructor() {

    }
    SetLevel(data) {
        this.road_list = GameTool.SpliteString(data["road_list"]);
        this.gold = Number(data["gold"]);
        this.fail_gold = Number(data["fail_gold"]);
        this.enemy = data["enemy"];
        this.enemy_hp = data["enemy_hp"];
        this.isgold = Number(data["isgold"]) == 1;
        this.enemy_cloth=data["enemy_cloth"]?Number(data["enemy_cloth"]):1;
    }

}
export default class LevelController {
    private static instance: LevelController;
    public static get Instance(): LevelController {
        return LevelController.instance || (LevelController.instance = new LevelController());
    }

    private curLevelData: any;
    public _level: Level;

    public SetLevel(level?) {
        //level=13;
        //    if (level > GlobalVariable.maxLevel) level = GameTool.randomInt(GlobalVariable.maxLevel - 5, GlobalVariable.maxLevel);
        // if()
        // if (level > GlobalVariable.maxLevel) level = GameTool.randomInt(GlobalVariable.maxLevel - 5, GlobalVariable.maxLevel);
        //   let maxL=CfgManager.Instance.mission.length;
        //    if(level>=maxL)level = GameTool.randomInt(maxL- 6, maxL-1);
        //   this.curLevelData = CfgManager.Instance.GetMission(level + 1);
        //     if (!this._level) this._level = new Level();
        //     this._level.SetLevel(this.curLevelData);
        //level=1;

        let len = CfgManager.Instance._level.length;
        let index =PlayerManager.Instance.stage;//TODO
        if (PlayerManager.Instance.stage > len) index = GameTool.randomInt(1, len);
        this.curLevelData = CfgManager.Instance.GetLevel(index);
        if (!this._level) this._level = new Level();
        this._level.SetLevel(this.curLevelData);
    }
}