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);
    }
Example #2
0
            public static void Postfix(int cell, string defName, string soundName, bool fireEvents, ref bool __result)
            {
                //Only need to patch if the result was false and a pipe is being checked (liquid/gas)
                if (__result)
                {
                    return;
                }
                if (!defName.Contains("Conduit"))
                {
                    return;
                }
                Building building = Grid.Objects[cell, 1]?.GetComponent <Building>();

                if (building == null)
                {
                    return;
                }

                ConduitIO port = MultiIOExtensions.GetPortAt(building.gameObject, cell);

                if (port == null)
                {
                    return;
                }

                ConduitType type      = port.ConduitType;
                string      nameCheck = "";

                if (type == ConduitType.Gas)
                {
                    nameCheck = "Gas";
                }
                else if (type == ConduitType.Liquid)
                {
                    nameCheck = "Liquid";
                }
                else if (type == ConduitType.Solid)
                {
                    nameCheck = "Solid";
                }
                if (nameCheck == "" || !defName.Contains(nameCheck))
                {
                    return;
                }

                BuildingCellVisualizer bcv = building.GetComponent <BuildingCellVisualizer>();

                if (bcv != null)
                {
                    if (fireEvents)
                    {
                        bcv.ConnectedEvent(cell);
                        string sound = GlobalAssets.GetSound(soundName);
                        if (sound != null)
                        {
                            KMonoBehaviour.PlaySound(sound);
                        }
                    }
                    __result = true;
                }
            }
    private bool CheckForConnection(int cell, string defName, string soundName, ref BuildingCellVisualizer outBcv, bool fireEvents = true)
    {
        outBcv = null;
        DebugUtil.Assert(defName != null, "defName was null");
        Building building = GetBuilding(cell);

        if (!(bool)building)
        {
            return(false);
        }
        DebugUtil.Assert(building.gameObject, "targetBuilding.gameObject was null");
        int num  = -1;
        int num2 = -1;
        int num3 = -1;

        if (defName.Contains("LogicWire"))
        {
            LogicPorts component = building.gameObject.GetComponent <LogicPorts>();
            if ((Object)component != (Object)null)
            {
                if (component.inputPorts != null)
                {
                    foreach (ILogicUIElement inputPort in component.inputPorts)
                    {
                        DebugUtil.Assert(inputPort != null, "input port was null");
                        if (inputPort.GetLogicUICell() == cell)
                        {
                            num = cell;
                            break;
                        }
                    }
                }
                if (num == -1 && component.outputPorts != null)
                {
                    foreach (ILogicUIElement outputPort in component.outputPorts)
                    {
                        DebugUtil.Assert(outputPort != null, "output port was null");
                        if (outputPort.GetLogicUICell() == cell)
                        {
                            num2 = cell;
                            break;
                        }
                    }
                }
            }
        }
        else if (defName.Contains("Wire"))
        {
            num  = building.GetPowerInputCell();
            num2 = building.GetPowerOutputCell();
        }
        else if (defName.Contains("Liquid"))
        {
            if (building.Def.InputConduitType == ConduitType.Liquid)
            {
                num = building.GetUtilityInputCell();
            }
            if (building.Def.OutputConduitType == ConduitType.Liquid)
            {
                num2 = building.GetUtilityOutputCell();
            }
            ElementFilter component2 = building.GetComponent <ElementFilter>();
            if ((Object)component2 != (Object)null)
            {
                DebugUtil.Assert(component2.portInfo != null, "elementFilter.portInfo was null A");
                if (component2.portInfo.conduitType == ConduitType.Liquid)
                {
                    num3 = component2.GetFilteredCell();
                }
            }
        }
        else if (defName.Contains("Gas"))
        {
            if (building.Def.InputConduitType == ConduitType.Gas)
            {
                num = building.GetUtilityInputCell();
            }
            if (building.Def.OutputConduitType == ConduitType.Gas)
            {
                num2 = building.GetUtilityOutputCell();
            }
            ElementFilter component3 = building.GetComponent <ElementFilter>();
            if ((Object)component3 != (Object)null)
            {
                DebugUtil.Assert(component3.portInfo != null, "elementFilter.portInfo was null B");
                if (component3.portInfo.conduitType == ConduitType.Gas)
                {
                    num3 = component3.GetFilteredCell();
                }
            }
        }
        if (cell == num || cell == num2 || cell == num3)
        {
            BuildingCellVisualizer buildingCellVisualizer = outBcv = building.gameObject.GetComponent <BuildingCellVisualizer>();
            if (((Object)buildingCellVisualizer != (Object)null) ? true : false)
            {
                if (fireEvents)
                {
                    buildingCellVisualizer.ConnectedEvent(cell);
                    string sound = GlobalAssets.GetSound(soundName, false);
                    if (sound != null)
                    {
                        KMonoBehaviour.PlaySound(sound);
                    }
                }
                return(true);
            }
        }
        outBcv = null;
        return(false);
    }