Exemple #1
0
        protected override void OnSpawn()
        {
            base.OnSpawn();
            _spawned = true;
            Debug.Log($"[MultiIO] ConduitIO.OnSpawn() -> ConduitType: {ConduitType.ToString()}  CellOffset: {CellOffset.x + "," + CellOffset.y}");
            portCell = GetPortCell();
            MultiIOExtensions.RegisterPort(portCell, this);
            //Register an event listener for any changes to the grid at the location of this port.
            ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(int)GetConduitObjectLayer()];

            partitionerEntry = GameScenePartitioner.Instance.Add("ConduitIO.OnSpawn", _parent, portCell, layer, delegate
            {
                UpdateConduitExistsStatus();
            });
            //Register this conduit to the relevant network. Allows the network to determine flow direction.
            IUtilityNetworkMgr networkManager = GetNetworkManager();

            _networkItem = new FlowUtilityNetwork.NetworkItem(ConduitType, EndpointType, portCell, _parent);
            networkManager.AddToNetworks(portCell, _networkItem, EndpointType != Endpoint.Conduit);

            if (UseConduitUpdater)
            {
                GetConduitManager().AddConduitUpdater(ConduitTick, FlowPriority);
            }

            UpdateConduitExistsStatus(true);
        }
            public static void Postfix(ref bool __result, BuildingDef __instance, GameObject source_go, int cell, Orientation orientation, ref string fail_reason)
            {
                if (!__result || source_go == null)
                {
                    return;
                }
                List <ConduitIO> portList = MultiIOExtensions.GetAllPortsFromObject(source_go);

                if (portList.Count == 0)
                {
                    return;
                }

                foreach (ConduitIO port in portList)
                {
                    CellOffset rotatedCellOffset = Rotatable.GetRotatedCellOffset(port.CellOffset, orientation);
                    int        portCell          = Grid.OffsetCell(cell, rotatedCellOffset);
                    //fail_reason is ref, Invoke will modify this array if fail_reason is used
                    object[] parameters = new object[] { source_go, port.ConduitType, portCell, fail_reason };
                    //Debug.Log($"[MultiIO] Are Conduit Ports in Valid Positions?");
                    __result    = (bool)areConduitPortsInValidPositionsMethod.Invoke(__instance, parameters);
                    fail_reason = (string)parameters[3];
                    if (!__result)
                    {
                        return;
                    }
                }
            }
Exemple #3
0
        protected override void OnCleanUp()
        {
            MultiIOExtensions.UnregisterPort(portCell);
            GetConduitManager().RemoveConduitUpdater(ConduitTick);
            GameScenePartitioner.Instance.Free(ref partitionerEntry);
            IUtilityNetworkMgr networkManager = GetNetworkManager();

            networkManager.RemoveFromNetworks(portCell, _networkItem, EndpointType != Endpoint.Conduit);
        }
            public static void Postfix(BuildingCellVisualizer __instance)
            {
                List <ConduitIO> ports = MultiIOExtensions.GetAllPortsFromObject(__instance.gameObject);

                foreach (ConduitIO outPort in ports)
                {
                    GameObject visualizer = outPort.CellVisualizer;
                    if (visualizer != null)
                    {
                        UnityEngine.Object.Destroy(visualizer);
                    }
                }
            }
            public static void Postfix(BuildingCellVisualizer __instance)
            {
                List <ConduitIO> ports = MultiIOExtensions.GetAllPortsFromObject(__instance.gameObject);

                foreach (ConduitIO port in ports)
                {
                    GameObject visualizer = port.CellVisualizer;
                    if (visualizer != null)
                    {
                        visualizer.SetActive(false);
                    }
                }
            }
            public static void Postfix(BuildingCellVisualizer __instance, int cell)
            {
                ConduitIO port = MultiIOExtensions.GetPortAt(__instance.gameObject, cell);

                if (port != null)
                {
                    GameObject visualizer = port.CellVisualizer;
                    SizePulse  pulse      = visualizer.AddComponent <SizePulse>();
                    pulse.speed            = 20f;
                    pulse.multiplier       = 0.75f;
                    pulse.updateWhenPaused = true;
                    pulse.onComplete       = (System.Action)Delegate.Combine(pulse.onComplete, (System.Action) delegate { UnityEngine.Object.Destroy(pulse); });
                }
            }
            public static void Postfix(ref bool __result, BuildingDef __instance, GameObject source_go, int cell, Orientation orientation)
            {
                if (!__result || source_go == null)
                {
                    return;
                }
                List <ConduitIO> portList = MultiIOExtensions.GetAllPortsFromObject(source_go);

                if (portList.Count == 0)
                {
                    return;
                }

                foreach (ConduitIO port in portList)
                {
                }
            }
            public static void Postfix(HashedString mode, BuildingCellVisualizer __instance, Building ___building, BuildingCellVisualizerResources ___resources)
            {
                List <ConduitIO> ports      = MultiIOExtensions.GetAllPortsFromObject(___building.gameObject);
                Sprite           outputIcon = ___resources.gasOutputIcon;
                Sprite           inputIcon  = ___resources.gasInputIcon;

                if (OverlayModes.GasConduits.ID == mode)
                {
                    foreach (ConduitIO port in ports)
                    {
                        if (port.ConduitType == ConduitType.Gas)
                        {
                            CellOffset offset = port.CellOffset;
                            int        cell   = Grid.OffsetCell(___building.GetCell(), ___building.GetRotatedOffset(offset));
                            CallDrawUtilityIcon(__instance, cell, port is InputPort ? inputIcon : outputIcon, ref port.CellVisualizer, port.IconColor, Color.white);
                        }
                    }
                }
                else if (OverlayModes.LiquidConduits.ID == mode)
                {
                    foreach (ConduitIO port in ports)
                    {
                        if (port.ConduitType == ConduitType.Liquid)
                        {
                            CellOffset offset = port.CellOffset;
                            int        cell   = Grid.OffsetCell(___building.GetCell(), ___building.GetRotatedOffset(offset));
                            CallDrawUtilityIcon(__instance, cell, port is InputPort ? inputIcon : outputIcon, ref port.CellVisualizer, port.IconColor, Color.white);
                        }
                    }
                }
                else if (OverlayModes.SolidConveyor.ID == mode)
                {
                    foreach (ConduitIO port in ports)
                    {
                        if (port.ConduitType == ConduitType.Solid)
                        {
                            CellOffset offset = port.CellOffset;
                            int        cell   = Grid.OffsetCell(___building.GetCell(), ___building.GetRotatedOffset(offset));
                            CallDrawUtilityIcon(__instance, cell, port is InputPort ? inputIcon : outputIcon, ref port.CellVisualizer, port.IconColor, Color.white);
                        }
                    }
                }
            }
            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;
                }
            }