

import Sprite3D = Laya.Sprite3D;
import Dictionary from "../Util/Dictionary";
import { GamePool } from "./GamePool";
import Vector3 = Laya.Vector3;
import { GlobalParam } from "../Net/GlobalParam";
import { Scene3DManager } from "./Scene3DManager";

import Sprite = Laya.Sprite;
import Stage = Laya.Stage;
import MapLayer = Laya.MapLayer;
import TiledMap = Laya.TiledMap;
import Point = Laya.Point;
import Rectangle = Laya.Rectangle;
import Handler = Laya.Handler;
import WebGL = Laya.WebGL;

export class ParticleManager {
    private static instance: ParticleManager;
    public static get Instance(): ParticleManager {
        return ParticleManager.instance || (ParticleManager.instance = new ParticleManager());
    }
    private attackmaxcount = 0;
    AttackEffect(pos) {
        if (this.attackmaxcount >= GlobalParam.hitmaxcount) return;
        let h = GamePool.Instance.GetModel("hit");
        h.transform.position = pos;
        Scene3DManager.Instance.effectCon.addChild(h);
        this.attackmaxcount++;
        Laya.timer.once(800, this, this.RecoverEffect, [h], false);
    }
    RecoverEffect(sp: Sprite3D) {
        GamePool.Instance.RecoverModel(sp);
        this.attackmaxcount--;
    }
    
    /************************************************ */
    private tiledMap: TiledMap;
    private layer: MapLayer;
    private sprite: Sprite;
    private mapLoaded(): void {
        this.layer = this.tiledMap.getLayerByIndex(0);

        var radiusX: number = 32;
        var radiusY: number = Math.tan(180 / Math.PI * 30) * radiusX;
        var color: string = "#FF7F50";

        this.sprite = new Sprite();
        this.sprite.graphics.drawLine(0, 0, -radiusX, radiusY, color);
        this.sprite.graphics.drawLine(0, 0, radiusX, radiusY, color);
        this.sprite.graphics.drawLine(-radiusX, radiusY, 0, radiusY * 2, color);
        this.sprite.graphics.drawLine(radiusX, radiusY, 0, radiusY * 2, color);
        Laya.stage.addChild(this.sprite);
    }
    /************************************************ */


    private explodemaxcount = 0;
    ExplodeEffect(pos) {
        if (this.explodemaxcount >= GlobalParam.boommaxcount) return;
        let h = GamePool.Instance.GetModel("boom");
        h.transform.position = pos;
        Scene3DManager.Instance.effectCon.addChild(h);
        this.explodemaxcount++;
        Laya.timer.once(800, this, this.RecoverExpolde, [h], false);
    }
    RecoverExpolde(sp: Sprite3D) {
        GamePool.Instance.RecoverModel(sp);
        this.explodemaxcount--;
    }

    BloodEffect(pos) {
        let h = GamePool.Instance.GetModel("xue");
        h.transform.position = pos;
        Scene3DManager.Instance.effectCon.addChild(h);
        Laya.timer.once(800, this, this.RecoverBlood, [h], false);
    }
    RecoverBlood(sp: Sprite3D){
        GamePool.Instance.RecoverModel(sp);
    }
}