import { _decorator, instantiate, log, Prefab, Sprite, Vec2, Vec3 } from 'cc';
import { ModulerBase } from './ModulerBase';
import { GameMgr } from './GameMgr';
import { MapMgr } from './MapMgr';
import { resMgr } from '../../Frames/ResourcesMgr';
import { TowerData } from '../../DataItem/ItemData';
import { dataMgr } from '../../Frames/DataManager';
import { Tower } from '../Tower';
import { ExpandTower, LaserTower, MShootTower, ShootTower, StickTower } from './InsTower';
const { ccclass, property } = _decorator;

@ccclass('TowerMgr')
export class TowerMgr extends ModulerBase {
    // @property(Prefab)
    // pre: Prefab = null;
    start() {
        //GameMgr.Instance.getModuler(MapMgr).test();
        //this.getModuler(MapMgr).test();
    }
    creatTower(pos: Vec3, data: TowerData) {
        //const data: TowerData = dataMgr.getData(id, "TowerDt");

        const node = instantiate(resMgr.getPrefab("Tower"));
        //const node = instantiate(resMgr.getPrefab("Tower"));
        //const tower = node.getComponent(Tower);
        let tower: Tower;
        switch (data.fireType) {
            case "shoot":
                tower = node.addComponent(ShootTower);
                break;
            case "expand":
                tower = node.addComponent(ExpandTower);
                break;
            case "mshoot":
                tower = node.addComponent(MShootTower);
                break;
            case "laser":
                tower = node.addComponent(LaserTower);
                break;
            case "stick":
                tower = node.addComponent(StickTower);
                break;
            default:
                break;
        }
        node.parent = this.node;
        tower.init(data, pos);
    }
    protected clearSelf(): void {

    }

    bTouchTower(pos: Vec2) {
        for (const towerNode of this.node.children) {
            const tower: Tower = towerNode.getComponent(Tower);
            if (tower.bTouch(pos)) {
                return true;
            }
        }
        return false;
    }
    update(deltaTime: number) {

    }
}


