import { GamePool, PoolType } from "../Game/GamePool";
import { Mound } from "../Game/Mound";
import Sprite3D = Laya.Sprite3D;
import Dictionary from "../Util/Dictionary";
import Transform3D = Laya.Transform3D;
import Vector3 = Laya.Vector3;
import {MainRoleManager} from "./MainRoleManager";
import { ThingArr } from "./StreetManager";
export  class MoundManager {
    private static instance: MoundManager;
    public static get Instance(): MoundManager {
        return this.instance || (this.instance = new MoundManager());
    }
    constructor() {
        this.MoundrDic = new Dictionary();
    }
    moundContainer: Sprite3D;
    public MoundrDic: Dictionary;
    public Init(da: Sprite3D) {
        this.moundContainer = da;
    }
    /**
     * 
     * @param type 创建tower   1:单个的  2:满的5个
     * @param x 
     */
    MakeMound(data:ThingArr) {
        let tower = GamePool.Instance.GetModel(GamePool.modeltype.Mound);
        if (!tower) return;
       // tower.transform.position = new Vector3(0, 0, MainRoleManager.Instance.player.transform.position.z + 40);
        this.moundContainer.addChild(tower);
        let ts = tower.getComponent(Mound) as Mound;
        if (!ts) ts = tower.addComponent(Mound) as Mound;
        ts.SetMound(data);
        this.MoundrDic.set(tower.id, ts);
    }

    public Reset() {
        let arr = [];
        //console.log("this.towerDic.size",this.towerDic.size)
        for (const key in this.MoundrDic.container) {
            arr.push(key);
        }
        if (arr.length > 0) {
            for (let index = 0; index < arr.length; index++) {
                const element = arr[index];
                let s = this.MoundrDic.get(element) as Mound;
                if (s) s.Recovery();
            }
        }
    }

    /**
     * 去除tower(被消灭 或者回收)
     */
    RecoverMound(sp: Sprite3D) {
        this.MoundrDic.delete(sp.id);
    }
    /**
     * 创建hptext
     */
    public HpUi() {
        return GamePool.Instance.GetUi(PoolType.HpText);
    }
}