public override void doDie(Creature killer)
    {
        World.getInstance().unregisterTower(this);
        World.getInstance().unregisterTowerBySpawn(_spawn);

        _gameInstance.GetComponent <HealthBarController> ().destroy();

        Vector3 originalPos = getGameInstance().transform.position;

        GameObject.Destroy(getGameInstance());

        GameObject fracturedInstance = GameObject.Instantiate(
            getTower().getFracturedAsset(), World.getInstance().getTerrainTransform()) as GameObject;

        fracturedInstance.transform.position = originalPos;
        fracturedInstance.AddComponent <TowerCollapse> ().Propagate = true;

        GameObject ps = ParticleSystemTable.getInstance().instantiateParticleSystem("PS_Collapse");

        ps.transform.position = originalPos;
        ps.AddComponent <ParticleSystemCollector> ();
        ps.GetComponent <ParticleSystem> ().Play();
        ps.AddComponent <AudioSource> ().loop = false;
        SoundTable.getInstance().getAudioPlayer(ps.GetComponent <AudioSource> (), "sound_collapse");
        ps.GetComponent <AudioSource> ().Play();
        CameraShake.INSTANCE.prepareShake();

        PlatfromSpawnTable.getInstance().enablePlatform(_spawn);
        SpawnTable.getInstance().releaseSpawn(_spawn);
    }
    public SwarmOrder createOrder(byte source, byte target, int spawnZone)
    {
        PathSolution ps = _computedPaths [spawnZone];

        if (source != 0)
        {
            ps = ps.getSpecifiSolution(source);
        }

        Vector3         targetAvgPos = new Vector3();
        Queue <Vector3> path         = null;

        if (target == MAIN_TARGET)
        {
            path         = ps.getPathToTarget();
            targetAvgPos = SpawnTable.getInstance().getTargetSpawns() [0].getAveragePosition();
        }
        else
        {
            path = ps.getPathToTower(target);

            if (path == null)
            {
                Debug.Log("Null order. source: " + source + ", target: " + target + ", spawnZone: " + spawnZone);
                return(null);
            }

            targetAvgPos = SpawnTable.getInstance().getTowerSpawns() [target].getAveragePosition();
        }

        SwarmOrder order = new SwarmOrder(target, targetAvgPos, path);

        return(order);
    }
    public void spawnPlatforms()
    {
        foreach (GameObject obj in _spawnPlatforms.Values)
        {
            GameObject.Destroy(obj);
        }
        _spawnPlatforms.Clear();

        Dictionary <byte, SpawnPoint> towerSpawns = SpawnTable.getInstance().getTowerSpawns();

        Material[] platformMat = { Resources.Load("Materials/glowing_platform") as Material };

        foreach (byte index in towerSpawns.Keys)
        {
            SpawnPoint sp = towerSpawns [index];

            //SpawnTable.SpawnPoint sp = to
            Vector3[] vertices =
            {
                new Vector3(0,                        0,                        0),
                new Vector3(0,                        0, Constants.VERTEX_SPACING),
                new Vector3(Constants.VERTEX_SPACING, 0,                        0),
                new Vector3(Constants.VERTEX_SPACING, 0, Constants.VERTEX_SPACING)
            };

            GameObject empty = new GameObject();
            empty.name           = "spawn_position_" + index;
            empty.transform.name = empty.name + "_transform";
            empty.AddComponent <MeshFilter> ();
            empty.AddComponent <MeshRenderer> ();

            int[] faces =
            {
                0, 3, 2,
                0, 1, 3
            };

            Mesh platform = new Mesh();
            platform.vertices  = vertices;
            platform.triangles = faces;

            platform.RecalculateNormals();

            empty.GetComponent <MeshFilter> ().mesh        = platform;
            empty.GetComponent <MeshRenderer> ().materials = platformMat;

            empty.transform.parent = World.getInstance().getTerrainTransform();
            Vector3 emptyPos = Formulas.getPositionInMap(sp.getAveragePosition());
            emptyPos.y += 0.1f;
            emptyPos.x -= Constants.VERTEX_SPACING / 2.0f;
            emptyPos.z -= Constants.VERTEX_SPACING / 2.0f;
            empty.transform.position = emptyPos;

            empty.AddComponent <BoxCollider> ();
            empty.AddComponent <SpawnIndex> ();
            empty.GetComponent <SpawnIndex> ()._spawnIndex = index;

            _spawnPlatforms.Add(index, empty);
        }
    }
        public virtual void init()
        {
            Message("Siege registration of " + name + " has begun!");
            Message("Now its open for 2 hours!");

            npc4 = (L2Character)SpawnTable.getInstance().spawnOne(MessengerId, spawn4[0], spawn4[1], spawn4[2], spawn4[3]);
        }
    private void updateObstacleGridWithTowers()
    {
        Dictionary <byte, SpawnPoint> towerSpawns = SpawnTable.getInstance().getTowerSpawns();

        foreach (byte key in towerSpawns.Keys)
        {
            SpawnPoint sp = towerSpawns [key];

            foreach (int vertexIndex in sp.getBounds().Keys)
            {
                _obstacleGrid [vertexIndex] = key;
                _maxPossiblePositions++;
            }
        }
    }
    public void setPositionGrid(Vector3[] positions, byte[] obstacleGrid)
    {
        _obstacleGrid = obstacleGrid;
        _positions    = new Vector3[positions.Length];

        for (int i = 0; i < positions.Length; i++)
        {
            _positions [i] = Formulas.getPositionInMap(positions [i]);
            if (_obstacleGrid [i] == Pathfinder.WALKABLE_CELL)
            {
                _maxPossiblePositions++;
            }
        }

        updateObstacleGridWithTowers();

        SpawnPoint target = SpawnTable.getInstance().getTargetSpawns() [0];

        _maxPossiblePositions += target.getBounds().Count;
    }
    public void preComputePaths()
    {
        _computedPaths.Clear();

        Dictionary <int, SpawnPoint> enemySpawns = SpawnTable.getInstance().getMonsterSpawnPoints();

        foreach (int soldierSpawnIndex in enemySpawns.Keys)
        {
            SpawnPoint spawnObject = enemySpawns [soldierSpawnIndex];

            SpawnPoint target = SpawnTable.getInstance().getTargetSpawns() [0];
            float      closer = Mathf.Infinity;
            int        index  = 0;
            foreach (int vIndex in target.getBounds().Keys)
            {
                float sqrtMag = (target.getBounds() [vIndex] - spawnObject.getAveragePosition()).sqrMagnitude;
                if (sqrtMag < closer)
                {
                    closer = sqrtMag;
                    index  = vIndex;
                }
            }

            Vector3      finalTarget = Formulas.getPositionInMap(target.getBounds() [index]);
            Pathfinder   pf          = new Pathfinder(spawnObject, finalTarget);
            PathSolution ps          = pf.computePaths();

            GameObject go = new GameObject("Spawn_Zone_Controller_" + soldierSpawnIndex);
            go.transform.parent   = World.getInstance().getTerrainTransform();
            go.transform.position = Formulas.getPositionInMap(spawnObject.getAveragePosition());               // Irrelevant, but still...
            go.AddComponent <SpawnZoneController> ()._spawnZone = soldierSpawnIndex;
            _spawnZoneControllers.Add(soldierSpawnIndex, go);

            _computedPaths.Add(soldierSpawnIndex, ps);
        }

        SwarmAI.getInstance().initialize(_computedPaths);
    }
        public virtual void start()
        {
            isActive = true;
            Message("Siege of " + name + " has begun!");
            npc1       = (L2Character)SpawnTable.getInstance().spawnOne(BossId, spawn1[0], spawn1[1], spawn1[2], spawn1[3]);
            npc2       = (L2Character)SpawnTable.getInstance().spawnOne(Minion1Id, spawn2[0], spawn2[1], spawn2[2], spawn2[3]);
            npc3       = (L2Character)SpawnTable.getInstance().spawnOne(Minion2Id, spawn3[0], spawn3[1], spawn3[2], spawn3[3]);
            npc4       = (L2Character)SpawnTable.getInstance().spawnOne(MessengerId, spawn4[0], spawn4[1], spawn4[2], spawn4[3]);
            clanDamage = new SortedList <int, double>();
            mobActive  = new List <L2Character>();

            foreach (int[] sp in mobSpawns)
            {
                L2Character o = (L2Character)SpawnTable.getInstance().spawnOne(sp[0], sp[1], sp[2], sp[3], sp[4]);
                mobActive.Add(o);
            }

            TimeSiege          = new Timer();
            TimeSiege.Interval = 3600000;// 60 минут
            TimeSiege.Elapsed += new ElapsedEventHandler(TimeSiegeEnd);

            Message("Guards " + mobActive.Count + "! 60 min left");
        }