import { GamePool, PoolType } from "../GameLogic/GamePool";
import { Mound } from "../GameLogic/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 default class MoundManager {
    private static instance: MoundManager;
    public static get Instance(): MoundManager {
        return this.instance || (this.instance = new MoundManager());
    }
    constructor() {
        this.towerDic = new Dictionary();
    }

    towerContainer: Sprite3D;
    public towerDic: Dictionary;
    public Init(da: Sprite3D) {
        this.towerContainer = da;
    }

    /**
     * 
     * @param type 创建tower   1:单个的  2:满的5个
     * @param x 
     */
    CreateTower(data:ThingArr) {
        let tower = GamePool.Instance.SetActiveObject(GamePool.pooltype.Tower);
        if (!tower) return;

       // tower.transform.position = new Vector3(0, 0, MainRoleManager.Instance.player.transform.position.z + 40);
        this.towerContainer.addChild(tower);
        let ts = tower.getComponent(Mound) as Mound;
        if (!ts) ts = tower.addComponent(Mound) as Mound;
        ts.SetTower(data);
        this.towerDic.set(tower.id, ts);
    }

    /**
     * 去除tower(被消灭 或者回收)
     */
    RemoveTower(sp: Sprite3D) {
        this.towerDic.delete(sp.id);
    }

    /**
     * 创建hptext
     */
    public CreateHpText() {
        return GamePool.Instance.SetActiveForUi(PoolType.HpText);
    }

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