diff --git a/Content.Server/GameObjects/Components/Power/PowerDevice.cs b/Content.Server/GameObjects/Components/Power/PowerDevice.cs index 2144e887a3..df973b4534 100644 --- a/Content.Server/GameObjects/Components/Power/PowerDevice.cs +++ b/Content.Server/GameObjects/Components/Power/PowerDevice.cs @@ -98,15 +98,16 @@ namespace Content.Server.GameObjects.Components.Power _provider.RemoveDevice(this); } + _provider = value; if (value != null) { - _provider = value; _provider.AddDevice(this); } else { Connected = DrawTypes.None; } + } } @@ -133,7 +134,7 @@ namespace Content.Server.GameObjects.Components.Power { if (Owner.TryGetComponent(out PowerNodeComponent node)) { - if (node.Parent != null) + if (node.Parent != null && node.Parent.HasDevice(this)) { node.Parent.RemoveDevice(this); } @@ -145,7 +146,7 @@ namespace Content.Server.GameObjects.Components.Power if (Provider != null) { - Provider.RemoveDevice(this); + Provider = null; } base.Shutdown(); @@ -228,7 +229,7 @@ namespace Content.Server.GameObjects.Components.Power private void ConnectToBestProvider() { //Any values we can connect to or are we already connected to a node, cancel! - if (!AvailableProviders.Any() || Connected == DrawTypes.Node) + if (!AvailableProviders.Any() || Connected == DrawTypes.Node || Deleted) return; //Get the starting value for our loop diff --git a/Content.Server/GameObjects/Components/Power/PowerProviderComponent.cs b/Content.Server/GameObjects/Components/Power/PowerProviderComponent.cs index 6dc70e885c..8e1f045962 100644 --- a/Content.Server/GameObjects/Components/Power/PowerProviderComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerProviderComponent.cs @@ -173,7 +173,7 @@ namespace Content.Server.GameObjects.Components.Power } /// - /// Register a continuous load from a device connected to the powernet + /// Register a continuous load from a device connected to the powernet /// public void AddDevice(PowerDeviceComponent device) { @@ -184,7 +184,7 @@ namespace Content.Server.GameObjects.Components.Power } /// - /// Update one of the loads from a deviceconnected to the powernet + /// Update one of the loads from a deviceconnected to the powernet /// public void UpdateDevice(PowerDeviceComponent device, float oldLoad) { @@ -196,7 +196,7 @@ namespace Content.Server.GameObjects.Components.Power } /// - /// Remove a continuous load from a device connected to the powernet + /// Remove a continuous load from a device connected to the powernet /// public void RemoveDevice(PowerDeviceComponent device) { @@ -209,8 +209,7 @@ namespace Content.Server.GameObjects.Components.Power } else { - var name = device.Owner.Prototype.Name; - Logger.WarningS("power", "We tried to remove a device twice from the same {0} somehow, prototype {1}", Name, name); + Logger.WarningS("power", "We tried to remove device {0} twice from the same {1}, somehow.", device.Owner, Owner); } } } diff --git a/Content.Server/GameObjects/Components/Power/Powernet.cs b/Content.Server/GameObjects/Components/Power/Powernet.cs index 28d9be747e..d066fa5a75 100644 --- a/Content.Server/GameObjects/Components/Power/Powernet.cs +++ b/Content.Server/GameObjects/Components/Power/Powernet.cs @@ -289,7 +289,17 @@ namespace Content.Server.GameObjects.Components.Power } /// - /// Remove a continuous load from a device connected to the powernet + /// Returns whether or not a power device is in this powernet's load list. + /// + /// The device to check for. + /// True if the device is in the load list, false otherwise. + public bool HasDevice(PowerDeviceComponent device) + { + return DeviceLoadList.Contains(device); + } + + /// + /// Remove a continuous load from a device connected to the powernet /// public void RemoveDevice(PowerDeviceComponent device) { @@ -302,8 +312,7 @@ namespace Content.Server.GameObjects.Components.Power } else { - var name = device.Owner.Prototype.Name; - Logger.Info("We tried to remove a device twice from the same powernet somehow, prototype {0}", name); + Logger.WarningS("power", "We tried to remove device {0} twice from {1}, somehow.", device.Owner, this); } } @@ -341,8 +350,7 @@ namespace Content.Server.GameObjects.Components.Power } else { - var name = generator.Owner.Prototype.Name; - Logger.Info(String.Format("We tried to remove a device twice from the same power somehow, prototype {1}", name)); + Logger.WarningS("power", "We tried to remove generator {0} twice from {1}, somehow.", generator.Owner, this); } } @@ -389,17 +397,22 @@ namespace Content.Server.GameObjects.Components.Power } #endregion Registration + public override string ToString() + { + return $"Powernet {Uid}"; + } + /// /// Priority that a device will receive power if powernet cannot supply every device /// public enum Priority { - Necessary, - High, - Medium, - Low, - Provider, - Unnecessary + Necessary = 0, + High = 1, + Medium = 2, + Low = 3, + Provider = 4, + Unnecessary = 5 } /// @@ -412,9 +425,9 @@ namespace Content.Server.GameObjects.Components.Power int compare = y.Priority.CompareTo(x.Priority); //If the comparer returns 0 sortedset will believe it is a duplicate and return 0, so return 1 instead - if (compare == 0 && !x.Equals(y)) + if (compare == 0) { - return 1; + return y.Owner.Uid.CompareTo(x.Owner.Uid); } return compare; } diff --git a/engine b/engine index 480a0b4a0a..1812e8743d 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 480a0b4a0abeb233f74ec4c6c6e31c7e6cc3c4fe +Subproject commit 1812e8743d07e4dc94e5c96bece123c7c501fc29