diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs index 48e68d8ce..6fe79715c 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs @@ -17,8 +17,8 @@ namespace Barotrauma.Items.Components { get { return outputContainer; } } - - public Deconstructor(Item item, XElement element) + + public Deconstructor(Item item, XElement element) : base(item, element) { InitProjSpecific(element); @@ -53,7 +53,13 @@ namespace Barotrauma.Items.Components return; } - if (voltage < minVoltage) return; + if (voltage < minVoltage) { return; } + + var repairable = item.GetComponent(); + if (repairable != null) + { + repairable.LastActiveTime = (float)Timing.TotalTime + 10.0f; + } ApplyStatusEffects(ActionType.OnActive, deltaTime, null); @@ -73,8 +79,7 @@ namespace Barotrauma.Items.Components float percentageHealth = targetItem.Condition / targetItem.Prefab.Health; if (percentageHealth <= deconstructProduct.MinCondition || percentageHealth > deconstructProduct.MaxCondition) continue; - var itemPrefab = MapEntityPrefab.Find(null, deconstructProduct.ItemIdentifier) as ItemPrefab; - if (itemPrefab == null) + if (!(MapEntityPrefab.Find(null, deconstructProduct.ItemIdentifier) is ItemPrefab itemPrefab)) { DebugConsole.ThrowError("Tried to deconstruct item \"" + targetItem.Name + "\" but couldn't find item prefab \"" + deconstructProduct.ItemIdentifier + "\"!"); continue; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs index 5df72ff59..74d56b690 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs @@ -113,7 +113,7 @@ namespace Barotrauma.Items.Components #endif } - voltage = 0.0f; + voltage -= deltaTime; } private void UpdatePropellerDamage(float deltaTime) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs index 80b083a3e..7ade916d4 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs @@ -18,14 +18,14 @@ namespace Barotrauma.Items.Components private FabricationRecipe fabricatedItem; private float timeUntilReady; private float requiredTime; - + private Character user; private ItemContainer inputContainer, outputContainer; private float progressState; - public Fabricator(Item item, XElement element) + public Fabricator(Item item, XElement element) : base(item, element) { foreach (XElement subElement in element.Elements()) @@ -174,6 +174,12 @@ namespace Barotrauma.Items.Components if (voltage < minVoltage) { return; } + var repairable = item.GetComponent(); + if (repairable != null) + { + repairable.LastActiveTime = (float)Timing.TotalTime + 10.0f; + } + ApplyStatusEffects(ActionType.OnActive, deltaTime, null); if (powerConsumption <= 0) { voltage = 1.0f; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs index 53a54e414..18b2c7f55 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs @@ -81,7 +81,7 @@ namespace Barotrauma.Items.Components ApplyStatusEffects(ActionType.OnActive, deltaTime, null); } - voltage = 0.0f; + voltage -= deltaTime; } public override bool Pick(Character picker) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs index ae2249034..f9ef48349 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs @@ -73,6 +73,7 @@ namespace Barotrauma.Items.Components public override void UpdateBroken(float deltaTime, Camera cam) { powerDownTimer += deltaTime; + CurrFlow = 0.0f; } private void GetVents() diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Pump.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Pump.cs index 9eec99bba..7998e5b1d 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Pump.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Pump.cs @@ -19,10 +19,10 @@ namespace Barotrauma.Items.Components public float FlowPercentage { get { return flowPercentage; } - set + set { if (!MathUtils.IsValid(flowPercentage)) return; - flowPercentage = MathHelper.Clamp(value,-100.0f,100.0f); + flowPercentage = MathHelper.Clamp(value, -100.0f, 100.0f); flowPercentage = MathUtils.Round(flowPercentage, 1.0f); } } @@ -86,8 +86,8 @@ namespace Barotrauma.Items.Components item.CurrentHull.WaterVolume += currFlow; if (item.CurrentHull.WaterVolume > item.CurrentHull.Volume) { item.CurrentHull.Pressure += 0.5f; } - - voltage = 0.0f; + + voltage -= deltaTime; } partial void UpdateProjSpecific(float deltaTime); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs index 8d3baec86..1a6c18870 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs @@ -15,6 +15,8 @@ namespace Barotrauma.Items.Components private float deteriorationTimer; + public float LastActiveTime; + [Serialize(0.0f, true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f, DecimalCount = 2, ToolTip = "How fast the condition of the item deteriorates per second.")] public float DeteriorationSpeed { @@ -113,6 +115,8 @@ namespace Barotrauma.Items.Components { UpdateProjSpecific(deltaTime); + if (!ShouldDeteriorate()) { return; } + if (CurrentFixer == null) { if (item.Condition > 0.0f) @@ -179,8 +183,48 @@ namespace Barotrauma.Items.Components } } + partial void UpdateProjSpecific(float deltaTime); + private bool ShouldDeteriorate() + { + if (LastActiveTime > Timing.TotalTime) { return true; } + foreach (ItemComponent ic in item.Components) + { + if (ic is PowerTransfer pt) + { + //power transfer items (junction boxes, relays) don't deteriorate if they're no carrying any power + if (Math.Abs(pt.CurrPowerConsumption) < 0.1f) { return false; } + } + else if (ic is Engine engine) + { + //engines don't deteriorate if they're not running + if (Math.Abs(engine.Force) < 1.0f) { return false; } + } + else if (ic is Pump pump) + { + //pumps don't deteriorate if they're not running + if (Math.Abs(pump.FlowPercentage) < 1.0f) { return false; } + } + else if (ic is Reactor reactor) + { + //reactors don't deteriorate if they're not powered up + if (reactor.Temperature < 0.1f) { return false; } + } + else if (ic is OxygenGenerator oxyGenerator) + { + //oxygen generators don't deteriorate if they're not running + if (oxyGenerator.CurrFlow < 0.1f) { return false; } + } + else if (ic is Powered powered) + { + if (powered.Voltage < powered.MinVoltage) { return false; } + } + } + + return true; + } + private void UpdateFixAnimation(Character character) { character.AnimController.UpdateUseItem(false, item.WorldPosition + new Vector2(0.0f, 100.0f) * ((item.Condition / item.MaxCondition) % 0.1f)); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs index 4f140dd39..b7d2c38c2 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs @@ -254,7 +254,7 @@ namespace Barotrauma.Items.Components UpdateAITarget(item.AiTarget); } - voltage = 0.0f; + voltage -= deltaTime; } #if CLIENT diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs index 202f33fd1..a91f7103f 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs @@ -282,10 +282,17 @@ namespace Barotrauma.Items.Components { //use linked projectile containers in case they have to react to the turret being launched somehow //(play a sound, spawn more projectiles) - Item linkedItem = e as Item; - if (linkedItem == null) continue; + if (!(e is Item linkedItem)) continue; ItemContainer projectileContainer = linkedItem.GetComponent(); - if (projectileContainer != null) linkedItem.Use(deltaTime, null); + if (projectileContainer != null) + { + linkedItem.Use(deltaTime, null); + var repairable = linkedItem.GetComponent(); + if (repairable != null) + { + repairable.LastActiveTime = (float)Timing.TotalTime + 1.0f; + } + } } var projectiles = GetLoadedProjectiles(true); @@ -417,9 +424,8 @@ namespace Barotrauma.Items.Components int maxProjectileCount = 0; foreach (MapEntity e in item.linkedTo) { - var projectileContainer = e as Item; - if (projectileContainer == null) continue; - + if (!(e is Item projectileContainer)) continue; + var containedItems = projectileContainer.ContainedItems; if (containedItems != null) {