protected override void OnDragTool(int cell, int distFromOrigin)
    {
        if (path.Count == 0)
        {
            return;
        }
        PathNode pathNode = path[path.Count - 1];

        if (pathNode.cell == cell)
        {
            return;
        }
        placeSound = GlobalAssets.GetSound("Place_building_" + def.AudioSize, false);
        Vector3       pos      = Grid.CellToPos(cell);
        EventInstance instance = SoundEvent.BeginOneShot(placeSound, pos);

        if (path.Count > 1)
        {
            int      num       = cell;
            PathNode pathNode2 = path[path.Count - 2];
            if (num == pathNode2.cell)
            {
                if ((Object)previousCellConnection != (Object)null)
                {
                    previousCellConnection.ConnectedEvent(previousCell);
                    KMonoBehaviour.PlaySound(GlobalAssets.GetSound("OutletDisconnected", false));
                    previousCellConnection = null;
                }
                previousCell = cell;
                CheckForConnection(cell, def.PrefabID, string.Empty, ref previousCellConnection, false);
                PathNode pathNode3 = path[path.Count - 1];
                Object.Destroy(pathNode3.visualizer);
                PathNode pathNode4 = path[path.Count - 1];
                TileVisualizer.RefreshCell(pathNode4.cell, def.TileLayer, def.ReplacementLayer);
                path.RemoveAt(path.Count - 1);
                buildingCount = ((buildingCount != 1) ? (buildingCount - 1) : (buildingCount = 14));
                instance.setParameterValue("tileCount", (float)buildingCount);
                SoundEvent.EndOneShot(instance);
                goto IL_029c;
            }
        }
        if (!path.Exists((PathNode n) => n.cell == cell))
        {
            bool valid = CheckValidPathPiece(cell);
            path.Add(new PathNode
            {
                cell       = cell,
                visualizer = null,
                valid      = valid
            });
            CheckForConnection(cell, def.PrefabID, "OutletConnected", ref previousCellConnection, true);
            buildingCount = buildingCount % 14 + 1;
            instance.setParameterValue("tileCount", (float)buildingCount);
            SoundEvent.EndOneShot(instance);
        }
        goto IL_029c;
IL_029c:
        visualizer.SetActive(path.Count < 2);
        ResourceRemainingDisplayScreen.instance.SetNumberOfPendingConstructions(path.Count);
    }
    private IEnumerator VisUpdater()
    {
        conduitMgr.StashVisualGrids();
        if (path.Count == 1)
        {
            PathNode node = path[0];
            path[0] = CreateVisualizer(node);
        }
        ApplyPathToConduitSystem();
        for (int i = 0; i < path.Count; i++)
        {
            PathNode pathNode = path[i];
            pathNode = CreateVisualizer(pathNode);
            path[i]  = pathNode;
            string text = conduitMgr.GetVisualizerString(pathNode.cell) + "_place";
            KBatchedAnimController component = pathNode.visualizer.GetComponent <KBatchedAnimController>();
            if (component.HasAnimation(text))
            {
                pathNode.Play(text);
            }
            else
            {
                pathNode.Play(conduitMgr.GetVisualizerString(pathNode.cell));
            }
            component.TintColour = ((!def.IsValidBuildLocation(null, pathNode.cell, Orientation.Neutral, out string _)) ? Color.red : Color.white);
            TileVisualizer.RefreshCell(pathNode.cell, def.TileLayer, def.ReplacementLayer);
        }
        conduitMgr.UnstashVisualGrids();
        yield return((object)null);

        /*Error: Unable to find new state assignment for yield return*/;
    }
Exemplo n.º 3
0
        public void Clean()
        {
            if (DirtyCell != -1 && Grid.IsValidBuildingCell(DirtyCell))
            {
                //PUtil.LogDebug("1 " + DirtyCell);
                if (Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.TileLayer] == Visualizer)
                {
                    Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.TileLayer] = null;
                }
                //PUtil.LogDebug("2 " + DirtyCell);
                if (hasReplacementLayer && Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.ReplacementLayer] == Visualizer)
                {
                    Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.ReplacementLayer] = null;
                }
                //PUtil.LogDebug("3 " + DirtyCell);
                if (buildingConfig.BuildingDef.isKAnimTile)
                {
                    GameObject tileLayerObject = Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.TileLayer];
                    if (tileLayerObject == null || tileLayerObject.GetComponent <Constructable>() == null)
                    {
                        World.Instance.blockTileRenderer.RemoveBlock(buildingConfig.BuildingDef, false, SimHashes.Void, DirtyCell);
                    }

                    GameObject replacementLayerObject = hasReplacementLayer ? null : Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.ReplacementLayer];
                    if (replacementLayerObject == null || replacementLayerObject == Visualizer)
                    {
                        World.Instance.blockTileRenderer.RemoveBlock(buildingConfig.BuildingDef, true, SimHashes.Void, DirtyCell);
                    }
                }
                //PUtil.LogDebug("4 " + DirtyCell);
                TileVisualizer.RefreshCell(DirtyCell, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer);
            }

            DirtyCell = -1;
        }
Exemplo n.º 4
0
 protected override void OnCleanUp()
 {
     if (!Game.quitting)
     {
         GameScenePartitioner.Instance.Free(ref scenePartitionerEntry);
         if (hasSpawnedKComponents)
         {
             BuildingConfigManager.Instance.DestroyBuildingCompleteKComponents(base.gameObject, Def.Tag);
         }
         if (Def.UseStructureTemperature)
         {
             GameComps.StructureTemperatures.Remove(base.gameObject);
         }
         base.OnCleanUp();
         if (!WasReplaced())
         {
             int cell = Grid.PosToCell(this);
             Def.UnmarkArea(cell, base.Orientation, Def.ObjectLayer, base.gameObject);
             if (Def.IsTilePiece)
             {
                 Def.UnmarkArea(cell, base.Orientation, Def.TileLayer, base.gameObject);
                 Def.RunOnArea(cell, base.Orientation, delegate(int c)
                 {
                     TileVisualizer.RefreshCell(c, Def.TileLayer, Def.ReplacementLayer);
                 });
             }
             if (Def.IsFoundation)
             {
                 int[] placementCells = base.PlacementCells;
                 foreach (int num in placementCells)
                 {
                     Grid.Foundation[num] = false;
                     Game.Instance.roomProber.SolidChangedEvent(num, false);
                 }
             }
             if (Def.PreventIdleTraversalPastBuilding)
             {
                 for (int j = 0; j < base.PlacementCells.Length; j++)
                 {
                     Grid.PreventIdleTraversal[base.PlacementCells[j]] = false;
                 }
             }
         }
         if (WasReplaced() && Def.IsTilePiece && replacingTileLayer != Def.TileLayer)
         {
             int cell2 = Grid.PosToCell(this);
             Def.UnmarkArea(cell2, base.Orientation, Def.TileLayer, base.gameObject);
             Def.RunOnArea(cell2, base.Orientation, delegate(int c)
             {
                 TileVisualizer.RefreshCell(c, Def.TileLayer, Def.ReplacementLayer);
             });
         }
         Components.BuildingCompletes.Remove(this);
         UnregisterBlockTileRenderer();
         Trigger(-21016276, this);
     }
 }
 protected override void OnCleanUp()
 {
     if (connectionManager != null && !skipCleanup)
     {
         skipRefresh = true;
         int cell = Grid.PosToCell(base.transform.GetPosition());
         connectionManager.ClearCell(cell, isPhysicalBuilding);
         Building component = GetComponent <Building>();
         TileVisualizer.RefreshCell(cell, component.Def.TileLayer, component.Def.ReplacementLayer);
     }
 }
    protected override void OnSpawn()
    {
        base.OnSpawn();
        connectionManager = ConnectionManager;
        int cell = Grid.PosToCell(base.transform.GetPosition());

        connectionManager.SetConnections(Connections, cell, isPhysicalBuilding);
        Building component = GetComponent <Building>();

        TileVisualizer.RefreshCell(cell, component.Def.TileLayer, component.Def.ReplacementLayer);
    }
Exemplo n.º 7
0
        public static void CleanDirtyVisuals()
        {
            foreach (int cell in ColoredCells.Keys)
            {
                CellColorPayload cellColorPayload = ColoredCells[cell];
                TileVisualizer.RefreshCell(cell, cellColorPayload.TileLayer, cellColorPayload.ReplacementLayer);
            }

            ColoredCells.Clear();
            cleanableVisuals.ForEach(cleanableVisual => cleanableVisual.Clean());
        }
Exemplo n.º 8
0
        public static void SetVisualizerColor(int cell, Color color, GameObject visualizer, BuildingConfig buildingConfig)
        {
            if (buildingConfig.BuildingDef.isKAnimTile && buildingConfig.BuildingDef.BlockTileAtlas != null && !BlueprintsState.ColoredCells.ContainsKey(cell))
            {
                BlueprintsState.ColoredCells.Add(cell, new CellColorPayload(color, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer));
                TileVisualizer.RefreshCell(cell, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer);
            }

            if (visualizer.GetComponent <KBatchedAnimController>() != null)
            {
                visualizer.GetComponent <KBatchedAnimController>().TintColour = color;
            }
        }
    protected override void OnCleanUp()
    {
        Building component = GetComponent <Building>();

        if ((Object)component != (Object)null)
        {
            int         cell      = Grid.PosToCell(base.transform.GetPosition());
            ObjectLayer tileLayer = component.Def.TileLayer;
            if ((Object)Grid.Objects[cell, (int)tileLayer] == (Object)base.gameObject)
            {
                Grid.Objects[cell, (int)tileLayer] = null;
            }
            TileVisualizer.RefreshCell(cell, tileLayer, component.Def.ReplacementLayer);
        }
        base.OnCleanUp();
    }
    protected override void OnCompleteWork(Worker worker)
    {
        PrimaryElement  component  = GetComponent <PrimaryElement>();
        Building        building   = GetComponent <Building>();
        SimCellOccupier component2 = GetComponent <SimCellOccupier>();

        if ((UnityEngine.Object)DetailsScreen.Instance != (UnityEngine.Object)null && DetailsScreen.Instance.CompareTargetWith(base.gameObject))
        {
            DetailsScreen.Instance.Show(false);
        }
        float temperature   = component.Temperature;
        byte  disease_idx   = component.DiseaseIdx;
        int   disease_count = component.DiseaseCount;

        if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
        {
            if (building.Def.TileLayer != ObjectLayer.NumLayers)
            {
                int num = Grid.PosToCell(base.transform.GetPosition());
                if ((UnityEngine.Object)Grid.Objects[num, (int)building.Def.TileLayer] == (UnityEngine.Object)base.gameObject)
                {
                    Grid.Objects[num, (int)building.Def.ObjectLayer] = null;
                    Grid.Objects[num, (int)building.Def.TileLayer]   = null;
                    Grid.Foundation[num] = false;
                    TileVisualizer.RefreshCell(num, building.Def.TileLayer, building.Def.ReplacementLayer);
                }
            }
            component2.DestroySelf(delegate
            {
                TriggerDestroy(building, temperature, disease_idx, disease_count);
            });
        }
        else
        {
            TriggerDestroy(building, temperature, disease_idx, disease_count);
        }
        string sound = GlobalAssets.GetSound("Finish_Deconstruction_" + building.Def.AudioSize, false);

        if (sound != null)
        {
            KMonoBehaviour.PlaySound3DAtLocation(sound, base.gameObject.transform.GetPosition());
        }
        Trigger(-702296337, this);
    }
Exemplo n.º 11
0
        private void UpdateGrid(int cell)
        {
            Clean();

            if (Grid.IsValidBuildingCell(cell))
            {
                bool visualizerSeated = false;

                if (Grid.Objects[cell, (int)buildingConfig.BuildingDef.TileLayer] == null)
                {
                    Grid.Objects[cell, (int)buildingConfig.BuildingDef.TileLayer] = Visualizer;
                    visualizerSeated = true;
                }

                if (buildingConfig.BuildingDef.isKAnimTile)
                {
                    GameObject tileLayerObject        = Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.TileLayer];
                    GameObject replacementLayerObject = hasReplacementLayer ? Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.ReplacementLayer] : null;

                    if (tileLayerObject == null || tileLayerObject.GetComponent <Constructable>() == null && replacementLayerObject == null)
                    {
                        if (buildingConfig.BuildingDef.BlockTileAtlas != null)
                        {
                            if (!ValidCell(cell))
                            {
                                VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                            }

                            bool replacing = hasReplacementLayer && CanReplace(cell);
                            World.Instance.blockTileRenderer.AddBlock(LayerMask.NameToLayer("Overlay"), buildingConfig.BuildingDef, replacing, SimHashes.Void, cell);
                            if (replacing && !visualizerSeated && Grid.Objects[DirtyCell, (int)buildingConfig.BuildingDef.ReplacementLayer] == null)
                            {
                                Grid.Objects[cell, (int)buildingConfig.BuildingDef.ReplacementLayer] = Visualizer;
                            }
                        }
                    }

                    TileVisualizer.RefreshCell(cell, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer);
                }

                DirtyCell = cell;
            }
        }
Exemplo n.º 12
0
    private void MarkArea()
    {
        int         num         = Grid.PosToCell(base.transform.GetPosition());
        BuildingDef def         = building.Def;
        Orientation orientation = building.Orientation;
        ObjectLayer layer       = (!IsReplacementTile) ? def.ObjectLayer : def.ReplacementLayer;

        def.MarkArea(num, orientation, layer, base.gameObject);
        if (def.IsTilePiece)
        {
            GameObject x = Grid.Objects[num, (int)def.TileLayer];
            if ((UnityEngine.Object)x == (UnityEngine.Object)null)
            {
                def.MarkArea(num, orientation, def.TileLayer, base.gameObject);
                def.RunOnArea(num, orientation, delegate(int c)
                {
                    TileVisualizer.RefreshCell(c, def.TileLayer, def.ReplacementLayer);
                });
            }
            Grid.IsTileUnderConstruction[num] = true;
        }
    }
Exemplo n.º 13
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        TileVisualizer TV = target as TileVisualizer;

        if (GUILayout.Button("Show Tile level"))
        {
            TV.Show();
        }

        if (GUILayout.Button("Show Tile Grid Only"))
        {
            TV.ShowGrid();
        }

        if (GUILayout.Button("CLEAR"))
        {
            TV.Clear();
        }

        TV.CheckGrid();
    }
    private void UpdateVis(Vector3 pos)
    {
        bool flag  = def.IsValidPlaceLocation(visualizer, pos, buildingOrientation, out string _);
        bool flag2 = def.IsValidReplaceLocation(pos, buildingOrientation, def.ReplacementLayer, def.ObjectLayer);

        flag = (flag || flag2);
        if ((Object)visualizer != (Object)null)
        {
            Color c        = Color.white;
            float strength = 0f;
            if (!flag)
            {
                c        = Color.red;
                strength = 1f;
            }
            SetColor(visualizer, c, strength);
        }
        int num = Grid.PosToCell(pos);

        if ((Object)def != (Object)null)
        {
            Vector3 vector = Grid.CellToPosCBC(num, def.SceneLayer);
            visualizer.transform.SetPosition(vector);
            base.transform.SetPosition(vector - Vector3.up * 0.5f);
            if (def.IsTilePiece)
            {
                ClearTilePreview();
                if (Grid.IsValidBuildingCell(num))
                {
                    GameObject gameObject = Grid.Objects[num, (int)def.TileLayer];
                    if ((Object)gameObject == (Object)null)
                    {
                        Grid.Objects[num, (int)def.TileLayer] = visualizer;
                    }
                    if (def.isKAnimTile)
                    {
                        GameObject x = null;
                        if (def.ReplacementLayer != ObjectLayer.NumLayers)
                        {
                            x = Grid.Objects[num, (int)def.ReplacementLayer];
                        }
                        if ((Object)gameObject == (Object)null || ((Object)gameObject.GetComponent <Constructable>() == (Object)null && (Object)x == (Object)null))
                        {
                            TileVisualizer.RefreshCell(num, def.TileLayer, def.ReplacementLayer);
                            if ((Object)def.BlockTileAtlas != (Object)null)
                            {
                                int renderLayer = LayerMask.NameToLayer("Overlay");
                                BlockTileRenderer blockTileRenderer = World.Instance.blockTileRenderer;
                                blockTileRenderer.SetInvalidPlaceCell(num, !flag);
                                if (lastCell != num)
                                {
                                    blockTileRenderer.SetInvalidPlaceCell(lastCell, false);
                                }
                                blockTileRenderer.AddBlock(renderLayer, def, flag2, SimHashes.Void, num);
                            }
                        }
                    }
                }
            }
            if (lastCell != num)
            {
                lastCell = num;
            }
        }
    }
Exemplo n.º 15
0
 void Awake()
 {
     instance = this;
 }
Exemplo n.º 16
0
        public bool TryUse(int cell)
        {
            if (BlueprintsState.InstantBuild)
            {
                if (ValidCell(cell))
                {
                    Vector3    positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);
                    GameObject building    = buildingConfig.BuildingDef.Create(positionCBC, null, buildingConfig.SelectedElements, buildingConfig.BuildingDef.CraftRecipe, 293.15F, buildingConfig.BuildingDef.BuildingComplete);
                    if (building == null)
                    {
                        return(false);
                    }

                    buildingConfig.BuildingDef.MarkArea(cell, buildingConfig.Orientation, buildingConfig.BuildingDef.TileLayer, building);
                    buildingConfig.BuildingDef.RunOnArea(cell, buildingConfig.Orientation, cell0 => TileVisualizer.RefreshCell(cell0, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer));

                    if (building.GetComponent <Rotatable>() != null)
                    {
                        building.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
                    }

                    if (buildingConfig.BuildingDef.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>() != null && building.GetComponent <KAnimGraphTileVisualizer>() != null)
                    {
                        building.GetComponent <KAnimGraphTileVisualizer>().UpdateConnections((UtilityConnections)buildingConfig.Flags);
                    }

                    VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                    return(true);
                }
            }

            else if (IsPlaceable(cell))
            {
                Vector3    positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);
                GameObject building    = buildingConfig.BuildingDef.Instantiate(positionCBC, buildingConfig.Orientation, buildingConfig.SelectedElements);

                if (building == null)
                {
                    return(false);
                }

                if (building.GetComponent <Rotatable>() != null)
                {
                    building.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
                }

                if (buildingConfig.BuildingDef.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>() != null && building.GetComponent <KAnimGraphTileVisualizer>() != null)
                {
                    building.GetComponent <KAnimGraphTileVisualizer>().UpdateConnections((UtilityConnections)buildingConfig.Flags);
                }

                if (ToolMenu.Instance != null)
                {
                    building.FindOrAddComponent <Prioritizable>().SetMasterPriority(ToolMenu.Instance.PriorityScreen.GetLastSelectedPriority());
                }

                VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                return(true);
            }

            return(false);
        }
Exemplo n.º 17
0
        protected override void OnDragComplete(Vector3 cursorDown, Vector3 cursorUp)
        {
            base.OnDragComplete(cursorDown, cursorUp);

            if (hasFocus)
            {
                Grid.PosToXY(cursorDown, out int x0, out int y0);
                Grid.PosToXY(cursorUp, out int x1, out int y1);

                if (x0 > x1)
                {
                    Util.Swap(ref x0, ref x1);
                }

                if (y0 > y1)
                {
                    Util.Swap(ref y0, ref y1);
                }

                for (int x = x0; x <= x1; ++x)
                {
                    for (int y = y0; y <= y1; ++y)
                    {
                        int cell = Grid.XYToCell(x, y);

                        if (Grid.IsVisible(cell))
                        {
                            for (int layer = 0; layer < Grid.ObjectLayers.Length; ++layer)
                            {
                                GameObject gameObject = Grid.Objects[cell, layer];
                                Building   building;

                                if (gameObject != null && (building = gameObject.GetComponent <Building>()) != null && IsActiveLayer(GetFilterLayerFromGameObject(gameObject)))
                                {
                                    IHaveUtilityNetworkMgr utilityNetworkManager;

                                    if ((utilityNetworkManager = building.Def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>()) != null)
                                    {
                                        UtilityConnections connectionsToRemove = 0;
                                        UtilityConnections buildingConnections = utilityNetworkManager.GetNetworkManager().GetConnections(cell, false);

                                        foreach (UtilityConnections utilityConnection in connections)
                                        {
                                            if ((buildingConnections & utilityConnection) != utilityConnection)
                                            {
                                                continue;
                                            }

                                            int offsetCell = Grid.OffsetCell(cell, Utilities.ConnectionsToOffset(utilityConnection));
                                            if (Grid.IsValidBuildingCell(offsetCell))
                                            {
                                                Grid.CellToXY(offsetCell, out int x2, out int y2);

                                                if (x2 >= x0 && x2 <= x1 && y2 >= y0 && y2 <= y1)
                                                {
                                                    GameObject otherGameObject = Grid.Objects[offsetCell, layer];
                                                    Building   otherBuilding;

                                                    if (otherGameObject != null && (otherBuilding = otherGameObject.GetComponent <Building>()) != null && otherBuilding.Def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>() != null && IsActiveLayer(GetFilterLayerFromGameObject(gameObject)))
                                                    {
                                                        connectionsToRemove |= utilityConnection;
                                                    }
                                                }
                                            }
                                        }

                                        if (connectionsToRemove != 0)
                                        {
                                            if (building.GetComponent <KAnimGraphTileVisualizer>() != null)
                                            {
                                                building.GetComponent <KAnimGraphTileVisualizer>().UpdateConnections(buildingConnections & ~connectionsToRemove);
                                                building.GetComponent <KAnimGraphTileVisualizer>().Refresh();
                                            }

                                            TileVisualizer.RefreshCell(cell, building.Def.TileLayer, building.Def.ReplacementLayer);
                                            utilityNetworkManager.GetNetworkManager()?.ForceRebuildNetworks();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        public bool TryUse(int cell)
        {
            Clean();

            if (BlueprintsState.InstantBuild)
            {
                if (ValidCell(cell))
                {
                    Vector3    positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);
                    GameObject building    = buildingConfig.BuildingDef.Create(positionCBC, null, buildingConfig.SelectedElements, buildingConfig.BuildingDef.CraftRecipe, 293.15F, buildingConfig.BuildingDef.BuildingComplete);
                    if (building == null)
                    {
                        return(false);
                    }

                    buildingConfig.BuildingDef.MarkArea(cell, buildingConfig.Orientation, buildingConfig.BuildingDef.TileLayer, building);
                    buildingConfig.BuildingDef.RunOnArea(cell, buildingConfig.Orientation, cell0 => TileVisualizer.RefreshCell(cell0, buildingConfig.BuildingDef.TileLayer, buildingConfig.BuildingDef.ReplacementLayer));

                    if (building.GetComponent <Deconstructable>() != null)
                    {
                        building.GetComponent <Deconstructable>().constructionElements = buildingConfig.SelectedElements.ToArray();
                    }

                    if (building.GetComponent <Rotatable>() != null)
                    {
                        building.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
                    }

                    VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                    return(true);
                }
            }

            else if (IsPlaceable(cell))
            {
                Vector3    positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);
                GameObject building    = buildingConfig.BuildingDef.Instantiate(positionCBC, buildingConfig.Orientation, buildingConfig.SelectedElements);
                if (building == null)
                {
                    return(false);
                }

                if (building.GetComponent <Rotatable>() != null)
                {
                    building.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
                }

                if (Visualizer.GetComponent <KBatchedAnimController>() != null)
                {
                    Visualizer.GetComponent <KBatchedAnimController>().TintColour = BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT;
                }

                VisualsUtilities.SetVisualizerColor(cell, BlueprintsAssets.BLUEPRINTS_COLOR_INVALIDPLACEMENT, Visualizer, buildingConfig);
                return(true);
            }

            return(false);
        }
Exemplo n.º 19
0
 void Update()
 {
     if (null == instance) {
         instance = this;
     }
 }
Exemplo n.º 20
0
 void Awake()
 {
     instance = this;
 }
Exemplo n.º 21
0
    protected override void OnSpawn()
    {
        base.OnSpawn();
        KBatchedAnimController component = GetComponent <KBatchedAnimController>();
        Rotatable component2             = GetComponent <Rotatable>();

        if ((Object)component != (Object)null && (Object)component2 == (Object)null)
        {
            component.Offset = Def.GetVisualizerOffset() + Def.placementPivot;
        }
        KBoxCollider2D component3 = GetComponent <KBoxCollider2D>();

        if ((Object)component3 != (Object)null)
        {
            Vector3 visualizerOffset = Def.GetVisualizerOffset();
            component3.offset += new Vector2(visualizerOffset.x, visualizerOffset.y);
        }
        int cell = Grid.PosToCell(base.transform.GetPosition());

        if (Def.IsFoundation)
        {
            int[] placementCells = base.PlacementCells;
            foreach (int num in placementCells)
            {
                Grid.Foundation[num] = true;
                Game.Instance.roomProber.SolidChangedEvent(num, false);
            }
        }
        Vector3 position = Grid.CellToPosCBC(cell, Def.SceneLayer);

        base.transform.SetPosition(position);
        PrimaryElement component4 = GetComponent <PrimaryElement>();

        if ((Object)component4 != (Object)null && component4.Mass == 0f)
        {
            component4.Mass = Def.Mass[0];
        }
        Def.MarkArea(cell, base.Orientation, Def.ObjectLayer, base.gameObject);
        if (Def.IsTilePiece)
        {
            Def.MarkArea(cell, base.Orientation, Def.TileLayer, base.gameObject);
            Def.RunOnArea(cell, base.Orientation, delegate(int c)
            {
                TileVisualizer.RefreshCell(c, Def.TileLayer, Def.ReplacementLayer);
            });
        }
        RegisterBlockTileRenderer();
        if (Def.PreventIdleTraversalPastBuilding)
        {
            for (int j = 0; j < base.PlacementCells.Length; j++)
            {
                Grid.PreventIdleTraversal[base.PlacementCells[j]] = true;
            }
        }
        KSelectable component5 = GetComponent <KSelectable>();

        if ((Object)component5 != (Object)null)
        {
            component5.SetStatusIndicatorOffset(Def.placementPivot);
        }
        Components.BuildingCompletes.Add(this);
        BuildingConfigManager.Instance.AddBuildingCompleteKComponents(base.gameObject, Def.Tag);
        hasSpawnedKComponents = true;
        scenePartitionerEntry = GameScenePartitioner.Instance.Add(base.name, this, GetExtents(), GameScenePartitioner.Instance.completeBuildings, null);
        Attributes attributes = this.GetAttributes();

        if (attributes != null)
        {
            Deconstructable component6 = GetComponent <Deconstructable>();
            if ((Object)component6 != (Object)null)
            {
                for (int k = 1; k < component6.constructionElements.Length; k++)
                {
                    Tag     tag     = component6.constructionElements[k];
                    Element element = ElementLoader.GetElement(tag);
                    if (element != null)
                    {
                        foreach (AttributeModifier attributeModifier in element.attributeModifiers)
                        {
                            attributes.Add(attributeModifier);
                        }
                    }
                    else
                    {
                        GameObject gameObject = Assets.TryGetPrefab(tag);
                        if ((Object)gameObject != (Object)null)
                        {
                            PrefabAttributeModifiers component7 = gameObject.GetComponent <PrefabAttributeModifiers>();
                            if ((Object)component7 != (Object)null)
                            {
                                foreach (AttributeModifier descriptor in component7.descriptors)
                                {
                                    attributes.Add(descriptor);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 22
0
    protected override void OnSpawn()
    {
        base.OnSpawn();
        Subscribe(2127324410, OnCancelDelegate);
        if ((UnityEngine.Object)rotatable != (UnityEngine.Object)null)
        {
            MarkArea();
        }
        this.fetchList = new FetchList2(storage, Db.Get().ChoreTypes.BuildFetch);
        PrimaryElement component = GetComponent <PrimaryElement>();
        Element        element   = ElementLoader.GetElement(SelectedElementsTags[0]);

        Debug.Assert(element != null, "Missing primary element for Constructable");
        component.ElementID = element.id;
        float num3 = component.Temperature = (component.Temperature = 293.15f);

        Recipe.Ingredient[] allIngredients = Recipe.GetAllIngredients(selectedElementsTags);
        foreach (Recipe.Ingredient ingredient in allIngredients)
        {
            FetchList2 fetchList = this.fetchList;
            Tag        tag       = ingredient.tag;
            num3 = ingredient.amount;
            fetchList.Add(tag, null, null, num3, FetchOrder2.OperationalRequirement.None);
            MaterialNeeds.Instance.UpdateNeed(ingredient.tag, ingredient.amount);
        }
        if (!building.Def.IsTilePiece)
        {
            base.gameObject.layer = LayerMask.NameToLayer("Construction");
        }
        building.RunOnArea(delegate(int offset_cell)
        {
            if ((UnityEngine.Object)base.gameObject.GetComponent <ConduitBridge>() == (UnityEngine.Object)null)
            {
                GameObject gameObject2 = Grid.Objects[offset_cell, 7];
                if ((UnityEngine.Object)gameObject2 != (UnityEngine.Object)null)
                {
                    gameObject2.DeleteObject();
                }
            }
        });
        if (IsReplacementTile)
        {
            GameObject gameObject = null;
            if (building.Def.ReplacementLayer != ObjectLayer.NumLayers)
            {
                int cell = Grid.PosToCell(base.transform.GetPosition());
                gameObject = Grid.Objects[cell, (int)building.Def.ReplacementLayer];
                if ((UnityEngine.Object)gameObject == (UnityEngine.Object)null || (UnityEngine.Object)gameObject == (UnityEngine.Object)base.gameObject)
                {
                    Grid.Objects[cell, (int)building.Def.ReplacementLayer] = base.gameObject;
                    if ((UnityEngine.Object)base.gameObject.GetComponent <SimCellOccupier>() != (UnityEngine.Object)null)
                    {
                        int renderLayer = LayerMask.NameToLayer("Overlay");
                        World.Instance.blockTileRenderer.AddBlock(renderLayer, building.Def, IsReplacementTile, SimHashes.Void, cell);
                    }
                    TileVisualizer.RefreshCell(cell, building.Def.TileLayer, building.Def.ReplacementLayer);
                }
                else
                {
                    Debug.LogError("multiple replacement tiles on the same cell!");
                    Util.KDestroyGameObject(base.gameObject);
                }
            }
        }
        bool flag = building.Def.BuildingComplete.GetComponent <Ladder>();

        waitForFetchesBeforeDigging = (flag || (bool)building.Def.BuildingComplete.GetComponent <SimCellOccupier>() || (bool)building.Def.BuildingComplete.GetComponent <Door>() || (bool)building.Def.BuildingComplete.GetComponent <LiquidPumpingStation>());
        if (flag)
        {
            int x     = 0;
            int y     = 0;
            int cell2 = Grid.PosToCell(this);
            Grid.CellToXY(cell2, out x, out y);
            int y2 = y - 3;
            ladderDetectionExtents = new Extents(x, y2, 1, 5);
            ladderParititonerEntry = GameScenePartitioner.Instance.Add("Constructable.OnNearbyBuildingLayerChanged", base.gameObject, ladderDetectionExtents, GameScenePartitioner.Instance.objectLayers[1], OnNearbyBuildingLayerChanged);
            OnNearbyBuildingLayerChanged(null);
        }
        this.fetchList.Submit(OnFetchListComplete, true);
        PlaceDiggables();
        ReachabilityMonitor.Instance instance = new ReachabilityMonitor.Instance(this);
        instance.StartSM();
        Subscribe(493375141, OnRefreshUserMenuDelegate);
        Prioritizable component2 = GetComponent <Prioritizable>();
        Prioritizable obj        = component2;

        obj.onPriorityChanged = (Action <PrioritySetting>)Delegate.Combine(obj.onPriorityChanged, new Action <PrioritySetting>(OnPriorityChanged));
        OnPriorityChanged(component2.GetMasterPriority());
    }
    private void BuildPath()
    {
        ApplyPathToConduitSystem();
        int num = 0;

        for (int i = 0; i < path.Count; i++)
        {
            PathNode           pathNode           = path[i];
            Vector3            vector             = Grid.CellToPosCBC(pathNode.cell, Grid.SceneLayer.Building);
            UtilityConnections utilityConnections = (UtilityConnections)0;
            GameObject         gameObject         = Grid.Objects[pathNode.cell, (int)def.TileLayer];
            if ((Object)gameObject == (Object)null)
            {
                utilityConnections = conduitMgr.GetConnections(pathNode.cell, false);
                if ((DebugHandler.InstantBuildMode || (Game.Instance.SandboxModeActive && SandboxToolParameterMenu.instance.settings.InstantBuild)) && def.IsValidBuildLocation(visualizer, vector, Orientation.Neutral) && def.IsValidPlaceLocation(visualizer, vector, Orientation.Neutral, out string _))
                {
                    BuildingDef buildingDef       = def;
                    int         cell              = pathNode.cell;
                    Orientation orientation       = Orientation.Neutral;
                    Storage     resource_storage  = null;
                    IList <Tag> selected_elements = selectedElements;
                    float       temperature       = 293.15f;
                    float       time              = GameClock.Instance.GetTime();
                    gameObject = buildingDef.Build(cell, orientation, resource_storage, selected_elements, temperature, true, time);
                }
                else
                {
                    gameObject = def.TryPlace(null, vector, Orientation.Neutral, selectedElements, 0);
                    if ((Object)gameObject != (Object)null)
                    {
                        if (!def.MaterialsAvailable(selectedElements) && !DebugHandler.InstantBuildMode)
                        {
                            PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, UI.TOOLTIPS.NOMATERIAL, null, vector, 1.5f, false, false);
                        }
                        Constructable component = gameObject.GetComponent <Constructable>();
                        if (component.IconConnectionAnimation(0.1f * (float)num, num, "Wire", "OutletConnected_release") || component.IconConnectionAnimation(0.1f * (float)num, num, "Pipe", "OutletConnected_release"))
                        {
                            num++;
                        }
                        Prioritizable component2 = gameObject.GetComponent <Prioritizable>();
                        if ((Object)component2 != (Object)null)
                        {
                            if ((Object)BuildMenu.Instance != (Object)null)
                            {
                                component2.SetMasterPriority(BuildMenu.Instance.GetBuildingPriority());
                            }
                            if ((Object)PlanScreen.Instance != (Object)null)
                            {
                                component2.SetMasterPriority(PlanScreen.Instance.GetBuildingPriority());
                            }
                        }
                    }
                }
            }
            else
            {
                IUtilityItem component3 = gameObject.GetComponent <KAnimGraphTileVisualizer>();
                if (component3 != null)
                {
                    utilityConnections = component3.Connections;
                }
                utilityConnections |= conduitMgr.GetConnections(pathNode.cell, false);
                if ((Object)gameObject.GetComponent <BuildingComplete>() != (Object)null)
                {
                    component3.UpdateConnections(utilityConnections);
                }
            }
            if (def.ReplacementLayer != ObjectLayer.NumLayers && !DebugHandler.InstantBuildMode && (!Game.Instance.SandboxModeActive || !SandboxToolParameterMenu.instance.settings.InstantBuild) && def.IsValidBuildLocation(null, vector, Orientation.Neutral))
            {
                GameObject gameObject2 = Grid.Objects[pathNode.cell, (int)def.TileLayer];
                GameObject x           = Grid.Objects[pathNode.cell, (int)def.ReplacementLayer];
                if ((Object)gameObject2 != (Object)null && (Object)x == (Object)null)
                {
                    BuildingComplete component4 = gameObject2.GetComponent <BuildingComplete>();
                    if ((Object)component4 != (Object)null && (Object)component4.Def != (Object)def)
                    {
                        Constructable component5 = def.BuildingUnderConstruction.GetComponent <Constructable>();
                        component5.IsReplacementTile = true;
                        gameObject = def.Instantiate(vector, Orientation.Neutral, selectedElements, 0);
                        component5.IsReplacementTile = false;
                        if (!def.MaterialsAvailable(selectedElements) && !DebugHandler.InstantBuildMode)
                        {
                            PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, UI.TOOLTIPS.NOMATERIAL, null, vector, 1.5f, false, false);
                        }
                        Grid.Objects[pathNode.cell, (int)def.ReplacementLayer] = gameObject;
                        IUtilityItem component6 = gameObject.GetComponent <KAnimGraphTileVisualizer>();
                        if (component6 != null)
                        {
                            utilityConnections = component6.Connections;
                        }
                        utilityConnections |= conduitMgr.GetConnections(pathNode.cell, false);
                        if ((Object)gameObject.GetComponent <BuildingComplete>() != (Object)null)
                        {
                            component6.UpdateConnections(utilityConnections);
                        }
                        string visualizerString = conduitMgr.GetVisualizerString(utilityConnections);
                        string text             = visualizerString;
                        if (gameObject.GetComponent <KBatchedAnimController>().HasAnimation(visualizerString + "_place"))
                        {
                            text += "_place";
                        }
                        Play(gameObject, text);
                    }
                }
            }
            if ((Object)gameObject != (Object)null)
            {
                IUtilityItem component7 = gameObject.GetComponent <KAnimGraphTileVisualizer>();
                if (component7 != null)
                {
                    component7.Connections = utilityConnections;
                }
            }
            TileVisualizer.RefreshCell(pathNode.cell, def.TileLayer, def.ReplacementLayer);
        }
        ResourceRemainingDisplayScreen.instance.SetNumberOfPendingConstructions(0);
    }