private static int GetUnstableCellAbove(int cell)
    {
        Vector2I cellXY = Grid.CellToXY(cell);
        UnstableGroundManager component = World.Instance.GetComponent <UnstableGroundManager>();
        List <int>            cellsContainingFallingAbove = component.GetCellsContainingFallingAbove(cellXY);

        if (cellsContainingFallingAbove.Contains(cell))
        {
            return(cell);
        }
        int num = Grid.CellAbove(cell);

        while (Grid.IsValidCell(num))
        {
            if (Grid.Foundation[num])
            {
                return(Grid.InvalidCell);
            }
            if (Grid.Solid[num])
            {
                if (Grid.Element[num].IsUnstable)
                {
                    return(num);
                }
                return(Grid.InvalidCell);
            }
            if (cellsContainingFallingAbove.Contains(num))
            {
                return(num);
            }
            num = Grid.CellAbove(num);
        }
        return(Grid.InvalidCell);
    }
示例#2
0
    private void Explode(Vector3 pos, int cell, int prev_cell, Element element)
    {
        PlayImpactSound(pos);
        Vector3 pos2 = pos;

        pos2.z = Grid.GetLayerZ(Grid.SceneLayer.FXFront2);
        Game.Instance.SpawnFX(explosionEffectHash, pos2, 0f);
        Substance substance = element.substance;
        int       num       = Random.Range(explosionOreCount.x, explosionOreCount.y + 1);
        Vector2   a         = -velocity.normalized;
        Vector2   a2        = new Vector2(a.y, 0f - a.x);

        ListPool <ScenePartitionerEntry, Comet> .PooledList pooledList = ListPool <ScenePartitionerEntry, Comet> .Allocate();

        GameScenePartitioner.Instance.GatherEntries((int)pos.x - 3, (int)pos.y - 3, 6, 6, GameScenePartitioner.Instance.pickupablesLayer, pooledList);
        foreach (ScenePartitionerEntry item in pooledList)
        {
            GameObject gameObject = (item.obj as Pickupable).gameObject;
            if (!((Object)gameObject.GetComponent <MinionIdentity>() != (Object)null) && gameObject.GetDef <CreatureFallMonitor.Def>() == null)
            {
                Vector2 vector = gameObject.transform.GetPosition() - pos;
                vector  = vector.normalized;
                vector += new Vector2(0f, 0.55f);
                vector *= 0.5f * Random.Range(explosionSpeedRange.x, explosionSpeedRange.y);
                if (GameComps.Fallers.Has(gameObject))
                {
                    GameComps.Fallers.Remove(gameObject);
                }
                if (GameComps.Gravities.Has(gameObject))
                {
                    GameComps.Gravities.Remove(gameObject);
                }
                GameComps.Fallers.Add(gameObject, vector);
            }
        }
        pooledList.Recycle();
        int num2 = splashRadius + 1;

        for (int i = -num2; i <= num2; i++)
        {
            for (int j = -num2; j <= num2; j++)
            {
                int num3 = Grid.OffsetCell(cell, j, i);
                if (Grid.IsValidCell(num3) && !destroyedCells.Contains(num3))
                {
                    float num4 = (1f - (float)Mathf.Abs(j) / (float)num2) * (1f - (float)Mathf.Abs(i) / (float)num2);
                    if (num4 > 0f)
                    {
                        DamageTiles(num3, prev_cell, num4 * totalTileDamage * 0.5f);
                    }
                }
            }
        }
        float mass        = (num <= 0) ? 1f : (explosionMass / (float)num);
        float temperature = Random.Range(explosionTemperatureRange.x, explosionTemperatureRange.y);

        for (int k = 0; k < num; k++)
        {
            Vector2 normalized = (a + a2 * Random.Range(-1f, 1f)).normalized;
            Vector3 v          = normalized * Random.Range(explosionSpeedRange.x, explosionSpeedRange.y);
            Vector3 a3         = normalized.normalized * 0.75f;
            a3 += new Vector3(0f, 0.55f, 0f);
            a3 += pos;
            GameObject go = substance.SpawnResource(a3, mass, temperature, byte.MaxValue, 0, false, false, false);
            if (GameComps.Fallers.Has(go))
            {
                GameComps.Fallers.Remove(go);
            }
            GameComps.Fallers.Add(go, v);
        }
        if (addTiles > 0)
        {
            int   depthOfElement = GetDepthOfElement(cell, element);
            float num5           = 1f - (float)(depthOfElement - addTilesMinHeight) / (float)(addTilesMaxHeight - addTilesMinHeight);
            int   num6           = Mathf.Min(addTiles, Mathf.Clamp(Mathf.RoundToInt((float)addTiles * num5), 1, addTiles));
            HashSetPool <int, Comet> .PooledHashSet pooledHashSet = HashSetPool <int, Comet> .Allocate();

            HashSetPool <int, Comet> .PooledHashSet pooledHashSet2 = HashSetPool <int, Comet> .Allocate();

            QueuePool <GameUtil.FloodFillInfo, Comet> .PooledQueue pooledQueue = QueuePool <GameUtil.FloodFillInfo, Comet> .Allocate();

            pooledQueue.Enqueue(new GameUtil.FloodFillInfo
            {
                cell  = cell,
                depth = 0
            });
            pooledQueue.Enqueue(new GameUtil.FloodFillInfo
            {
                cell  = prev_cell,
                depth = 0
            });
            pooledQueue.Enqueue(new GameUtil.FloodFillInfo
            {
                cell  = Grid.OffsetCell(cell, new CellOffset(-1, 0)),
                depth = 0
            });
            pooledQueue.Enqueue(new GameUtil.FloodFillInfo
            {
                cell  = Grid.OffsetCell(cell, new CellOffset(1, 0)),
                depth = 0
            });
            GameUtil.FloodFillConditional(pooledQueue, SpawnTilesCellTest, pooledHashSet2, pooledHashSet, 10);
            float mass2 = (num6 <= 0) ? 1f : (addTileMass / (float)addTiles);
            UnstableGroundManager component = World.Instance.GetComponent <UnstableGroundManager>();
            foreach (int item2 in pooledHashSet)
            {
                if (num6 <= 0)
                {
                    break;
                }
                component.Spawn(item2, element, mass2, temperature, byte.MaxValue, 0);
                num6--;
            }
            pooledHashSet.Recycle();
            pooledHashSet2.Recycle();
            pooledQueue.Recycle();
        }
    }