Example #1
0
        public static void ForceDeconstruction(int cell, bool isStairs = true)
        {
            if (!Grid.IsValidCell(cell))
            {
                return;
            }
            if (isStairs)
            {
                if (!MyGrid.IsStair(cell))
                {
                    return;
                }
            }
            else if (!MyGrid.IsScaffolding(cell))
            {
                return;
            }

            int layer = (int)ObjectLayer.Building;

            if (!isStairs)
            {
                layer = (int)ObjectLayer.AttachableBuilding;
            }
            GameObject gameObject = Grid.Objects[cell, layer];

            if (gameObject == null)
            {
                return;
            }

            //if (!isStairs && gameObject.GetComponent<Scaffolding>() == null) return;
            Deconstructable deconstructable = gameObject.GetComponent <Deconstructable>();

            if (deconstructable == null)
            {
                return;
            }
            if (!deconstructable.IsMarkedForDeconstruction())
            {
                return;
            }
            deconstructable.CompleteWork(null);
        }